summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-02-26 18:31:06 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:59:06 +0200
commitc70a304dfcc93d3360413dbb4c36884c33f5f201 (patch)
tree472b495f7eca261fc744f0fdcca54cd3a9e18537 /src
parent2ec539cba1bc8ad1f6437eb91e4b81db7944e124 (diff)
logind: trivial improvements
Just some addition whitespace, some additional assert()s, and removal of redundant variables.
Diffstat (limited to 'src')
-rw-r--r--src/login/logind-core.c3
-rw-r--r--src/login/logind-session-device.c51
-rw-r--r--src/login/logind.c12
3 files changed, 35 insertions, 31 deletions
diff --git a/src/login/logind-core.c b/src/login/logind-core.c
index c4dd48e08..559307c15 100644
--- a/src/login/logind-core.c
+++ b/src/login/logind-core.c
@@ -647,6 +647,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)
@@ -660,5 +662,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 9d1256dca..cc56e62df 100644
--- a/src/login/logind-session-device.c
+++ b/src/login/logind-session-device.c
@@ -78,20 +78,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;
}
@@ -124,24 +129,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;
@@ -150,7 +149,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);
@@ -158,28 +159,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 */
@@ -199,26 +199,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 7246c13ec..ed250bc2a 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -482,7 +482,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);
@@ -1002,7 +1002,7 @@ static void manager_gc(Manager *m, bool drop_not_started) {
LIST_REMOVE(gc_queue, m->seat_gc_queue, seat);
seat->in_gc_queue = false;
- if (!seat_check_gc(seat, drop_not_started)) {
+ if (seat_may_gc(seat, drop_not_started)) {
seat_stop(seat, false);
seat_free(seat);
}
@@ -1013,14 +1013,14 @@ static void manager_gc(Manager *m, bool drop_not_started) {
session->in_gc_queue = false;
/* First, if we are not closing yet, initiate stopping */
- if (!session_check_gc(session, drop_not_started) &&
+ if (session_may_gc(session, drop_not_started) &&
session_get_state(session) != SESSION_CLOSING)
session_stop(session, false);
/* Normally, this should make the session referenced
* again, if it doesn't then let's get rid of it
* immediately */
- if (!session_check_gc(session, drop_not_started)) {
+ if (session_may_gc(session, drop_not_started)) {
session_finalize(session);
session_free(session);
}
@@ -1031,11 +1031,11 @@ static void manager_gc(Manager *m, bool drop_not_started) {
user->in_gc_queue = false;
/* First step: queue stop jobs */
- if (!user_check_gc(user, drop_not_started))
+ if (user_may_gc(user, drop_not_started))
user_stop(user, false);
/* Second step: finalize user */
- if (!user_check_gc(user, drop_not_started)) {
+ if (user_may_gc(user, drop_not_started)) {
user_finalize(user);
user_free(user);
}