mirror of
https://github.com/troglobit/libite.git
synced 2026-11-01 13:00:33 +00: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:
1 parent
c15e883427
commit
8ce46eb439
1 file changed
+4
-2
+4
-2
@@ -43,8 +43,9 @@ int systemf(const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
status = system(cmd);
|
status = system(cmd);
|
||||||
|
if (status == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
rc = WEXITSTATUS(status);
|
|
||||||
if (!WIFEXITED(status)) {
|
if (!WIFEXITED(status)) {
|
||||||
if (WIFSIGNALED(status) &&
|
if (WIFSIGNALED(status) &&
|
||||||
(WTERMSIG(status) == SIGINT ||
|
(WTERMSIG(status) == SIGINT ||
|
||||||
@@ -59,7 +60,8 @@ int systemf(const char *fmt, ...)
|
|||||||
*/
|
*/
|
||||||
rc = 1;
|
rc = 1;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
|
rc = WEXITSTATUS(status);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user