Skip to content

Commit d3face3

Browse files
committed
Merge pull request #180 from acv/fix-execute
Child return value not checked properly
2 parents 7c3c3c3 + e1b14e6 commit d3face3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/util.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,19 @@ execute(const char *cmd_line, int quiet)
117117
debug(LOG_DEBUG, "Waiting for PID %d to exit", pid);
118118
rc = waitpid(pid, &status, 0);
119119
debug(LOG_DEBUG, "Process PID %d exited", rc);
120+
121+
if (-1 == rc) {
122+
debug(LOG_ERR, "waitpid() failed (%s)", strerror(errno));
123+
return 1; /* waitpid failed. */
124+
}
120125

121-
return (WEXITSTATUS(status));
126+
if (WIFEXITED(status)) {
127+
return (WEXITSTATUS(status));
128+
} else {
129+
/* If we get here, child did not exit cleanly. Will return non-zero exit code to caller*/
130+
debug(LOG_DEBUG, "Child may have been killed.");
131+
return 1;
132+
}
122133
}
123134

124135
struct in_addr *

0 commit comments

Comments
 (0)