aboutsummaryrefslogtreecommitdiffstats
path: root/swayidle
diff options
context:
space:
mode:
authorLibravatar Oscar Cowdery Lack <oscar.cowderylack@gmail.com>2019-01-07 22:48:42 +1100
committerLibravatar Oscar Cowdery Lack <oscar.cowderylack@gmail.com>2019-01-07 22:55:42 +1100
commit5a24ed2bf2b4826a41542e03449d96ddd6ab63e0 (patch)
tree44afae9eb5b4f830b306cf69c850c5f1aaa91998 /swayidle
parentMerge pull request #3378 from jbeich/master (diff)
downloadsway-5a24ed2bf2b4826a41542e03449d96ddd6ab63e0.tar.gz
sway-5a24ed2bf2b4826a41542e03449d96ddd6ab63e0.tar.zst
sway-5a24ed2bf2b4826a41542e03449d96ddd6ab63e0.zip
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.
Diffstat (limited to 'swayidle')
-rw-r--r--swayidle/main.c13
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 @@
1#define _POSIX_C_SOURCE 200809L 1#define _POSIX_C_SOURCE 200809L
2#include <assert.h> 2#include <assert.h>
3#include <errno.h> 3#include <errno.h>
4#include <fcntl.h>
4#include <getopt.h> 5#include <getopt.h>
5#include <pthread.h> 6#include <pthread.h>
6#include <signal.h> 7#include <signal.h>
@@ -104,9 +105,21 @@ static void acquire_sleep_lock(void) {
104 if (ret < 0) { 105 if (ret < 0) {
105 wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s", 106 wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s",
106 strerror(-ret)); 107 strerror(-ret));
108 sd_bus_error_free(&error);
109 sd_bus_message_unref(msg);
110 return;
107 } else { 111 } else {
108 wlr_log(WLR_INFO, "Got sleep lock: %d", lock_fd); 112 wlr_log(WLR_INFO, "Got sleep lock: %d", lock_fd);
109 } 113 }
114
115 // sd_bus_message_unref closes the file descriptor so we need
116 // to copy it beforehand
117 lock_fd = fcntl(lock_fd, F_DUPFD_CLOEXEC, 3);
118 if (lock_fd < 0) {
119 wlr_log(WLR_ERROR, "Failed to copy sleep lock fd: %s",
120 strerror(errno));
121 }
122
110 sd_bus_error_free(&error); 123 sd_bus_error_free(&error);
111 sd_bus_message_unref(msg); 124 sd_bus_message_unref(msg);
112} 125}