mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 13:33:09 +07:00
keventd: drop SIGCHLD save/restore dance, libuev reaps for us
modprobe_load() and run_program() used to temporarily restore the default SIGCHLD handler around fork+waitpid because the main loop set SIGCHLD=SIG_IGN. With the libuev conversion, sigchld_cb in keventd.c handles reaping via signalfd -- and signalfd does not interfere with synchronous waitpid(pid, ...) -- so the dance is dead code. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+1
-12
@@ -782,13 +782,9 @@ static int pattern_match(const char *pat, const char *subject, pat_type_t type)
|
||||
|
||||
/* ----- program execution ------------------------------------------------ */
|
||||
|
||||
/*
|
||||
* Fork and exec cmd via /bin/sh, capture stdout into result.
|
||||
* Temporarily restores SIGCHLD (keventd uses SIG_IGN) so waitpid works.
|
||||
*/
|
||||
/* Fork and exec cmd via /bin/sh, capture stdout into result. */
|
||||
static int run_program(const char *cmd, char *result, size_t rlen)
|
||||
{
|
||||
struct sigaction sa_dfl, sa_old;
|
||||
int pipefd[2];
|
||||
pid_t pid;
|
||||
int rc = -1;
|
||||
@@ -799,14 +795,8 @@ static int run_program(const char *cmd, char *result, size_t rlen)
|
||||
if (pipe(pipefd) < 0)
|
||||
return -1;
|
||||
|
||||
sigemptyset(&sa_dfl.sa_mask);
|
||||
sa_dfl.sa_flags = 0;
|
||||
sa_dfl.sa_handler = SIG_DFL;
|
||||
sigaction(SIGCHLD, &sa_dfl, &sa_old);
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
sigaction(SIGCHLD, &sa_old, NULL);
|
||||
close(pipefd[0]);
|
||||
close(pipefd[1]);
|
||||
return -1;
|
||||
@@ -838,7 +828,6 @@ static int run_program(const char *cmd, char *result, size_t rlen)
|
||||
rc = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
|
||||
}
|
||||
|
||||
sigaction(SIGCHLD, &sa_old, NULL);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -1038,13 +1038,9 @@ fail:
|
||||
* Synchronous: waits for modprobe to complete before returning so
|
||||
* that rules running after `kmod load` (e.g. IMPORT{builtin}=blkid
|
||||
* once the filesystem driver is in) see the post-load state.
|
||||
* keventd's main loop uses SIGCHLD=SIG_IGN to auto-reap stray
|
||||
* children, so we temporarily restore the default handler here to
|
||||
* make waitpid() observable.
|
||||
*/
|
||||
int modprobe_load(const char *modalias)
|
||||
{
|
||||
struct sigaction sa_dfl, sa_old;
|
||||
pid_t pid;
|
||||
int status = 0;
|
||||
|
||||
@@ -1053,15 +1049,9 @@ int modprobe_load(const char *modalias)
|
||||
|
||||
logit(LOG_DEBUG, "Loading module for %s", modalias);
|
||||
|
||||
sigemptyset(&sa_dfl.sa_mask);
|
||||
sa_dfl.sa_flags = 0;
|
||||
sa_dfl.sa_handler = SIG_DFL;
|
||||
sigaction(SIGCHLD, &sa_dfl, &sa_old);
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
logit(LOG_ERR, "fork failed: %s", strerror(errno));
|
||||
sigaction(SIGCHLD, &sa_old, NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1072,7 +1062,6 @@ int modprobe_load(const char *modalias)
|
||||
|
||||
while (waitpid(pid, &status, 0) < 0 && errno == EINTR)
|
||||
;
|
||||
sigaction(SIGCHLD, &sa_old, NULL);
|
||||
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user