summaryrefslogtreecommitdiffstats
path: root/plugins/popen.c
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2005-09-12 10:31:29 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2005-09-12 10:31:29 +0000
commite85edd9e55d79b7e475f009df64accb65f317905 (patch)
tree1adf431a06733721b459d673fc1214295f53774a /plugins/popen.c
parent3c554b72de0df28175e7ed8a0bcf3b7e509335d9 (diff)
downloadmonitoring-plugins-e85edd9e55d79b7e475f009df64accb65f317905.tar.gz
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
Diffstat (limited to 'plugins/popen.c')
-rw-r--r--plugins/popen.c27
1 files changed, 26 insertions, 1 deletions
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
31FILE *spopen (const char *); 31FILE *spopen (const char *);
32int spclose (FILE *); 32int spclose (FILE *);
33#ifdef REDHAT_SPOPEN_ERROR
34RETSIGTYPE popen_sigchld_handler (int);
35#endif
33RETSIGTYPE popen_timeout_alarm_handler (int); 36RETSIGTYPE 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 */
68static int maxfd; /* from our open_max(), {Prog openmax} */ 71static int maxfd; /* from our open_max(), {Prog openmax} */
69 72
73#ifdef REDHAT_SPOPEN_ERROR
74static volatile int childtermd = 0;
75#endif
76
70FILE * 77FILE *
71spopen (const char *cmdstring) 78spopen (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
260RETSIGTYPE
261popen_sigchld_handler (int signo)
262{
263 if (signo == SIGCHLD)
264 childtermd = 1;
265}
266#endif
242 267
243void 268RETSIGTYPE
244popen_timeout_alarm_handler (int signo) 269popen_timeout_alarm_handler (int signo)
245{ 270{
246 int fh; 271 int fh;