aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsin <sin@2f30.org>2019-08-04 11:53:02 +0100
committersin <sin@2f30.org>2019-08-04 11:53:20 +0100
commite81a1c5362dc178e1c9006077f836d7ca5bfb577 (patch)
tree8150df5c4796e3dee53d3c740ce719e33fad0de2
parent86fa68dc89e87d10748ceb642e4d766e9f2b749b (diff)
downloadnoice-e81a1c5362dc178e1c9006077f836d7ca5bfb577.tar.gz
Die on fork() failure (thanks Evil_Bob)
-rw-r--r--spawn.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/spawn.c b/spawn.c
index 614ab64..5f63cb9 100644
--- a/spawn.c
+++ b/spawn.c
@@ -2,6 +2,7 @@
#include <sys/types.h>
#include <sys/wait.h>
+#include <err.h>
#include <stdarg.h>
#include <unistd.h>
@@ -14,12 +15,15 @@ spawnvp(char *dir, char *file, char *argv[])
int status;
pid = fork();
- if (pid == 0) {
+ switch (pid) {
+ case -1:
+ err(1, "fork");
+ case 0:
if (dir != NULL)
chdir(dir);
execvp(file, argv);
_exit(1);
- } else {
+ default:
/* Ignore interruptions */
while (waitpid(pid, &status, 0) == -1)
;
Un proyecto texto-plano.xyz