diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-04-05 09:21:39 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-04-05 09:21:39 -0400 |
commit | 9939d98454db32635dd9d0887ac930d7a24440bc (patch) | |
tree | a04f638acd08d19528b21345dac64533f29e8669 | |
parent | 9e89daf21353d3739d84ed25ae99aab82704df97 (diff) | |
download | sway-9939d98454db32635dd9d0887ac930d7a24440bc.tar.xz |
Error handling in swaylock daemonize()
Fixes #1741
-rw-r--r-- | swaylock/main.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index 1d522184..4c6b44c6 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -23,12 +23,34 @@ #include "wlr-layer-shell-unstable-v1-client-protocol.h" static void daemonize() { + int fds[2]; + if (pipe(fds) != 0) { + wlr_log(L_ERROR, "Failed to pipe"); + exit(1); + } if (fork() == 0) { + close(fds[0]); int devnull = open("/dev/null", O_RDWR); dup2(STDOUT_FILENO, devnull); dup2(STDERR_FILENO, devnull); - chdir("/"); + uint8_t success = 0; + if (chdir("/") != 0) { + write(fds[1], &success, 1); + exit(1); + } + success = 1; + if (write(fds[1], &success, 1) != 1) { + exit(1); + } + close(fds[1]); } else { + close(fds[1]); + uint8_t success; + if (read(fds[0], &success, 1) != 1 || !success) { + wlr_log(L_ERROR, "Failed to daemonize"); + exit(1); + } + close(fds[0]); exit(0); } } |