libc: Block and ignore appropriate signals in system()
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
apio 2023-07-10 21:17:56 +02:00
parent 4a5947e10e
commit 66365e15a7
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -191,9 +191,6 @@ extern "C"
return S_ISREG(st.st_mode); return S_ISREG(st.st_mode);
} }
// FIXME: During the execution of system(), SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored, in
// the process that calls system().
pid_t child = fork(); pid_t child = fork();
if (child == 0) if (child == 0)
{ {
@ -203,9 +200,21 @@ extern "C"
if (child < 0) return -1; if (child < 0) return -1;
sigset_t set, oldset;
sigemptyset(&set);
sigaddset(&set, SIGCHLD);
sigprocmask(SIG_BLOCK, &set, &oldset);
auto old_int = signal(SIGINT, SIG_IGN);
auto old_quit = signal(SIGQUIT, SIG_IGN);
int status; int status;
waitpid(child, &status, 0); waitpid(child, &status, 0);
sigprocmask(SIG_SETMASK, &oldset, nullptr);
signal(SIGINT, old_int);
signal(SIGQUIT, old_quit);
return status; return status;
} }