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.
This commit is contained in:
Sergey Bugaev 2020-09-10 16:40:32 +03:00 committed by Andreas Kling
parent 0055a28710
commit 039e529dbe
Notes: sideshowbarker 2024-07-19 02:47:36 +09:00

View file

@ -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);
if (g_interrupted)
raise(SIGINT);
}
return 0;
}