On 25/02/19 22:35, Pádraig Brady wrote: > Thanks for doing all that. > I've attached a few changes: > > - spelling fixes > - usage() clarified/reordered > - ensure sigset_t are initialized > - Don't setprocmask() unless specified > - Simplified SETMASK_SIGNAL_OPTION handling > - The test missed `env` as a prerequisite > - The test was slow/spun cpu, so used sleep instead of seq > - Used $SHELL in case sh didn't support trap > > I see that the last signal that `kill -l` lists is not included. > I think we should be processing SIGNUM_BOUND also?
An additional patch attached to replace --list-signal-actions with --list-ignored-signals. This is simpler, and more symmetric with the other options. Also the extra output was moot I think since handlers are reset upon exec. For completeness the transitions are: upon fork default -> default handled -> handled ignored -> ignored pending -> cleared blocked -> blocked upon exec default -> default handled -> default ignored -> ignored pending -> pending blocked -> blocked shell has additional rules: can't unignore handled -> default in subshell I'll squash this into yours, before commit. cheers, Pádraig
>From a8e531b15a2e85ecf7d18526bfbb7990537621b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com> Date: Sun, 3 Mar 2019 15:29:59 -0800 Subject: [PATCH] env: use --list-ignored-signals instead of --list-signals-action This is more symmetric and anyway signal handlers are reset upon exec(), so the more complicated reporting is moot. --- src/env.c | 60 ++++++++++++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/src/env.c b/src/env.c index 1acfc11..74043b1 100644 --- a/src/env.c +++ b/src/env.c @@ -81,8 +81,8 @@ enum BLOCK_SIGNAL_OPTION, UNBLOCK_SIGNAL_OPTION, SETMASK_SIGNAL_OPTION, - LIST_SIGNAL_ACTIONS_OPTION, LIST_BLOCKED_SIGNALS_OPTION, + LIST_IGNORED_SIGNALS_OPTION, }; static struct option const longopts[] = @@ -93,11 +93,11 @@ static struct option const longopts[] = {"chdir", required_argument, NULL, 'C'}, {"default-signal", optional_argument, NULL, DEFAULT_SIGNAL_OPTION}, {"ignore-signal", optional_argument, NULL, IGNORE_SIGNAL_OPTION}, - {"list-signal-actions", no_argument, NULL, LIST_SIGNAL_ACTIONS_OPTION}, {"block-signal", optional_argument, NULL, BLOCK_SIGNAL_OPTION}, {"unblock-signal", optional_argument, NULL, UNBLOCK_SIGNAL_OPTION}, {"setmask-signal", optional_argument, NULL, SETMASK_SIGNAL_OPTION}, {"list-blocked-signals", no_argument, NULL, LIST_BLOCKED_SIGNALS_OPTION}, + {"list-ignored-signals", no_argument, NULL, LIST_IGNORED_SIGNALS_OPTION}, {"debug", no_argument, NULL, 'v'}, {"split-string", required_argument, NULL, 'S'}, {GETOPT_HELP_OPTION_DECL}, @@ -149,7 +149,7 @@ Set each NAME to VALUE in the environment and run COMMAND.\n\ --ignore-signal[=SIG] set handling of SIG signals(s) to do nothing\n\ "), stdout); fputs (_("\ - --list-signal-actions list signals with non-default actions and exit\n\ + --list-ignored-signals list ignored signals and exit\n\ "), stdout); fputs (_("\ --list-blocked-signals list blocked (masked) signals and exit\n\ @@ -680,34 +680,6 @@ reset_signal_handlers (void) } } -static void -list_signal_actions (void) -{ - char signame[SIG2STR_MAX]; - const char* action; - - for (int i = 1; i < SIGNUM_BOUND; i++) - { - struct sigaction act; - if (sigaction (i, NULL, &act)) - continue; - - if (act.sa_flags & SA_SIGINFO) - action = "sig-action"; - else if (act.sa_handler == SIG_DFL) - continue; /* no need to print defaults. */ - else if (act.sa_handler == SIG_IGN) - action = "ignore"; - else - action = "sig-handler"; - - sig2str (i, signame); - printf ("%-10s (%2d): %s\n", signame, i, action); - } - - exit (EXIT_SUCCESS); -} - static void parse_block_signal_params (const char* optarg, bool block) @@ -819,6 +791,26 @@ list_blocked_signals (void) exit (EXIT_SUCCESS); } +static void +list_ignored_signals (void) +{ + char signame[SIG2STR_MAX]; + + for (int i = 1; i < SIGNUM_BOUND; i++) + { + struct sigaction act; + if (sigaction (i, NULL, &act)) + continue; + + if (act.sa_handler != SIG_IGN) + continue; + + sig2str (i, signame); + printf ("%-10s (%2d)\n", signame, i); + } + + exit (EXIT_SUCCESS); +} int main (int argc, char **argv) @@ -863,9 +855,6 @@ main (int argc, char **argv) case IGNORE_SIGNAL_OPTION: parse_signal_action_params (optarg, false); break; - case LIST_SIGNAL_ACTIONS_OPTION: - list_signal_actions (); - break; case BLOCK_SIGNAL_OPTION: parse_block_signal_params (optarg, true); break; @@ -879,6 +868,9 @@ main (int argc, char **argv) case LIST_BLOCKED_SIGNALS_OPTION: list_blocked_signals (); break; + case LIST_IGNORED_SIGNALS_OPTION: + list_ignored_signals (); + break; case 'C': newdir = optarg; break; -- 2.9.3