diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/popen.c | 27 |
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 | ||
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; |