Only check status field if waitpid() did not fail - noice - small file browser (mirror / fork from 2f30.org) (HTM) git clone git://git.codemadness.org/noice (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit ab7d3fba38ec3bfe6ce6ba223106c05fdd00331d (DIR) parent 19a73c3706a1b4fbfe8dfe03f570d4a6dc468186 (HTM) Author: sin <sin@2f30.org> Date: Thu, 22 Aug 2019 16:04:39 +0100 Only check status field if waitpid() did not fail Diffstat: M spawn.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- (DIR) 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; }