mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
logind: trivial improvements
Just some addition whitespace, some additional assert()s, and removal of redundant variables.
This commit is contained in:
parent
f2e3f36950
commit
864fe630a7
@ -618,6 +618,8 @@ bool manager_is_on_external_power(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool manager_all_buttons_ignored(Manager *m) {
|
bool manager_all_buttons_ignored(Manager *m) {
|
||||||
|
assert(m);
|
||||||
|
|
||||||
if (m->handle_power_key != HANDLE_IGNORE)
|
if (m->handle_power_key != HANDLE_IGNORE)
|
||||||
return false;
|
return false;
|
||||||
if (m->handle_suspend_key != HANDLE_IGNORE)
|
if (m->handle_suspend_key != HANDLE_IGNORE)
|
||||||
@ -631,5 +633,6 @@ bool manager_all_buttons_ignored(Manager *m) {
|
|||||||
return false;
|
return false;
|
||||||
if (m->handle_lid_switch_docked != HANDLE_IGNORE)
|
if (m->handle_lid_switch_docked != HANDLE_IGNORE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -74,20 +74,25 @@ static int session_device_notify(SessionDevice *sd, enum SessionDeviceNotificati
|
|||||||
return r;
|
return r;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
case SESSION_DEVICE_RESUME:
|
case SESSION_DEVICE_RESUME:
|
||||||
r = sd_bus_message_append(m, "uuh", major, minor, sd->fd);
|
r = sd_bus_message_append(m, "uuh", major, minor, sd->fd);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SESSION_DEVICE_TRY_PAUSE:
|
case SESSION_DEVICE_TRY_PAUSE:
|
||||||
t = "pause";
|
t = "pause";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SESSION_DEVICE_PAUSE:
|
case SESSION_DEVICE_PAUSE:
|
||||||
t = "force";
|
t = "force";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SESSION_DEVICE_RELEASE:
|
case SESSION_DEVICE_RELEASE:
|
||||||
t = "gone";
|
t = "gone";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -120,24 +125,18 @@ static int sd_eviocrevoke(int fd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int sd_drmsetmaster(int fd) {
|
static int sd_drmsetmaster(int fd) {
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
|
|
||||||
r = ioctl(fd, DRM_IOCTL_SET_MASTER, 0);
|
if (ioctl(fd, DRM_IOCTL_SET_MASTER, 0) < 0)
|
||||||
if (r < 0)
|
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sd_drmdropmaster(int fd) {
|
static int sd_drmdropmaster(int fd) {
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
|
|
||||||
r = ioctl(fd, DRM_IOCTL_DROP_MASTER, 0);
|
if (ioctl(fd, DRM_IOCTL_DROP_MASTER, 0) < 0)
|
||||||
if (r < 0)
|
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -146,7 +145,9 @@ static int sd_drmdropmaster(int fd) {
|
|||||||
static int session_device_open(SessionDevice *sd, bool active) {
|
static int session_device_open(SessionDevice *sd, bool active) {
|
||||||
int fd, r;
|
int fd, r;
|
||||||
|
|
||||||
|
assert(sd);
|
||||||
assert(sd->type != DEVICE_TYPE_UNKNOWN);
|
assert(sd->type != DEVICE_TYPE_UNKNOWN);
|
||||||
|
assert(sd->node);
|
||||||
|
|
||||||
/* open device and try to get an udev_device from it */
|
/* open device and try to get an udev_device from it */
|
||||||
fd = open(sd->node, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
|
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;
|
return -errno;
|
||||||
|
|
||||||
switch (sd->type) {
|
switch (sd->type) {
|
||||||
|
|
||||||
case DEVICE_TYPE_DRM:
|
case DEVICE_TYPE_DRM:
|
||||||
if (active) {
|
if (active) {
|
||||||
/* Weird legacy DRM semantics might return an error
|
/* Weird legacy DRM semantics might return an error even though we're master. No way to detect
|
||||||
* even though we're master. No way to detect that so
|
* that so fail at all times and let caller retry in inactive state. */
|
||||||
* fail at all times and let caller retry in inactive
|
|
||||||
* state. */
|
|
||||||
r = sd_drmsetmaster(fd);
|
r = sd_drmsetmaster(fd);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
close_nointr(fd);
|
close_nointr(fd);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
/* DRM-Master is granted to the first user who opens a
|
/* DRM-Master is granted to the first user who opens a device automatically (ughh,
|
||||||
* device automatically (ughh, racy!). Hence, we just
|
* racy!). Hence, we just drop DRM-Master in case we were the first. */
|
||||||
* drop DRM-Master in case we were the first. */
|
|
||||||
sd_drmdropmaster(fd);
|
sd_drmdropmaster(fd);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DEVICE_TYPE_EVDEV:
|
case DEVICE_TYPE_EVDEV:
|
||||||
if (!active)
|
if (!active)
|
||||||
sd_eviocrevoke(fd);
|
sd_eviocrevoke(fd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DEVICE_TYPE_UNKNOWN:
|
case DEVICE_TYPE_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
/* fallback for devices wihout synchronizations */
|
/* fallback for devices wihout synchronizations */
|
||||||
@ -195,26 +195,27 @@ static int session_device_start(SessionDevice *sd) {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch (sd->type) {
|
switch (sd->type) {
|
||||||
|
|
||||||
case DEVICE_TYPE_DRM:
|
case DEVICE_TYPE_DRM:
|
||||||
/* Device is kept open. Simply call drmSetMaster() and hope
|
/* Device is kept open. Simply call drmSetMaster() and hope there is no-one else. In case it fails, we
|
||||||
* there is no-one else. In case it fails, we keep the device
|
* keep the device paused. Maybe at some point we have a drmStealMaster(). */
|
||||||
* paused. Maybe at some point we have a drmStealMaster(). */
|
|
||||||
r = sd_drmsetmaster(sd->fd);
|
r = sd_drmsetmaster(sd->fd);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DEVICE_TYPE_EVDEV:
|
case DEVICE_TYPE_EVDEV:
|
||||||
/* Evdev devices are revoked while inactive. Reopen it and we
|
/* Evdev devices are revoked while inactive. Reopen it and we are fine. */
|
||||||
* are fine. */
|
|
||||||
r = session_device_open(sd, true);
|
r = session_device_open(sd, true);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
/* For evdev devices, the file descriptor might be left
|
|
||||||
* uninitialized. This might happen while resuming into a
|
/* For evdev devices, the file descriptor might be left uninitialized. This might happen while resuming
|
||||||
* session and logind has been restarted right before. */
|
* into a session and logind has been restarted right before. */
|
||||||
safe_close(sd->fd);
|
safe_close(sd->fd);
|
||||||
sd->fd = r;
|
sd->fd = r;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DEVICE_TYPE_UNKNOWN:
|
case DEVICE_TYPE_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
/* fallback for devices wihout synchronizations */
|
/* fallback for devices wihout synchronizations */
|
||||||
|
@ -455,7 +455,7 @@ static int manager_attach_fds(Manager *m) {
|
|||||||
|
|
||||||
sd = hashmap_get(s->devices, &st.st_rdev);
|
sd = hashmap_get(s->devices, &st.st_rdev);
|
||||||
if (!sd) {
|
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... */
|
* recorded in the session state file... */
|
||||||
log_warning("Got fd for missing session device [%u:%u] in session %s",
|
log_warning("Got fd for missing session device [%u:%u] in session %s",
|
||||||
major(st.st_rdev), minor(st.st_rdev), s->id);
|
major(st.st_rdev), minor(st.st_rdev), s->id);
|
||||||
|
Loading…
Reference in New Issue
Block a user