summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-10-16 04:56:19 +0000
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-10-16 04:56:19 +0000
commit6cbf1dd4a321ced6dffa5ca590692d283731f987 (patch)
tree80abc79978b6894c786ecb27e48a00f429df3027
parent509f71f79e62c52299ab61820c70726bc3a8f9cb (diff)
downloadmonitoring-plugins-6cbf1dd4a321ced6dffa5ca590692d283731f987.tar.gz
start support for gettimeofday and tv_usec
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@116 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--plugins/utils.c13
-rw-r--r--plugins/utils.h.in33
2 files changed, 39 insertions, 7 deletions
diff --git a/plugins/utils.c b/plugins/utils.c
index d97ad480..6e52dab7 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -316,6 +316,19 @@ is_option (char *str)
316 316
317 317
318 318
319double
320delta_time (struct timeval *tv)
321{
322 struct timeval *pt;
323 struct timezone *tz;
324
325 gettimeofday (pt, tz);
326
327 return (pt->tv_sec - tv->tv_sec + (pt->tv_usec - tv->tv_usec) / 1000000);
328}
329
330
331
319 332
320void 333void
321strip (char *buffer) 334strip (char *buffer)
diff --git a/plugins/utils.h.in b/plugins/utils.h.in
index 46b152a3..e910c417 100644
--- a/plugins/utils.h.in
+++ b/plugins/utils.h.in
@@ -45,13 +45,31 @@ int is_percentage (char *);
45 45
46int is_option (char *); 46int is_option (char *);
47 47
48/* generalized timer that will do milliseconds if available */
49#ifndef HAVE_GETTIMEOFDAY
50struct timeval {
51 long tv_sec; /* seconds */
52 long tv_usec; /* microseconds */
53};
54
55struct timezone {
56 int tz_minuteswest; /* minutes W of Greenwich */
57 int tz_dsttime; /* type of dst correction */
58};
59
60#define gettimeofday (tvp,tz) {\
61 tvp->tv_usec=0;\
62 tvp->tv_sec=(long)time();\
63}
64#endif
65
48/* Handle strings safely */ 66/* Handle strings safely */
49 67
50void strip (char *buffer); 68void strip (char *buffer);
51char *strscpy (char *dest, char *src); 69char *strscpy (char *dest, char *src);
52char *strscat (char *dest, char *src); 70char *strscat (char *dest, char *src);
53char *strnl (char *str); 71char *strnl (char *str);
54char *ssprintf (char *str, const char *fmt, ...); 72char *ssprintf (char *str, const char *fmt, ...); /* deprecate for asprintf */
55char *strpcpy (char *dest, const char *src, const char *str); 73char *strpcpy (char *dest, const char *src, const char *str);
56char *strpcat (char *dest, const char *src, const char *str); 74char *strpcat (char *dest, const char *src, const char *str);
57 75
@@ -61,15 +79,15 @@ int max_state(int, int);
61#define max(a,b) ((a)>(b))?(a):(b) 79#define max(a,b) ((a)>(b))?(a):(b)
62 80
63#define usage(msg) {\ 81#define usage(msg) {\
64 printf(msg);\ 82 printf(msg);\
65 print_usage();\ 83 print_usage();\
66exit(STATE_UNKNOWN);\ 84 exit(STATE_UNKNOWN);\
67} 85}
68 86
69#define usage2(msg,arg) {\ 87#define usage2(msg,arg) {\
70 printf("%s: %s - %s\n",PROGNAME,msg,arg);\ 88 printf("%s: %s - %s\n",PROGNAME,msg,arg);\
71 print_usage();\ 89 print_usage();\
72 exit(STATE_UNKNOWN);\ 90 exit(STATE_UNKNOWN);\
73} 91}
74 92
75#define state_text(a) \ 93#define state_text(a) \
@@ -94,3 +112,4 @@ exit(STATE_UNKNOWN);\
94{"warning",required_argument,0,'w'},\ 112{"warning",required_argument,0,'w'},\
95{"hostname",required_argument,0,'H'},\ 113{"hostname",required_argument,0,'H'},\
96{"file",required_argument,0,'F'} 114{"file",required_argument,0,'F'}
115