diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-10-16 04:56:19 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-10-16 04:56:19 +0000 |
commit | 6cbf1dd4a321ced6dffa5ca590692d283731f987 (patch) | |
tree | 80abc79978b6894c786ecb27e48a00f429df3027 | |
parent | 509f71f79e62c52299ab61820c70726bc3a8f9cb (diff) | |
download | monitoring-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.c | 13 | ||||
-rw-r--r-- | plugins/utils.h.in | 33 |
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 | ||
319 | double | ||
320 | delta_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 | ||
320 | void | 333 | void |
321 | strip (char *buffer) | 334 | strip (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 | ||
46 | int is_option (char *); | 46 | int is_option (char *); |
47 | 47 | ||
48 | /* generalized timer that will do milliseconds if available */ | ||
49 | #ifndef HAVE_GETTIMEOFDAY | ||
50 | struct timeval { | ||
51 | long tv_sec; /* seconds */ | ||
52 | long tv_usec; /* microseconds */ | ||
53 | }; | ||
54 | |||
55 | struct 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 | ||
50 | void strip (char *buffer); | 68 | void strip (char *buffer); |
51 | char *strscpy (char *dest, char *src); | 69 | char *strscpy (char *dest, char *src); |
52 | char *strscat (char *dest, char *src); | 70 | char *strscat (char *dest, char *src); |
53 | char *strnl (char *str); | 71 | char *strnl (char *str); |
54 | char *ssprintf (char *str, const char *fmt, ...); | 72 | char *ssprintf (char *str, const char *fmt, ...); /* deprecate for asprintf */ |
55 | char *strpcpy (char *dest, const char *src, const char *str); | 73 | char *strpcpy (char *dest, const char *src, const char *str); |
56 | char *strpcat (char *dest, const char *src, const char *str); | 74 | char *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();\ |
66 | exit(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 | |||