diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2006-04-27 13:25:10 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2006-04-27 13:25:10 +0000 |
commit | 34cb16d283298885b73f75146433a703e93c0d4f (patch) | |
tree | c1e7b1b0ff0ad3e59e4921dd5e65d4527cd23d3f /plugins | |
parent | 37ebbab7fbd251c4c357459ff738847f5a5a4883 (diff) | |
download | monitoring-plugins-34cb16d283298885b73f75146433a703e93c0d4f.tar.gz |
Internal version of basename if one not found in system
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1383 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_procs.c | 8 | ||||
-rw-r--r-- | plugins/tests/test_utils.c | 5 | ||||
-rw-r--r-- | plugins/utils.c | 27 | ||||
-rw-r--r-- | plugins/utils.h | 3 |
4 files changed, 35 insertions, 8 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 01acc937..d05020b5 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -96,9 +96,6 @@ main (int argc, char **argv) | |||
96 | char procstat[8]; | 96 | char procstat[8]; |
97 | char procetime[MAX_INPUT_BUFFER] = { '\0' }; | 97 | char procetime[MAX_INPUT_BUFFER] = { '\0' }; |
98 | char *procargs; | 98 | char *procargs; |
99 | #ifdef HAVE_BASENAME | ||
100 | char *temp_string; | ||
101 | #endif | ||
102 | 99 | ||
103 | const char *zombie = "Z"; | 100 | const char *zombie = "Z"; |
104 | 101 | ||
@@ -179,10 +176,7 @@ main (int argc, char **argv) | |||
179 | strip (procargs); | 176 | strip (procargs); |
180 | 177 | ||
181 | /* Some ps return full pathname for command. This removes path */ | 178 | /* Some ps return full pathname for command. This removes path */ |
182 | #ifdef HAVE_BASENAME | 179 | procprog = basename(procprog); |
183 | temp_string = strdup(procprog); | ||
184 | procprog = basename(temp_string); | ||
185 | #endif /* HAVE_BASENAME */ | ||
186 | 180 | ||
187 | /* we need to convert the elapsed time to seconds */ | 181 | /* we need to convert the elapsed time to seconds */ |
188 | procseconds = convert_to_seconds(procetime); | 182 | procseconds = convert_to_seconds(procetime); |
diff --git a/plugins/tests/test_utils.c b/plugins/tests/test_utils.c index 5aa0028a..67c304a3 100644 --- a/plugins/tests/test_utils.c +++ b/plugins/tests/test_utils.c | |||
@@ -34,7 +34,7 @@ main (int argc, char **argv) | |||
34 | thresholds *thresholds = NULL; | 34 | thresholds *thresholds = NULL; |
35 | int rc; | 35 | int rc; |
36 | 36 | ||
37 | plan_tests(73); | 37 | plan_tests(74); |
38 | 38 | ||
39 | range = parse_range_string("6"); | 39 | range = parse_range_string("6"); |
40 | ok( range != NULL, "'6' is valid range"); | 40 | ok( range != NULL, "'6' is valid range"); |
@@ -165,6 +165,9 @@ main (int argc, char **argv) | |||
165 | ok( strcmp(test, "everything") == 0, "everything okay"); | 165 | ok( strcmp(test, "everything") == 0, "everything okay"); |
166 | free(test); | 166 | free(test); |
167 | 167 | ||
168 | test = basename("/here/is/a/path"); | ||
169 | ok( strcmp(test, "path") == 0, "basename okay"); | ||
170 | |||
168 | return exit_status(); | 171 | return exit_status(); |
169 | } | 172 | } |
170 | 173 | ||
diff --git a/plugins/utils.c b/plugins/utils.c index bb4ffbc2..f2593a16 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -5,6 +5,7 @@ | |||
5 | * Library of useful functions for plugins | 5 | * Library of useful functions for plugins |
6 | * | 6 | * |
7 | * Copyright (c) 2000 Karl DeBisschop (karl@debisschop.net) | 7 | * Copyright (c) 2000 Karl DeBisschop (karl@debisschop.net) |
8 | * Copyright (c) 2006 Nagios Plugin Development Team | ||
8 | * License: GPL | 9 | * License: GPL |
9 | * | 10 | * |
10 | * $Revision$ | 11 | * $Revision$ |
@@ -639,6 +640,32 @@ strpcat (char *dest, const char *src, const char *str) | |||
639 | return dest; | 640 | return dest; |
640 | } | 641 | } |
641 | 642 | ||
643 | #ifndef HAVE_BASENAME | ||
644 | /* function modified from coreutils base_name function - see ACKNOWLEDGEMENTS */ | ||
645 | char *basename(const char *path) { | ||
646 | char const *base = path; | ||
647 | char const *p; | ||
648 | for (p = base; *p; p++) { | ||
649 | if (*p == '/') { | ||
650 | /* Treat multiple adjacent slashes like single slash */ | ||
651 | do p++; | ||
652 | while (*p == '/'); | ||
653 | |||
654 | /* If filename ends in slash, use trailing slash | ||
655 | as basename if no non-slashes found */ | ||
656 | if (! *p) { | ||
657 | if (*base == '/') | ||
658 | base = p - 1; | ||
659 | break; | ||
660 | } | ||
661 | |||
662 | /* *p is non-slash preceded by slash */ | ||
663 | base = p; | ||
664 | } | ||
665 | } | ||
666 | return (char *) base; | ||
667 | } | ||
668 | #endif | ||
642 | 669 | ||
643 | /****************************************************************************** | 670 | /****************************************************************************** |
644 | * | 671 | * |
diff --git a/plugins/utils.h b/plugins/utils.h index 4bbe33d0..ed6243df 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -80,6 +80,9 @@ void set_thresholds(thresholds **, char *, char *); | |||
80 | int check_range(double, range *); | 80 | int check_range(double, range *); |
81 | int get_status(double, thresholds *); | 81 | int get_status(double, thresholds *); |
82 | 82 | ||
83 | /* I think this needs to be defined even if you use the system version */ | ||
84 | char *basename(const char *path); | ||
85 | |||
83 | #ifndef HAVE_GETTIMEOFDAY | 86 | #ifndef HAVE_GETTIMEOFDAY |
84 | int gettimeofday(struct timeval *, struct timezone *); | 87 | int gettimeofday(struct timeval *, struct timezone *); |
85 | #endif | 88 | #endif |