diff options
author | Benjamin Barenblat <bbaren@google.com> | 2020-02-04 10:29:55 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2020-02-04 10:29:55 -0500 |
commit | 23f8830a13a7f82837aef72f408ee0af53da3449 (patch) | |
tree | 7944f9f4dc7d8c9dbe437445f4fc3334dddd9f78 | |
parent | cd8509637458c2e3ceedbe173ff20180ce0ea25a (diff) |
Reap `xdg-screensaver` correctly
Call waitpid(2) so spawned `xdg-screensaver` processes get reaped.
-rw-r--r-- | xssxss.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -21,6 +21,8 @@ #include <pthread.h> #include <signal.h> #include <spawn.h> +#include <sys/types.h> +#include <sys/wait.h> #include <unistd.h> #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); } |