diff options
author | Sergey Bugaev <bugaevc@serenityos.org> | 2020-09-10 16:40:32 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-10 16:00:11 +0200 |
commit | 039e529dbe802425318ed92da245f3e81e494e91 (patch) | |
tree | c3e4c62e728d7eb08a5d60b57277effc20aee8f0 /Userland | |
parent | 0055a28710731e25d889536c0f6dd8bbb8f69509 (diff) | |
download | serenity-039e529dbe802425318ed92da245f3e81e494e91.zip |
Userland: Fix a signal race condition
It has been possible for a signal to arrive in between us checking
g_interrupted and exiting - sucessfully, even though we were interrupted.
This way, if a signal arrives before we reset the disposition, we
will reliably check for it later; if it arrives afterwards, it'll
kill us automatically.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/sleep.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Userland/sleep.cpp b/Userland/sleep.cpp index c21c06b814..6cbc4465a6 100644 --- a/Userland/sleep.cpp +++ b/Userland/sleep.cpp @@ -59,10 +59,9 @@ int main(int argc, char** argv) printf("Sleep interrupted with %u seconds remaining.\n", remaining); } - if (g_interrupted) { - signal(SIGINT, SIG_DFL); + signal(SIGINT, SIG_DFL); + if (g_interrupted) raise(SIGINT); - } return 0; } |