mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
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.
This commit is contained in:
parent
92bfe40954
commit
42153221a5
Notes:
sideshowbarker
2024-07-19 02:49:27 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/42153221a54 Pull-request: https://github.com/SerenityOS/serenity/pull/3438
1 changed files with 9 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue