diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 93ceedeb89..4d32687ff9 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -1135,8 +1135,6 @@ static sd_login_monitor* FD_TO_MONITOR(int fd) { _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **ret) { _cleanup_close_ int fd = -EBADF; - bool good = false; - int k; assert_return(ret, -EINVAL); @@ -1144,33 +1142,22 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **ret) if (fd < 0) return -errno; - if (!category || streq(category, "seat")) { - k = inotify_add_watch(fd, "/run/systemd/seats/", IN_MOVED_TO|IN_DELETE); - if (k < 0) - return -errno; + static const struct { + const char *name; + const char *path; + } categories[] = { + { "seat", "/run/systemd/seats/" }, + { "session", "/run/systemd/sessions/" }, + { "uid", "/run/systemd/users/" }, + { "machine", "/run/systemd/machines/" }, + }; - good = true; - } + bool good = false; + FOREACH_ELEMENT(c, categories) { + if (category && !streq(category, c->name)) + continue; - if (!category || streq(category, "session")) { - k = inotify_add_watch(fd, "/run/systemd/sessions/", IN_MOVED_TO|IN_DELETE); - 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) - 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) + if (inotify_add_watch(fd, c->path, IN_MOVED_TO|IN_DELETE) < 0) return -errno; good = true;