diff options
author | Oscar Cowdery Lack <oscar.cowderylack@gmail.com> | 2019-01-07 22:48:42 +1100 |
---|---|---|
committer | Oscar Cowdery Lack <oscar.cowderylack@gmail.com> | 2019-01-07 22:55:42 +1100 |
commit | 5a24ed2bf2b4826a41542e03449d96ddd6ab63e0 (patch) | |
tree | 44afae9eb5b4f830b306cf69c850c5f1aaa91998 | |
parent | 688f4137a573d87f591c86edafdaf7c0f4d0aee4 (diff) |
swayidle: Fix sleep inhibitor not being acquired
Fixes #3377.
The sleep lock file descriptor was immediately closed after it was
acquired due to the dbus message being freed. Now the fd is duplicated
before the message is freed so the inhibitor stays active.
-rw-r--r-- | swayidle/main.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/swayidle/main.c b/swayidle/main.c index 9a76e58c..41eecc41 100644 --- a/swayidle/main.c +++ b/swayidle/main.c @@ -1,6 +1,7 @@ #define _POSIX_C_SOURCE 200809L #include <assert.h> #include <errno.h> +#include <fcntl.h> #include <getopt.h> #include <pthread.h> #include <signal.h> @@ -104,9 +105,21 @@ static void acquire_sleep_lock(void) { if (ret < 0) { wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s", strerror(-ret)); + sd_bus_error_free(&error); + sd_bus_message_unref(msg); + return; } else { wlr_log(WLR_INFO, "Got sleep lock: %d", lock_fd); } + + // sd_bus_message_unref closes the file descriptor so we need + // to copy it beforehand + lock_fd = fcntl(lock_fd, F_DUPFD_CLOEXEC, 3); + if (lock_fd < 0) { + wlr_log(WLR_ERROR, "Failed to copy sleep lock fd: %s", + strerror(errno)); + } + sd_bus_error_free(&error); sd_bus_message_unref(msg); } |