From 039e529dbe802425318ed92da245f3e81e494e91 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Thu, 10 Sep 2020 16:40:32 +0300 Subject: [PATCH] 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. --- Userland/sleep.cpp | 5 ++--- 1 file 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; }