Skip to content

Commit 7397dfd

Browse files
committed
Check waitpid() in paranoid mode
Signed-off-by: Adrien Gallouët <[email protected]>
1 parent be3b6ed commit 7397dfd

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

init.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdio.h>
55
#include <stdlib.h>
66
#include <unistd.h>
7+
#include <errno.h>
78

89
#include <sys/mount.h>
910
#include <sys/stat.h>
@@ -29,7 +30,22 @@ spawn(const char *cmd)
2930
_exit(1);
3031
}
3132

32-
while (waitpid(-1, NULL, 0) != pid);
33+
while (1) {
34+
int status;
35+
pid_t ret = waitpid(-1, &status, 0);
36+
37+
if (ret == (pid_t)-1) {
38+
if (errno == EINTR)
39+
continue;
40+
perror("waitpid");
41+
return;
42+
}
43+
44+
if (ret == pid) {
45+
if (WIFEXITED(status) || WIFSIGNALED(status))
46+
return;
47+
}
48+
}
3349
}
3450

3551
static void

0 commit comments

Comments
 (0)