diff options
author | Nico Weber <thakis@chromium.org> | 2020-09-08 10:19:07 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-09 12:44:35 +0200 |
commit | 42153221a54cc58775a254633c54d869d19f95c7 (patch) | |
tree | 9544bb22dc31eb989e201b190f537abe3193faa2 /Userland | |
parent | 92bfe409548d1e7c27a85a72ba6ef806a63bd019 (diff) | |
download | serenity-42153221a54cc58775a254633c54d869d19f95c7.zip |
sleep: On SIGINT, call default SIGINT handler after printing remaining time
With this, hitting ctrl-c twice in `for i in $(seq 10) { sleep 1 }`
terminates the loop as expected (...well, I'd expect it to quit after
just one ctrl-c, but serenity's shell makes a single ctrl-c only
quit the current loop iteration).
Part of #3419.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/sleep.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Userland/sleep.cpp b/Userland/sleep.cpp index 32dd646275..025a144300 100644 --- a/Userland/sleep.cpp +++ b/Userland/sleep.cpp @@ -30,8 +30,10 @@ #include <string.h> #include <unistd.h> +static bool g_interrupted; static void handle_sigint(int) { + g_interrupted = true; } int main(int argc, char** argv) @@ -47,7 +49,7 @@ int main(int argc, char** argv) sa.sa_handler = handle_sigint; sigaction(SIGINT, &sa, nullptr); - if (pledge("stdio", nullptr) < 0) { + if (pledge("stdio sigaction", nullptr) < 0) { perror("pledge"); return 1; } @@ -56,5 +58,11 @@ int main(int argc, char** argv) if (remaining) { printf("Sleep interrupted with %u seconds remaining.\n", remaining); } + + if (g_interrupted) { + signal(SIGINT, SIG_DFL); + raise(SIGINT); + } + return 0; } |