Skip to content

Commit

Permalink
Fix log message about lock fd
Browse files Browse the repository at this point in the history
  • Loading branch information
ianyfan committed Jan 13, 2019
1 parent 63921a2 commit 161bc3c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,27 @@ static void acquire_sleep_lock(void) {
if (ret < 0) {
swayidle_log(LOG_ERROR,
"Failed to send Inhibit signal: %s", error.message);
sd_bus_error_free(&error);
return;
goto cleanup;
}

ret = sd_bus_message_read(msg, "h", &lock_fd);
if (ret < 0) {
errno = -ret;
swayidle_log_errno(LOG_ERROR,
"Failed to parse D-Bus response for Inhibit");
sd_bus_error_free(&error);
sd_bus_message_unref(msg);
return;
} else {
swayidle_log(LOG_INFO, "Got sleep lock: %d", lock_fd);
goto cleanup;
}

// 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) {
swayidle_log(LOG_ERROR, "Failed to copy sleep lock fd");
if (lock_fd >= 0) {
swayidle_log(LOG_INFO, "Got sleep lock: %d", lock_fd);
} else {
swayidle_log_errno(LOG_ERROR, "Failed to copy sleep lock fd");
}

cleanup:
sd_bus_error_free(&error);
sd_bus_message_unref(msg);
}
Expand Down

0 comments on commit 161bc3c

Please sign in to comment.