diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-02-26 18:45:45 +0100 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2018-05-30 07:59:07 +0200 |
commit | 746dd725294bda772acdfb819feb60015bddec4f (patch) | |
tree | c4db7033f5442dadd0760426b1467eb107b83e36 /src/libelogind | |
parent | b3e7eed4422277091947069c55cc3bc4e4f16f9c (diff) |
sd-login: make use of _cleanup_close_ where possible
Diffstat (limited to 'src/libelogind')
-rw-r--r-- | src/libelogind/sd-login/sd-login.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/libelogind/sd-login/sd-login.c b/src/libelogind/sd-login/sd-login.c index bc5f83eb3..53dc6bc84 100644 --- a/src/libelogind/sd-login/sd-login.c +++ b/src/libelogind/sd-login/sd-login.c @@ -1020,8 +1020,9 @@ static inline sd_login_monitor* FD_TO_MONITOR(int fd) { } _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { - int fd, k; + _cleanup_close_ int fd = -1; bool good = false; + int k; assert_return(m, -EINVAL); @@ -1031,50 +1032,42 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { if (!category || streq(category, "seat")) { k = inotify_add_watch(fd, "/run/systemd/seats/", IN_MOVED_TO|IN_DELETE); - if (k < 0) { - safe_close(fd); + if (k < 0) return -errno; - } good = true; } if (!category || streq(category, "session")) { k = inotify_add_watch(fd, "/run/systemd/sessions/", IN_MOVED_TO|IN_DELETE); - if (k < 0) { - safe_close(fd); + if (k < 0) return -errno; - } good = true; } if (!category || streq(category, "uid")) { k = inotify_add_watch(fd, "/run/systemd/users/", IN_MOVED_TO|IN_DELETE); - if (k < 0) { - safe_close(fd); + if (k < 0) return -errno; - } good = true; } if (!category || streq(category, "machine")) { k = inotify_add_watch(fd, "/run/systemd/machines/", IN_MOVED_TO|IN_DELETE); - if (k < 0) { - safe_close(fd); + if (k < 0) return -errno; - } good = true; } - if (!good) { - close_nointr(fd); + if (!good) return -EINVAL; - } *m = FD_TO_MONITOR(fd); + fd = -1; + return 0; } |