summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 37ebbab)
raw | patch | inline | side by side (parent: 37ebbab)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Thu, 27 Apr 2006 13:25:10 +0000 (13:25 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Thu, 27 Apr 2006 13:25:10 +0000 (13:25 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1383 f882894a-f735-0410-b71e-b25c423dba1c
diff --git a/configure.in b/configure.in
index ae6253bd2272256efecb0f993b6b9598121ad8c5..1313b2f52e4e6430e14042e9f3e62b0f9f59ddb5 100644 (file)
--- a/configure.in
+++ b/configure.in
dnl Checks for library functions.
AC_CHECK_FUNCS(memmove select socket strdup strstr strtod strtol strtoul floor)
+AC_CHECK_FUNCS(basename)
AC_MSG_CHECKING(return type of socket size)
AC_TRY_COMPILE([#include <stdlib.h>
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 01acc9379a73fdbdd5a3e0ba40c8d2c6922ec169..d05020b5a4eb748242b790f4b531b979309f3848 100644 (file)
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
char procstat[8];
char procetime[MAX_INPUT_BUFFER] = { '\0' };
char *procargs;
-#ifdef HAVE_BASENAME
- char *temp_string;
-#endif
const char *zombie = "Z";
strip (procargs);
/* Some ps return full pathname for command. This removes path */
-#ifdef HAVE_BASENAME
- temp_string = strdup(procprog);
- procprog = basename(temp_string);
-#endif /* HAVE_BASENAME */
+ procprog = basename(procprog);
/* we need to convert the elapsed time to seconds */
procseconds = convert_to_seconds(procetime);
index 5aa0028a8345dc14945a7df03d89bad4c387abb6..67c304a346763ba41426fde9e6e5ce31a3403f52 100644 (file)
thresholds *thresholds = NULL;
int rc;
- plan_tests(73);
+ plan_tests(74);
range = parse_range_string("6");
ok( range != NULL, "'6' is valid range");
ok( strcmp(test, "everything") == 0, "everything okay");
free(test);
+ test = basename("/here/is/a/path");
+ ok( strcmp(test, "path") == 0, "basename okay");
+
return exit_status();
}
diff --git a/plugins/utils.c b/plugins/utils.c
index bb4ffbc22ff1920a138ea80f158bd7be04304689..f2593a16623688f94a887e3cedeb3f0014e34f15 100644 (file)
--- a/plugins/utils.c
+++ b/plugins/utils.c
* Library of useful functions for plugins
*
* Copyright (c) 2000 Karl DeBisschop (karl@debisschop.net)
+ * Copyright (c) 2006 Nagios Plugin Development Team
* License: GPL
*
* $Revision$
return dest;
}
+#ifndef HAVE_BASENAME
+/* function modified from coreutils base_name function - see ACKNOWLEDGEMENTS */
+char *basename(const char *path) {
+ char const *base = path;
+ char const *p;
+ for (p = base; *p; p++) {
+ if (*p == '/') {
+ /* Treat multiple adjacent slashes like single slash */
+ do p++;
+ while (*p == '/');
+
+ /* If filename ends in slash, use trailing slash
+ as basename if no non-slashes found */
+ if (! *p) {
+ if (*base == '/')
+ base = p - 1;
+ break;
+ }
+
+ /* *p is non-slash preceded by slash */
+ base = p;
+ }
+ }
+ return (char *) base;
+}
+#endif
/******************************************************************************
*
diff --git a/plugins/utils.h b/plugins/utils.h
index 4bbe33d0fa351a1b9fba23f41bd2ac42a3f3287a..ed6243df59436c1d6e9db9840eb04a6516f9fc3d 100644 (file)
--- a/plugins/utils.h
+++ b/plugins/utils.h
int check_range(double, range *);
int get_status(double, thresholds *);
+/* I think this needs to be defined even if you use the system version */
+char *basename(const char *path);
+
#ifndef HAVE_GETTIMEOFDAY
int gettimeofday(struct timeval *, struct timezone *);
#endif