diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-12-07 10:51:15 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-12-09 10:08:51 +0100 |
commit | c74d5fe25d53263c143f0a9c2698d8bb483e398c (patch) | |
tree | 04209041aba302c44acec1e66a209985dbc325db | |
parent | 1d9aa4d572b661fd6500c55ab524141332f76230 (diff) | |
download | systemd-c74d5fe25d53263c143f0a9c2698d8bb483e398c.tar.gz |
logind: fix closing of button input devices
This is a fix of #17751. Specifically:
1. Sort #include headers again
2. Remove tabs, as per coding style
3. Don't install fds in half-initialized objects
4. Use asynchronous_close() everywhere
That all said:
Quit frankly, I am not convinced we should do all this at all. If
close()ing of these input devices is really that slow, then this should
probably be fixed in the kernel, not worked around in userspace like
this.
-rw-r--r-- | src/login/logind-button.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/login/logind-button.c b/src/login/logind-button.c index 60de2dccad..0e38b5f57c 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -8,12 +8,12 @@ #include "sd-messages.h" #include "alloc-util.h" +#include "async.h" #include "fd-util.h" #include "logind-button.h" #include "missing_input.h" #include "string-util.h" #include "util.h" -#include "async.h" #define CONST_MAX5(a, b, c, d, e) CONST_MAX(CONST_MAX(a, b), CONST_MAX(CONST_MAX(c, d), e)) @@ -60,11 +60,7 @@ void button_free(Button *b) { sd_event_source_unref(b->io_event_source); sd_event_source_unref(b->check_event_source); - if (b->fd >= 0) - /* If the device has been unplugged close() returns - * ENODEV, let's ignore this, hence we don't use - * safe_close() */ - (void) asynchronous_close(b->fd); + asynchronous_close(b->fd); free(b->name); free(b->seat); @@ -327,14 +323,14 @@ static int button_set_mask(const char *name, int fd) { } int button_open(Button *b) { - _cleanup_close_ int fd = -1; + _cleanup_(asynchronous_closep) int fd = -1; const char *p; char name[256]; int r; assert(b); - b->fd = safe_close(b->fd); + b->fd = asynchronous_close(b->fd); p = strjoina("/dev/input/", b->name); @@ -345,12 +341,10 @@ int button_open(Button *b) { r = button_suitable(fd); if (r < 0) return log_warning_errno(r, "Failed to determine whether input device %s is relevant to us: %m", p); - if (r == 0) { - b->fd = TAKE_FD(fd); + if (r == 0) return log_debug_errno(SYNTHETIC_ERRNO(EADDRNOTAVAIL), "Device %s does not expose keys or switches relevant to us, ignoring.", p); - } - + if (ioctl(fd, EVIOCGNAME(sizeof name), name) < 0) return log_error_errno(errno, "Failed to get input name for %s: %m", p); |