mirror of
https://github.com/wolfcw/libfaketime.git
synced 2026-05-17 08:36:28 +03:00
use pipe to block process exit until all transitive children exit
This commit is contained in:
@@ -198,6 +198,8 @@ int main (int argc, char **argv)
|
||||
/* simply pass format string along */
|
||||
setenv("FAKETIME", argv[curr_opt], true);
|
||||
}
|
||||
int keepalive_fds[2];
|
||||
(void) (pipe(keepalive_fds) + 1);
|
||||
|
||||
/* we just consumed the timestamp option */
|
||||
curr_opt++;
|
||||
@@ -334,6 +336,7 @@ int main (int argc, char **argv)
|
||||
/* run command and clean up shared objects */
|
||||
if (0 == (child_pid = fork()))
|
||||
{
|
||||
close(keepalive_fds[0]); /* only parent needs to read this */
|
||||
if (EXIT_SUCCESS != execvp(argv[curr_opt], &argv[curr_opt]))
|
||||
{
|
||||
perror("Running specified command failed");
|
||||
@@ -343,7 +346,10 @@ int main (int argc, char **argv)
|
||||
else
|
||||
{
|
||||
int ret;
|
||||
char buf;
|
||||
close(keepalive_fds[1]); /* only children need keep this open */
|
||||
waitpid(child_pid, &ret, 0);
|
||||
(void) (read(keepalive_fds[0], &buf, 1) + 1); /* reads 0B when all children exit */
|
||||
cleanup_shobjs();
|
||||
if (WIFSIGNALED(ret))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user