From 23f8830a13a7f82837aef72f408ee0af53da3449 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Tue, 4 Feb 2020 10:29:55 -0500 Subject: Reap `xdg-screensaver` correctly Call waitpid(2) so spawned `xdg-screensaver` processes get reaped. --- xssxss.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xssxss.c b/xssxss.c index 17966de..ee15596 100644 --- a/xssxss.c +++ b/xssxss.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include "xssbase.h" @@ -47,6 +49,9 @@ static void* WakerThreadMain(void* const ignored) { // Start the process to wake up xscreensaver. When it exits, we'll get // SIGCHLD, but we don't care; see notes in `SpawnWakerThread`. + // + // TODO(bbaren@google.com): Once Linux 5.2 is deployed more widely, switch + // to using pidfds. pid_t waker_pid; char* const waker[] = {"xdg-screensaver", "reset", NULL}; const int e = posix_spawnp(&waker_pid, waker[0], /*file_action=*/NULL, @@ -55,6 +60,9 @@ static void* WakerThreadMain(void* const ignored) { char buf[128]; LogDebug("failed to spawn waker: %d", strerror_r(e, buf, 128)); } + if (waitpid(waker_pid, /*wstatus=*/NULL, /*options=*/0) < 0) { + LogDebug("failed to wait for waker; continuing"); + } sleep(kWakeupSeconds); } -- cgit v1.2.3