commit a784c503368ba3d9f85b21647ae9fc08872a470c
parent ab7d3fba38ec3bfe6ce6ba223106c05fdd00331d
Author: sin <sin@2f30.org>
Date: Thu, 22 Aug 2019 16:15:02 +0100
Fail spawn*() if chdir() fails
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/spawn.c b/spawn.c
@@ -5,6 +5,7 @@
#include <err.h>
#include <errno.h>
#include <stdarg.h>
+#include <stdlib.h>
#include <unistd.h>
#include "util.h"
@@ -20,8 +21,8 @@ spawnvp(char *dir, char *file, char *argv[])
case -1:
return -1;
case 0:
- if (dir != NULL)
- chdir(dir);
+ if (dir != NULL && chdir(dir) == -1)
+ exit(1);
execvp(file, argv);
_exit(1);
default: