diff options
| -rw-r--r-- | Makefile.am | 3 | ||||
| -rw-r--r-- | config_test/Makefile | 10 | ||||
| -rw-r--r-- | config_test/child_test.c | 77 | ||||
| -rwxr-xr-x | config_test/run_tests | 16 | ||||
| -rw-r--r-- | configure.in | 16 | ||||
| -rw-r--r-- | plugins/popen.c | 27 |
6 files changed, 147 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am index a7c5ffc6..cc46a465 100644 --- a/Makefile.am +++ b/Makefile.am | |||
| @@ -5,7 +5,8 @@ SUBDIRS = intl lib plugins plugins-scripts m4 po | |||
| 5 | EXTRA_DIST = config.rpath \ | 5 | EXTRA_DIST = config.rpath \ |
| 6 | ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS BUGS CHANGES CODING FAQ LEGAL \ | 6 | ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS BUGS CHANGES CODING FAQ LEGAL \ |
| 7 | REQUIREMENTS SUPPORT THANKS \ | 7 | REQUIREMENTS SUPPORT THANKS \ |
| 8 | NPTest.pm contrib pkg nagios-plugins.spec | 8 | NPTest.pm contrib pkg nagios-plugins.spec \ |
| 9 | config_test/Makefile config_test/run_tests config_test/child_test.c | ||
| 9 | 10 | ||
| 10 | ACLOCAL_AMFLAGS = -I m4 | 11 | ACLOCAL_AMFLAGS = -I m4 |
| 11 | 12 | ||
diff --git a/config_test/Makefile b/config_test/Makefile new file mode 100644 index 00000000..295696e9 --- /dev/null +++ b/config_test/Makefile | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | |||
| 2 | all: child_test.c | ||
| 3 | gcc -o child_test child_test.c | ||
| 4 | |||
| 5 | test: | ||
| 6 | ./run_tests 10 | ||
| 7 | |||
| 8 | clean: | ||
| 9 | rm -f child_test | ||
| 10 | |||
diff --git a/config_test/child_test.c b/config_test/child_test.c new file mode 100644 index 00000000..e7d82106 --- /dev/null +++ b/config_test/child_test.c | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | // Base code taken from http://www-h.eng.cam.ac.uk/help/tpl/unix/fork.html | ||
| 2 | // Fix for redhat suggested by Ptere Pramberger, peter@pramberger.at | ||
| 3 | #include <unistd.h> | ||
| 4 | #include <sys/wait.h> | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <sys/types.h> | ||
| 7 | #include <signal.h> | ||
| 8 | void popen_sigchld_handler (int); | ||
| 9 | int childtermd; | ||
| 10 | |||
| 11 | int main(){ | ||
| 12 | char str[1024]; | ||
| 13 | int pipefd[2]; | ||
| 14 | pid_t pid; | ||
| 15 | int status, died; | ||
| 16 | |||
| 17 | if (signal (SIGCHLD, popen_sigchld_handler) == SIG_ERR) { | ||
| 18 | printf ("Cannot catch SIGCHLD\n"); | ||
| 19 | _exit(-1); | ||
| 20 | } | ||
| 21 | |||
| 22 | pipe (pipefd); | ||
| 23 | switch(pid=fork()){ | ||
| 24 | case -1: | ||
| 25 | printf("can't fork\n"); | ||
| 26 | _exit(-1); | ||
| 27 | |||
| 28 | case 0 : // this is the code the child runs | ||
| 29 | close(1); // close stdout | ||
| 30 | // pipefd[1] is for writing to the pipe. We want the output | ||
| 31 | // that used to go to the standard output (file descriptor 1) | ||
| 32 | // to be written to the pipe. The following command does this, | ||
| 33 | // creating a new file descripter 1 (the lowest available) | ||
| 34 | // that writes where pipefd[1] goes. | ||
| 35 | dup (pipefd[1]); // points pipefd at file descriptor | ||
| 36 | // the child isn't going to read from the pipe, so | ||
| 37 | // pipefd[0] can be closed | ||
| 38 | close (pipefd[0]); | ||
| 39 | |||
| 40 | //These are the commands to run, with success commented. dig and nslookup only problems | ||
| 41 | //execl ("/bin/date","date",0); // 100% | ||
| 42 | //execl ("/bin/cat", "cat", "/etc/hosts", 0); // 100% | ||
| 43 | //execl ("/usr/bin/dig", "dig", "redhat.com", 0); // 69% | ||
| 44 | //execl("/bin/sleep", "sleep", "1", 0); // 100% | ||
| 45 | execl ("/usr/bin/nslookup","nslookup","redhat.com",0); // 90% (after 100 tests), 40% (after 10 tests) | ||
| 46 | //execl ("/bin/ping","ping","-c","1","localhost",0); // 100% | ||
| 47 | //execl ("/bin/ping","ping","-c","1","192.168.10.32",0); // 100% | ||
| 48 | _exit(0); | ||
| 49 | |||
| 50 | default: // this is the code the parent runs | ||
| 51 | |||
| 52 | close(0); // close stdin | ||
| 53 | // Set file descriptor 0 (stdin) to read from the pipe | ||
| 54 | dup (pipefd[0]); | ||
| 55 | // the parent isn't going to write to the pipe | ||
| 56 | close (pipefd[1]); | ||
| 57 | // Now read from the pipe | ||
| 58 | fgets(str, 1023, stdin); | ||
| 59 | //printf("1st line output is %s\n", str); | ||
| 60 | |||
| 61 | //while (!childtermd); // Uncomment this line to fix | ||
| 62 | |||
| 63 | died= wait(&status); | ||
| 64 | //printf("died=%d status=%d\n", died, status); | ||
| 65 | if (died > 0) _exit(0); | ||
| 66 | else _exit(1); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | void | ||
| 71 | popen_sigchld_handler (int signo) | ||
| 72 | { | ||
| 73 | if (signo == SIGCHLD) { | ||
| 74 | //printf("Caught sigchld\n"); | ||
| 75 | childtermd = 1; | ||
| 76 | } | ||
| 77 | } | ||
diff --git a/config_test/run_tests b/config_test/run_tests new file mode 100755 index 00000000..e41db232 --- /dev/null +++ b/config_test/run_tests | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #!/bin/ksh | ||
| 2 | |||
| 3 | i=0 | ||
| 4 | success=0 | ||
| 5 | fail=0 | ||
| 6 | while [[ $i -lt $1 ]] ; do | ||
| 7 | ./child_test | ||
| 8 | if [[ $? -eq 0 ]] ; then | ||
| 9 | success=$(($success+1)) | ||
| 10 | else | ||
| 11 | fail=$((fail+1)) | ||
| 12 | fi | ||
| 13 | i=$(($i+1)) | ||
| 14 | done | ||
| 15 | print "Success=$success Fail=$fail" | ||
| 16 | [[ $fail -gt 0 ]] && exit 1 | ||
diff --git a/configure.in b/configure.in index 5453fe1d..4f9dc1c9 100644 --- a/configure.in +++ b/configure.in | |||
| @@ -1520,6 +1520,22 @@ AC_SUBST(DEPLIBS) | |||
| 1520 | AM_GNU_GETTEXT([no-libtool], [need-ngettext]) | 1520 | AM_GNU_GETTEXT([no-libtool], [need-ngettext]) |
| 1521 | AM_GNU_GETTEXT_VERSION(0.11.5) | 1521 | AM_GNU_GETTEXT_VERSION(0.11.5) |
| 1522 | 1522 | ||
| 1523 | dnl Check for Redhat spopen problem | ||
| 1524 | dnl Wierd problem where ECHILD is returned from a wait call in error | ||
| 1525 | dnl Only appears to affect nslookup and dig calls. Only affects redhat around | ||
| 1526 | dnl 2.6.9-11 (okay in 2.6.9-5). Redhat investigating root cause | ||
| 1527 | dnl We patch plugins/popen.c | ||
| 1528 | if echo $ac_cv_uname_r | egrep "\.EL$" >/dev/null 2>&1 ; then | ||
| 1529 | AC_MSG_CHECKING(for redhat spopen problem) | ||
| 1530 | ( cd config_test && make && make test ) > /dev/null 2>&1 | ||
| 1531 | if test $? -eq 0 ; then | ||
| 1532 | AC_MSG_RESULT(okay) | ||
| 1533 | else | ||
| 1534 | AC_MSG_RESULT(error) | ||
| 1535 | AC_DEFINE(REDHAT_SPOPEN_ERROR, 1, "Problem on redhat with spopen") | ||
| 1536 | fi | ||
| 1537 | fi | ||
| 1538 | |||
| 1523 | dnl External libraries - see ACKNOWLEDGEMENTS | 1539 | dnl External libraries - see ACKNOWLEDGEMENTS |
| 1524 | np_COREUTILS | 1540 | np_COREUTILS |
| 1525 | np_CURL | 1541 | np_CURL |
diff --git a/plugins/popen.c b/plugins/popen.c index 062cf274..f6810691 100644 --- a/plugins/popen.c +++ b/plugins/popen.c | |||
| @@ -30,6 +30,9 @@ extern FILE *child_process; | |||
| 30 | 30 | ||
| 31 | FILE *spopen (const char *); | 31 | FILE *spopen (const char *); |
| 32 | int spclose (FILE *); | 32 | int spclose (FILE *); |
| 33 | #ifdef REDHAT_SPOPEN_ERROR | ||
| 34 | RETSIGTYPE popen_sigchld_handler (int); | ||
| 35 | #endif | ||
| 33 | RETSIGTYPE popen_timeout_alarm_handler (int); | 36 | RETSIGTYPE popen_timeout_alarm_handler (int); |
| 34 | 37 | ||
| 35 | #include <stdarg.h> /* ANSI C header file */ | 38 | #include <stdarg.h> /* ANSI C header file */ |
| @@ -67,6 +70,10 @@ char *pname = NULL; /* caller can set this from argv[0] */ | |||
| 67 | /*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */ | 70 | /*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */ |
| 68 | static int maxfd; /* from our open_max(), {Prog openmax} */ | 71 | static int maxfd; /* from our open_max(), {Prog openmax} */ |
| 69 | 72 | ||
| 73 | #ifdef REDHAT_SPOPEN_ERROR | ||
| 74 | static volatile int childtermd = 0; | ||
| 75 | #endif | ||
| 76 | |||
| 70 | FILE * | 77 | FILE * |
| 71 | spopen (const char *cmdstring) | 78 | spopen (const char *cmdstring) |
| 72 | { | 79 | { |
| @@ -171,6 +178,12 @@ spopen (const char *cmdstring) | |||
| 171 | if (pipe (pfderr) < 0) | 178 | if (pipe (pfderr) < 0) |
| 172 | return (NULL); /* errno set by pipe() */ | 179 | return (NULL); /* errno set by pipe() */ |
| 173 | 180 | ||
| 181 | #ifdef REDHAT_SPOPEN_ERROR | ||
| 182 | if (signal (SIGCHLD, popen_sigchld_handler) == SIG_ERR) { | ||
| 183 | usage4 (_("Cannot catch SIGCHLD")); | ||
| 184 | } | ||
| 185 | #endif | ||
| 186 | |||
| 174 | if ((pid = fork ()) < 0) | 187 | if ((pid = fork ()) < 0) |
| 175 | return (NULL); /* errno set by fork() */ | 188 | return (NULL); /* errno set by fork() */ |
| 176 | else if (pid == 0) { /* child */ | 189 | else if (pid == 0) { /* child */ |
| @@ -220,6 +233,10 @@ spclose (FILE * fp) | |||
| 220 | if (fclose (fp) == EOF) | 233 | if (fclose (fp) == EOF) |
| 221 | return (1); | 234 | return (1); |
| 222 | 235 | ||
| 236 | #ifdef REDHAT_SPOPEN_ERROR | ||
| 237 | while (!childtermd); /* wait until SIGCHLD */ | ||
| 238 | #endif | ||
| 239 | |||
| 223 | while (waitpid (pid, &status, 0) < 0) | 240 | while (waitpid (pid, &status, 0) < 0) |
| 224 | if (errno != EINTR) | 241 | if (errno != EINTR) |
| 225 | return (1); /* error other than EINTR from waitpid() */ | 242 | return (1); /* error other than EINTR from waitpid() */ |
| @@ -239,8 +256,16 @@ static int openmax = 0; | |||
| 239 | #define OPEN_MAX_GUESS 256 /* if OPEN_MAX is indeterminate */ | 256 | #define OPEN_MAX_GUESS 256 /* if OPEN_MAX is indeterminate */ |
| 240 | /* no guarantee this is adequate */ | 257 | /* no guarantee this is adequate */ |
| 241 | 258 | ||
| 259 | #ifdef REDHAT_SPOPEN_ERROR | ||
| 260 | RETSIGTYPE | ||
| 261 | popen_sigchld_handler (int signo) | ||
| 262 | { | ||
| 263 | if (signo == SIGCHLD) | ||
| 264 | childtermd = 1; | ||
| 265 | } | ||
| 266 | #endif | ||
| 242 | 267 | ||
| 243 | void | 268 | RETSIGTYPE |
| 244 | popen_timeout_alarm_handler (int signo) | 269 | popen_timeout_alarm_handler (int signo) |
| 245 | { | 270 | { |
| 246 | int fh; | 271 | int fh; |
