Skip to content

Commit 0d2fb9d

Browse files
authored
Merge pull request #349 from LeaYeh/fix-sigpipe-leaks
2 parents 10c72f4 + f5c0d00 commit 0d2fb9d

File tree

5 files changed

+5
-6
lines changed

5 files changed

+5
-6
lines changed

source/backend/executor/builtin_cmd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static void exec_builtin_cmd(t_sh *shell)
8787
{
8888
t_fct *final_cmd_table;
8989

90+
setup_signal(shell, SIGPIPE, SIG_IGNORE);
9091
final_cmd_table = shell->final_cmd_table;
9192
if (ft_strcmp(final_cmd_table->simple_cmd[0], "env") == 0)
9293
shell->exit_code = exec_env(final_cmd_table->env);
@@ -108,4 +109,5 @@ static void exec_builtin_cmd(t_sh *shell)
108109
else if (ft_strcmp(final_cmd_table->simple_cmd[0], "~") == 0 && \
109110
shell->is_interactive)
110111
shell->exit_code = exec_easter_egg();
112+
setup_signal(shell, SIGPIPE, SIG_STANDARD);
111113
}

source/backend/executor/external_cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ static bool check_execfile_exist(char *exec_path, char *cmd_name)
6161
static void reset_external_signal_handler(t_sh *shell)
6262
{
6363
setup_signal(shell, SIGINT, SIG_DEFAULT);
64-
setup_signal(shell, SIGQUIT, SIG_DEFAULT);
6564
setup_signal(shell, SIGTERM, SIG_DEFAULT);
6665
setup_signal(shell, SIGUSR1, SIG_DEFAULT);
66+
setup_signal(shell, SIGQUIT, SIG_DEFAULT);
6767
}
6868

6969
static void handle_exec_error(t_sh *shell, char *exec_path)

source/backend/executor/simple_cmd_process.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ static void exec_simple_cmd(t_sh *shell, t_list_d **cmd_table_node)
4444
if (ret == BAD_SUBSTITUTION)
4545
shell->exit_code = BAD_SUBSTITUTION;
4646
else if (is_builtin(shell->final_cmd_table->simple_cmd[0], shell))
47-
{
48-
setup_signal(shell, SIGPIPE, SIG_IGNORE);
4947
handle_builtin(shell, cmd_table_node);
50-
}
5148
else
5249
handle_external_cmd(shell, get_cmd_table_from_list(*cmd_table_node));
5350
clean_and_exit_shell(shell, shell->exit_code, NULL);

source/shell/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ bool init_shell(t_sh *shell)
3636
handle_signal_std(0, NULL, shell);
3737
handle_signal_record(0, NULL, shell);
3838
setup_signal(shell, SIGINT, SIG_STANDARD);
39-
setup_signal(shell, SIGUSR1, SIG_STANDARD);
4039
setup_signal(shell, SIGTERM, SIG_STANDARD);
40+
setup_signal(shell, SIGUSR1, SIG_STANDARD);
4141
setup_signal(shell, SIGQUIT, SIG_IGNORE);
4242
return (true);
4343
}

source/signal/exception_broadcaster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ void raise_error_to_own_subprocess(t_sh *shell, int exit_code, char *msg)
3939
if (msg)
4040
print_error(STY_RED"%s: error: %s\n"STY_RES, PROGRAM_NAME, msg);
4141
setup_signal(shell, SIGINT, SIG_STANDARD);
42-
setup_signal(shell, SIGUSR1, SIG_STANDARD);
4342
setup_signal(shell, SIGTERM, SIG_STANDARD);
43+
setup_signal(shell, SIGUSR1, SIG_STANDARD);
4444
setup_signal(shell, SIGQUIT, SIG_IGNORE);
4545
signal_to_all_subprocess(shell, SIGTERM);
4646
kill(getpid_from_proc(), SIGTERM);

0 commit comments

Comments
 (0)