From e85edd9e55d79b7e475f009df64accb65f317905 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Mon, 12 Sep 2005 10:31:29 +0000 Subject: ECHILD error at waitpid on Red Hat systems (Peter Pramberger and Sascha Runschke - 1250191) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1213 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/popen.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'plugins') 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; FILE *spopen (const char *); int spclose (FILE *); +#ifdef REDHAT_SPOPEN_ERROR +RETSIGTYPE popen_sigchld_handler (int); +#endif RETSIGTYPE popen_timeout_alarm_handler (int); #include /* ANSI C header file */ @@ -67,6 +70,10 @@ char *pname = NULL; /* caller can set this from argv[0] */ /*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */ static int maxfd; /* from our open_max(), {Prog openmax} */ +#ifdef REDHAT_SPOPEN_ERROR +static volatile int childtermd = 0; +#endif + FILE * spopen (const char *cmdstring) { @@ -171,6 +178,12 @@ spopen (const char *cmdstring) if (pipe (pfderr) < 0) return (NULL); /* errno set by pipe() */ +#ifdef REDHAT_SPOPEN_ERROR + if (signal (SIGCHLD, popen_sigchld_handler) == SIG_ERR) { + usage4 (_("Cannot catch SIGCHLD")); + } +#endif + if ((pid = fork ()) < 0) return (NULL); /* errno set by fork() */ else if (pid == 0) { /* child */ @@ -220,6 +233,10 @@ spclose (FILE * fp) if (fclose (fp) == EOF) return (1); +#ifdef REDHAT_SPOPEN_ERROR + while (!childtermd); /* wait until SIGCHLD */ +#endif + while (waitpid (pid, &status, 0) < 0) if (errno != EINTR) return (1); /* error other than EINTR from waitpid() */ @@ -239,8 +256,16 @@ static int openmax = 0; #define OPEN_MAX_GUESS 256 /* if OPEN_MAX is indeterminate */ /* no guarantee this is adequate */ +#ifdef REDHAT_SPOPEN_ERROR +RETSIGTYPE +popen_sigchld_handler (int signo) +{ + if (signo == SIGCHLD) + childtermd = 1; +} +#endif -void +RETSIGTYPE popen_timeout_alarm_handler (int signo) { int fh; -- cgit v1.2.3-74-g34f1