commit ab7d3fba38ec3bfe6ce6ba223106c05fdd00331d
parent 19a73c3706a1b4fbfe8dfe03f570d4a6dc468186
Author: sin <sin@2f30.org>
Date: Thu, 22 Aug 2019 16:04:39 +0100
Only check status field if waitpid() did not fail
Diffstat:
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/spawn.c b/spawn.c
@@ -13,7 +13,7 @@ int
spawnvp(char *dir, char *file, char *argv[])
{
pid_t pid;
- int status;
+ int status, r;
pid = fork();
switch (pid) {
@@ -25,8 +25,10 @@ spawnvp(char *dir, char *file, char *argv[])
execvp(file, argv);
_exit(1);
default:
- while (waitpid(pid, &status, 0) == -1 && errno == EINTR)
- ;
+ while ((r = waitpid(pid, &status, 0)) == -1 && errno == EINTR)
+ continue;
+ if (r == -1)
+ return -1;
if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
return -1;
}