From a4dc04a28e577a13f3748a0193c5e2d5d3792b36 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Thu, 14 Feb 2019 20:55:43 -0800 Subject: [PATCH] Add sighupint topic This corresponds to SIGHUP and SIGINT. This will be used to break out of process_mark_finished_children(). --- src/enum_set.h | 4 ++++ src/fish_tests.cpp | 14 ++++++++------ src/signal.cpp | 2 ++ src/topic_monitor.h | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/enum_set.h b/src/enum_set.h index 22eb8c66d..cbec399d0 100644 --- a/src/enum_set.h +++ b/src/enum_set.h @@ -31,6 +31,10 @@ class enum_set_t : private std::bitset()> { /*implicit*/ enum_set_t(T v) { set(v); } + /*implicit*/ enum_set_t(std::initializer_list vs) { + for (T v : vs) set(v); + } + static enum_set_t from_raw(unsigned long v) { return enum_set_t{v}; } unsigned long to_raw() const { return super::to_ulong(); } diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index dc2522784..538b05ebd 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -5102,14 +5102,15 @@ static void test_topic_monitor_torture() { say(L"Torture-testing topic monitor"); topic_monitor_t monitor; const size_t thread_count = 64; - constexpr auto t = topic_t::sigchld; + constexpr auto t1 = topic_t::sigchld; + constexpr auto t2 = topic_t::sighupint; std::vector gens; gens.resize(thread_count, generation_list_t{}); std::atomic post_count{}; for (auto &gen : gens) { gen = monitor.current_generations(); post_count += 1; - monitor.post(t); + monitor.post(t1); } std::atomic completed{}; @@ -5119,9 +5120,10 @@ static void test_topic_monitor_torture() { [&](size_t i) { for (size_t j = 0; j < (1 << 11); j++) { auto before = gens[i]; - auto changed = monitor.check(&gens[i], topic_set_t{t}, true /* wait */); - do_test(before[t] < gens[i][t]); - do_test(gens[i][t] <= post_count); + auto changed = monitor.check(&gens[i], topic_set_t{t1, t2}, true /* wait */); + do_test(before[t1] < gens[i][t1]); + do_test(gens[i][t1] <= post_count); + do_test(gens[i][t2] == 0); } auto amt = completed.fetch_add(1, std::memory_order_relaxed); }, @@ -5130,7 +5132,7 @@ static void test_topic_monitor_torture() { while (completed.load(std::memory_order_relaxed) < thread_count) { post_count += 1; - monitor.post(t); + monitor.post(t1); } for (auto &t : threads) t.join(); } diff --git a/src/signal.cpp b/src/signal.cpp index 8ca202330..927eb2dae 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -231,6 +231,7 @@ static void handle_hup(int sig, siginfo_t *info, void *context) { } else { reader_exit(1, 1); } + topic_monitor_t::principal().post(topic_t::sighupint); } /// Handle sigterm. The only thing we do is restore the front process ID, then die. @@ -249,6 +250,7 @@ static void handle_int(int sig, siginfo_t *info, void *context) { if (reraise_if_forked_child(sig)) return; reader_handle_sigint(); default_handler(sig, info, context); + topic_monitor_t::principal().post(topic_t::sighupint); } /// Non-interactive ^C handler. diff --git a/src/topic_monitor.h b/src/topic_monitor.h index fb61f06e5..f74c900ec 100644 --- a/src/topic_monitor.h +++ b/src/topic_monitor.h @@ -35,7 +35,8 @@ /// The list of topics that may be observed. enum class topic_t : uint8_t { - sigchld, // Corresponds to SIGCHLD signal. + sigchld, // Corresponds to SIGCHLD signal. + sighupint, // Corresponds to both SIGHUP and SIGINT signals. COUNT };