From a1ee7d0030eda1838932af29e986859c820cd2b8 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Tue, 27 Oct 2026 08:37:25 +0900 Subject: [PATCH] 0.15.1: the closing of the terminal is a request to end, taken over with SIGTERM and SIGINT Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com> --- README.md | 2 +- mcpp.toml | 2 +- src/process.cpp | 5 +++-- tests/stop_word_and_sigpipe.cpp | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c3b2959..44f1cf0 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ written on the kernel's own calls. openkal = "0.17.0" [target.'cfg(os = "macos")'.dependencies] -openkal-macos = "0.15.0" +openkal-macos = "0.15.1" ``` Its purpose is as much to test the specification as to be used. A specification diff --git a/mcpp.toml b/mcpp.toml index 933edff..5daacfa 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,7 +1,7 @@ [package] namespace = "mcpplibs" name = "openkal-macos" -version = "0.15.0" +version = "0.15.1" description = "An implementation of openkal for macOS, written on the kernel's own calls. Its purpose is as much to test the specification as to be used." license = "Apache-2.0" diff --git a/src/process.cpp b/src/process.cpp index 4a1723f..6da054d 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -865,9 +865,10 @@ const kal_u32* kal_process_stop_requested(void) { int state = __atomic_load_n(&g_stop_armed, __ATOMIC_ACQUIRE); if (state == 0) { // SIGTERM is the one `kal_process_terminate' sends here; SIGINT is what - // an interactive stream delivers. Both are requests to end, which is the + // an interactive stream delivers; SIGHUP is the terminal that started + // the program closing (0.15.1). All are requests to end, which is the // whole of what this word reports. - const bool ok = arm_one(15) && arm_one(2); + const bool ok = arm_one(15) && arm_one(2) && arm_one(1); state = ok ? 1 : -1; __atomic_store_n(&g_stop_armed, state, __ATOMIC_RELEASE); } diff --git a/tests/stop_word_and_sigpipe.cpp b/tests/stop_word_and_sigpipe.cpp index 6a86c39..c26151f 100644 --- a/tests/stop_word_and_sigpipe.cpp +++ b/tests/stop_word_and_sigpipe.cpp @@ -23,6 +23,15 @@ void check(bool held, const char* what) { } int main(int argc, char** argv) { + if (argc > 1 && std::strcmp(argv[1], "--hang-up") == 0) { + const kal_u32* word = kal_process_stop_requested(); + if (word == nullptr) return 90; + ::kill(::getpid(), SIGHUP); + for (int i = 0; i < 1000 && *word == 0; ++i) ::usleep(1000); + if (*word == 0) return 91; + kal_process_end_as_requested(); + return 92; + } if (argc > 1 && std::strcmp(argv[1], "--end-as-requested") == 0) { const kal_u32* word = kal_process_stop_requested(); if (word == nullptr) return 90; @@ -57,6 +66,15 @@ int main(int argc, char** argv) { ::waitpid(child, &st, 0); check(WIFSIGNALED(st) && WTERMSIG(st) == SIGTERM, "a program that ends as requested is reported to its starter as ended by the request"); + const pid_t hung = ::fork(); + if (hung == 0) { + ::execl(self, argv[0], "--hang-up", nullptr); + ::_exit(93); + } + st = 0; + ::waitpid(hung, &st, 0); + check(WIFSIGNALED(st) && WTERMSIG(st) == SIGHUP, + "a hang-up is taken over as a request, and the program ends as it would have (0.15.1)"); #else (void)word; (void)argv; #endif