mirror of
https://github.com/troglobit/libite.git
synced 2026-10-01 05:22:34 +07:00
systemf(): fix improper handling of WEXITSTATUS()
The call to system() may return -1, e.g. if fork() fails or return status from execl() cannot be read. In these cases we should end immediately and not call WIFEXITED() et al. Also, WEXITSTATUS() should only be called if WEXITED() returns true. For details, see system(3) and wait(2). Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+4
-2
@@ -43,8 +43,9 @@ int systemf(const char *fmt, ...)
|
||||
va_end(ap);
|
||||
|
||||
status = system(cmd);
|
||||
if (status == -1)
|
||||
return -1;
|
||||
|
||||
rc = WEXITSTATUS(status);
|
||||
if (!WIFEXITED(status)) {
|
||||
if (WIFSIGNALED(status) &&
|
||||
(WTERMSIG(status) == SIGINT ||
|
||||
@@ -59,7 +60,8 @@ int systemf(const char *fmt, ...)
|
||||
*/
|
||||
rc = 1;
|
||||
}
|
||||
}
|
||||
} else
|
||||
rc = WEXITSTATUS(status);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user