From 0fd525e85e9297c999c1b651a943743c68103729 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Thu, 6 Aug 2020 02:23:12 +0200 Subject: logind: close_device always returned error Error handling was broken in close_device, always returning -1. Use the return value, and add a few errno assignments while we're at it. --- libseat/backend/logind.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'libseat') diff --git a/libseat/backend/logind.c b/libseat/backend/logind.c index 7224508..ea2821c 100644 --- a/libseat/backend/logind.c +++ b/libseat/backend/logind.c @@ -115,6 +115,7 @@ out: static int close_device(struct libseat *base, int device_id) { struct backend_logind *session = backend_logind_from_libseat_backend(base); if (device_id < 0) { + errno = EINVAL; return -1; } @@ -133,19 +134,20 @@ static int close_device(struct libseat *base, int device_id) { sd_bus_message *msg = NULL; sd_bus_error error = SD_BUS_ERROR_NULL; - sd_bus_call_method(session->bus, "org.freedesktop.login1", session->path, - "org.freedesktop.login1.Session", "ReleaseDevice", &error, &msg, "uu", - major(st.st_rdev), minor(st.st_rdev)); + int ret = sd_bus_call_method(session->bus, "org.freedesktop.login1", session->path, + "org.freedesktop.login1.Session", "ReleaseDevice", &error, + &msg, "uu", major(st.st_rdev), minor(st.st_rdev)); sd_bus_error_free(&error); sd_bus_message_unref(msg); - return -1; + return ret >= 0; } static int switch_session(struct libseat *base, int s) { struct backend_logind *session = backend_logind_from_libseat_backend(base); if (s >= UINT16_MAX || s < 0) { + errno = EINVAL; return -1; } @@ -192,6 +194,7 @@ static int poll_connection(struct backend_logind *backend, int timeout) { } if (fd.revents & (POLLERR | POLLHUP)) { + errno = ECONNRESET; return -1; } return 0; -- cgit v1.2.3