From: Lennart Poettering Date: Mon, 26 Feb 2018 17:31:06 +0000 (+0100) Subject: logind: trivial improvements X-Git-Tag: v238~51^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=864fe630a7a1f11b735d818b8c79d2d1068e2f3f;p=thirdparty%2Fsystemd.git logind: trivial improvements Just some addition whitespace, some additional assert()s, and removal of redundant variables. --- diff --git a/src/login/logind-core.c b/src/login/logind-core.c index cd10536ce52..41b4d4d8d78 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -618,6 +618,8 @@ bool manager_is_on_external_power(void) { } bool manager_all_buttons_ignored(Manager *m) { + assert(m); + if (m->handle_power_key != HANDLE_IGNORE) return false; if (m->handle_suspend_key != HANDLE_IGNORE) @@ -631,5 +633,6 @@ bool manager_all_buttons_ignored(Manager *m) { return false; if (m->handle_lid_switch_docked != HANDLE_IGNORE) return false; + return true; } diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c index 067e67a93d5..b1bac04036a 100644 --- a/src/login/logind-session-device.c +++ b/src/login/logind-session-device.c @@ -74,20 +74,25 @@ static int session_device_notify(SessionDevice *sd, enum SessionDeviceNotificati return r; switch (type) { + case SESSION_DEVICE_RESUME: r = sd_bus_message_append(m, "uuh", major, minor, sd->fd); if (r < 0) return r; break; + case SESSION_DEVICE_TRY_PAUSE: t = "pause"; break; + case SESSION_DEVICE_PAUSE: t = "force"; break; + case SESSION_DEVICE_RELEASE: t = "gone"; break; + default: return -EINVAL; } @@ -120,24 +125,18 @@ static int sd_eviocrevoke(int fd) { } static int sd_drmsetmaster(int fd) { - int r; - assert(fd >= 0); - r = ioctl(fd, DRM_IOCTL_SET_MASTER, 0); - if (r < 0) + if (ioctl(fd, DRM_IOCTL_SET_MASTER, 0) < 0) return -errno; return 0; } static int sd_drmdropmaster(int fd) { - int r; - assert(fd >= 0); - r = ioctl(fd, DRM_IOCTL_DROP_MASTER, 0); - if (r < 0) + if (ioctl(fd, DRM_IOCTL_DROP_MASTER, 0) < 0) return -errno; return 0; @@ -146,7 +145,9 @@ static int sd_drmdropmaster(int fd) { static int session_device_open(SessionDevice *sd, bool active) { int fd, r; + assert(sd); assert(sd->type != DEVICE_TYPE_UNKNOWN); + assert(sd->node); /* open device and try to get an udev_device from it */ fd = open(sd->node, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK); @@ -154,28 +155,27 @@ static int session_device_open(SessionDevice *sd, bool active) { return -errno; switch (sd->type) { + case DEVICE_TYPE_DRM: if (active) { - /* Weird legacy DRM semantics might return an error - * even though we're master. No way to detect that so - * fail at all times and let caller retry in inactive - * state. */ + /* Weird legacy DRM semantics might return an error even though we're master. No way to detect + * that so fail at all times and let caller retry in inactive state. */ r = sd_drmsetmaster(fd); if (r < 0) { close_nointr(fd); return r; } - } else { - /* DRM-Master is granted to the first user who opens a - * device automatically (ughh, racy!). Hence, we just - * drop DRM-Master in case we were the first. */ + } else + /* DRM-Master is granted to the first user who opens a device automatically (ughh, + * racy!). Hence, we just drop DRM-Master in case we were the first. */ sd_drmdropmaster(fd); - } break; + case DEVICE_TYPE_EVDEV: if (!active) sd_eviocrevoke(fd); break; + case DEVICE_TYPE_UNKNOWN: default: /* fallback for devices wihout synchronizations */ @@ -195,26 +195,27 @@ static int session_device_start(SessionDevice *sd) { return 0; switch (sd->type) { + case DEVICE_TYPE_DRM: - /* Device is kept open. Simply call drmSetMaster() and hope - * there is no-one else. In case it fails, we keep the device - * paused. Maybe at some point we have a drmStealMaster(). */ + /* Device is kept open. Simply call drmSetMaster() and hope there is no-one else. In case it fails, we + * keep the device paused. Maybe at some point we have a drmStealMaster(). */ r = sd_drmsetmaster(sd->fd); if (r < 0) return r; break; + case DEVICE_TYPE_EVDEV: - /* Evdev devices are revoked while inactive. Reopen it and we - * are fine. */ + /* Evdev devices are revoked while inactive. Reopen it and we are fine. */ r = session_device_open(sd, true); if (r < 0) return r; - /* For evdev devices, the file descriptor might be left - * uninitialized. This might happen while resuming into a - * session and logind has been restarted right before. */ + + /* For evdev devices, the file descriptor might be left uninitialized. This might happen while resuming + * into a session and logind has been restarted right before. */ safe_close(sd->fd); sd->fd = r; break; + case DEVICE_TYPE_UNKNOWN: default: /* fallback for devices wihout synchronizations */ diff --git a/src/login/logind.c b/src/login/logind.c index 434a0698adb..875d467cbbe 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -455,7 +455,7 @@ static int manager_attach_fds(Manager *m) { sd = hashmap_get(s->devices, &st.st_rdev); if (!sd) { - /* Weird we got an fd for a session device which wasn't + /* Weird, we got an fd for a session device which wasn't * recorded in the session state file... */ log_warning("Got fd for missing session device [%u:%u] in session %s", major(st.st_rdev), minor(st.st_rdev), s->id);