summaryrefslogtreecommitdiffstats
path: root/src/shell.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-05-31 06:05:29 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-05-31 06:05:29 +0200
commit73f7d5048c0e2ad4817ad208de02adee73938ed0 (patch)
tree1a292a82567eb49d3b0c9a8218d869528a994682 /src/shell.c
parent6c656c7394bb972e81cd291b0ab126b2e73ce499 (diff)
downloadfastd-73f7d5048c0e2ad4817ad208de02adee73938ed0.tar
fastd-73f7d5048c0e2ad4817ad208de02adee73938ed0.zip
Unblock signals only during poll/epoll wait
If signals are normally blocked, we can avoid a lot of EINTR handling.
Diffstat (limited to 'src/shell.c')
-rw-r--r--src/shell.c25
1 files changed, 3 insertions, 22 deletions
diff --git a/src/shell.c b/src/shell.c
index c161a9e..076c4c8 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -138,11 +138,10 @@ static bool shell_command_do_exec(const fastd_shell_command_t *command, const fa
shell_command_setenv(parent, env);
- /* unblock SIGCHLD */
+ /* unblock signals */
sigset_t set;
sigemptyset(&set);
- sigaddset(&set, SIGCHLD);
- pthread_sigmask(SIG_UNBLOCK, &set, NULL);
+ pthread_sigmask(SIG_SETMASK, &set, NULL);
execl("/bin/sh", "sh", "-c", command->command, (char*)NULL);
_exit(127);
@@ -157,23 +156,13 @@ bool fastd_shell_command_exec_sync(const fastd_shell_command_t *command, const f
if (!fastd_shell_command_isset(command))
return true;
- /* block SIGCHLD */
- sigset_t set, oldset;
- sigemptyset(&set);
- sigaddset(&set, SIGCHLD);
- pthread_sigmask(SIG_BLOCK, &set, &oldset);
-
pid_t pid;
- if (!shell_command_do_exec(command, env, &pid)) {
- pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+ if (!shell_command_do_exec(command, env, &pid))
return false;
- }
int status;
pid_t err = waitpid(pid, &status, 0);
- pthread_sigmask(SIG_SETMASK, &oldset, NULL);
-
if (err <= 0) {
pr_error_errno("fastd_shell_command_exec_sync: waitpid");
return false;
@@ -199,17 +188,9 @@ bool fastd_shell_command_exec_sync(const fastd_shell_command_t *command, const f
on SIGCHLD.
*/
static void shell_command_exec_async(const fastd_shell_command_t *command, const fastd_shell_env_t *env) {
- /* block SIGCHLD */
- sigset_t set, oldset;
- sigemptyset(&set);
- sigaddset(&set, SIGCHLD);
- pthread_sigmask(SIG_BLOCK, &set, &oldset);
-
pid_t pid;
if (shell_command_do_exec(command, env, &pid))
VECTOR_ADD(ctx.async_pids, pid);
-
- pthread_sigmask(SIG_SETMASK, &oldset, NULL);
}
/** Executes a shell command */