From: Lennart Poettering Date: Wed, 4 Jun 2025 09:40:45 +0000 (+0200) Subject: sd-login: place inner part of sd_login_monitor_new() by a table X-Git-Tag: v258-rc1~392^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2af482f0adaee66d83b3413e10775fe5462a049;p=thirdparty%2Fsystemd.git sd-login: place inner part of sd_login_monitor_new() by a table --- diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 93ceedeb89c..4d32687ff9e 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; - - good = true; - } - - 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; + 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, "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;