Skip to content

Commit a1ee7d0

Browse files
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>
1 parent bb0a34c commit a1ee7d0

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ written on the kernel's own calls.
88
openkal = "0.17.0"
99

1010
[target.'cfg(os = "macos")'.dependencies]
11-
openkal-macos = "0.15.0"
11+
openkal-macos = "0.15.1"
1212
```
1313

1414
Its purpose is as much to test the specification as to be used. A specification

‎mcpp.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
namespace = "mcpplibs"
33
name = "openkal-macos"
4-
version = "0.15.0"
4+
version = "0.15.1"
55
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."
66
license = "Apache-2.0"
77

‎src/process.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,10 @@ const kal_u32* kal_process_stop_requested(void) {
865865
int state = __atomic_load_n(&g_stop_armed, __ATOMIC_ACQUIRE);
866866
if (state == 0) {
867867
// SIGTERM is the one `kal_process_terminate' sends here; SIGINT is what
868-
// an interactive stream delivers. Both are requests to end, which is the
868+
// an interactive stream delivers; SIGHUP is the terminal that started
869+
// the program closing (0.15.1). All are requests to end, which is the
869870
// whole of what this word reports.
870-
const bool ok = arm_one(15) && arm_one(2);
871+
const bool ok = arm_one(15) && arm_one(2) && arm_one(1);
871872
state = ok ? 1 : -1;
872873
__atomic_store_n(&g_stop_armed, state, __ATOMIC_RELEASE);
873874
}

‎tests/stop_word_and_sigpipe.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ void check(bool held, const char* what) {
2323
}
2424

2525
int main(int argc, char** argv) {
26+
if (argc > 1 && std::strcmp(argv[1], "--hang-up") == 0) {
27+
const kal_u32* word = kal_process_stop_requested();
28+
if (word == nullptr) return 90;
29+
::kill(::getpid(), SIGHUP);
30+
for (int i = 0; i < 1000 && *word == 0; ++i) ::usleep(1000);
31+
if (*word == 0) return 91;
32+
kal_process_end_as_requested();
33+
return 92;
34+
}
2635
if (argc > 1 && std::strcmp(argv[1], "--end-as-requested") == 0) {
2736
const kal_u32* word = kal_process_stop_requested();
2837
if (word == nullptr) return 90;
@@ -57,6 +66,15 @@ int main(int argc, char** argv) {
5766
::waitpid(child, &st, 0);
5867
check(WIFSIGNALED(st) && WTERMSIG(st) == SIGTERM,
5968
"a program that ends as requested is reported to its starter as ended by the request");
69+
const pid_t hung = ::fork();
70+
if (hung == 0) {
71+
::execl(self, argv[0], "--hang-up", nullptr);
72+
::_exit(93);
73+
}
74+
st = 0;
75+
::waitpid(hung, &st, 0);
76+
check(WIFSIGNALED(st) && WTERMSIG(st) == SIGHUP,
77+
"a hang-up is taken over as a request, and the program ends as it would have (0.15.1)");
6078
#else
6179
(void)word; (void)argv;
6280
#endif

0 commit comments

Comments
 (0)