From 8301aa99295277125bec7deaf86f29f817117389 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 10 Aug 2020 12:26:30 -0700 Subject: [PATCH] Add a test that nohup works If fish is invoked with nohup, then its children should be nohup too. --- src/fish_test_helper.cpp | 31 ++++++++++++++++++++++++------- tests/checks/sigint.fish | 9 ++++++++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/fish_test_helper.cpp b/src/fish_test_helper.cpp index 988b85d5d..de19d970d 100644 --- a/src/fish_test_helper.cpp +++ b/src/fish_test_helper.cpp @@ -74,6 +74,17 @@ static void print_fds() { fputc('\n', stdout); } +static void print_signal(int sig) { + // Print a signal description to stderr. + if (const char *s = strsignal(sig)) { + fprintf(stderr, "%s", s); + if (strchr(s, ':') == nullptr) { + fprintf(stderr, ": %d", sig); + } + fprintf(stderr, "\n"); + } +} + static void print_blocked_signals() { sigset_t sigs; sigemptyset(&sigs); @@ -87,13 +98,17 @@ static void print_blocked_signals() { // NetBSD taps out at 63, Linux at 64. for (int sig = 1; sig < 33; sig++) { if (sigismember(&sigs, sig)) { - if (const char *s = strsignal(sig)) { - fprintf(stderr, "%s", s); - if (strchr(s, ':') == nullptr) { - fprintf(stderr, ": %d", sig); - } - fprintf(stderr, "\n"); - } + print_signal(sig); + } + } +} + +static void print_ignored_signals() { + for (int sig = 1; sig < 33; sig++) { + struct sigaction act = {}; + sigaction(sig, nullptr, &act); + if (act.sa_handler == SIG_IGN) { + print_signal(sig); } } } @@ -125,6 +140,8 @@ static fth_command_t s_commands[] = { {"print_fds", print_fds, "Print the list of active FDs to stdout"}, {"print_blocked_signals", print_blocked_signals, "Print to stdout the name(s) of blocked signals"}, + {"print_ignored_signals", print_ignored_signals, + "Print to stdout the name(s) of ignored signals"}, {"help", show_help, "Print list of fish_test_helper commands"}, }; diff --git a/tests/checks/sigint.fish b/tests/checks/sigint.fish index bb645fd1d..483cccf92 100644 --- a/tests/checks/sigint.fish +++ b/tests/checks/sigint.fish @@ -1,7 +1,14 @@ #RUN: %fish -C "set helper %fish_test_helper" %s -# Block some signals if job control is off (#6828). +# Check that nohup is propagated. +set fish (status fish-path) +set output_path (mktemp) +nohup $fish -c "$helper print_ignored_signals" 2>&1 > $output_path +cat $output_path +# CHECK: Hangup: 1 +rm $output_path +# Block some signals if job control is off (#6828). status job-control none for fish_use_posix_spawn in 0 1 $helper print_blocked_signals &