summaryrefslogtreecommitdiffstats
path: root/web/attachments/148122-waitpid.patch
blob: dc6c06aad6832efa3e190c0bc33f6708a480dbcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
--- nagios-plugins-1.4.1/plugins/popen.c.orig	2005-09-05 14:02:00.314775817 +0200
+++ nagios-plugins-1.4.1/plugins/popen.c	2005-09-05 14:16:21.427287267 +0200
@@ -30,6 +30,7 @@
 
 FILE *spopen (const char *);
 int spclose (FILE *);
+static RETSIGTYPE popen_sigchld_handler (int);
 RETSIGTYPE popen_timeout_alarm_handler (int);
 
 #include <stdarg.h>							/* ANSI C header file */
@@ -66,6 +67,7 @@
 /*int *childerr = NULL;*//* ptr to array allocated at run-time */
 /*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */
 static int maxfd;								/* from our open_max(), {Prog openmax} */
+static volatile int childtermd = 0;				/* set by SIGCHLD handler */
 
 FILE *
 spopen (const char *cmdstring)
@@ -171,6 +173,10 @@
 	if (pipe (pfderr) < 0)
 		return (NULL);							/* errno set by pipe() */
 
+	if (signal (SIGCHLD, popen_sigchld_handler) == SIG_ERR) {
+		usage4 (_("Cannot catch SIGCHLD"));
+	}
+
 	if ((pid = fork ()) < 0)
 		return (NULL);							/* errno set by fork() */
 	else if (pid == 0) {					/* child */
@@ -220,6 +226,8 @@
 	if (fclose (fp) == EOF)
 		return (1);
 
+	while (!childtermd);								/* wait until SIGCHLD */
+
 	while (waitpid (pid, &status, 0) < 0)
 		if (errno != EINTR)
 			return (1);							/* error other than EINTR from waitpid() */
@@ -239,8 +247,14 @@
 #define	OPEN_MAX_GUESS	256			/* if OPEN_MAX is indeterminate */
 				/* no guarantee this is adequate */
 
+static RETSIGTYPE
+popen_sigchld_handler (int signo)
+{
+	if (signo == SIGCHLD)
+		childtermd = 1;
+}
 
-void
+RETSIGTYPE
 popen_timeout_alarm_handler (int signo)
 {
 	int fh;