From: Zbigniew Jędrzejewski-Szmek Date: Fri, 16 Feb 2018 05:58:33 +0000 (+0100) Subject: login,user-sessions: always warn when we fail to remove nologin file X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=be2283cf9e565994ae6db0db57a555c6db704fe0;p=elogind.git login,user-sessions: always warn when we fail to remove nologin file This usually is very annoying to users who then cannot log in, so make sure we always warn if that happens (selinux, or whatever other reason). This reverts a790812cb349c5cef95d1b4a20fc80ca08d3a145. --- diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index a72f47912..87116d618 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -567,6 +567,17 @@ int tmp_dir(const char **ret) { return tmp_dir_internal("/tmp", ret); } +int unlink_or_warn(const char *filename) { + if (unlink(filename) < 0 && errno != ENOENT) + /* If the file doesn't exist and the fs simply was read-only (in which + * case unlink() returns EROFS even if the file doesn't exist), don't + * complain */ + if (errno != EROFS || access(filename, F_OK) >= 0) + return log_error_errno(errno, "Failed to remove \"%s\": %m", filename); + + return 0; +} + #if 0 /// UNNEEDED by elogind int inotify_add_watch_fd(int fd, int what, uint32_t mask) { char path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h index e66a8651e..0e9fea991 100644 --- a/src/basic/fs-util.h +++ b/src/basic/fs-util.h @@ -77,6 +77,8 @@ int tmp_dir(const char **ret); #if 0 /// UNNEEDED by elogind int var_tmp_dir(const char **ret); +int unlink_or_warn(const char *filename); + #define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1) #define FOREACH_INOTIFY_EVENT(e, buffer, sz) \ diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index dd441ccc1..87734d8e5 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -2049,7 +2049,7 @@ static void reset_scheduled_shutdown(Manager *m) { m->shutdown_dry_run = false; if (m->unlink_nologin) { - (void) unlink("/run/nologin"); + (void) unlink_or_warn("/run/nologin"); m->unlink_nologin = false; } diff --git a/src/login/logind.c b/src/login/logind.c index cd6fa96cf..10cec3566 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -39,6 +39,7 @@ #include "dirent-util.h" #include "fd-util.h" #include "format-util.h" +//#include "fs-util.h" #include "logind.h" //#include "process-util.h" #include "selinux-util.h" @@ -203,7 +204,7 @@ static void manager_free(Manager *m) { udev_unref(m->udev); if (m->unlink_nologin) - (void) unlink("/run/nologin"); + (void) unlink_or_warn("/run/nologin"); bus_verify_polkit_async_registry_free(m->polkit_registry); @@ -999,7 +1000,7 @@ static void manager_gc(Manager *m, bool drop_not_started) { LIST_REMOVE(gc_queue, m->seat_gc_queue, seat); seat->in_gc_queue = false; - if (seat_may_gc(seat, drop_not_started)) { + if (!seat_check_gc(seat, drop_not_started)) { seat_stop(seat, false); seat_free(seat); } @@ -1010,14 +1011,14 @@ static void manager_gc(Manager *m, bool drop_not_started) { session->in_gc_queue = false; /* First, if we are not closing yet, initiate stopping */ - if (session_may_gc(session, drop_not_started) && + if (!session_check_gc(session, drop_not_started) && session_get_state(session) != SESSION_CLOSING) session_stop(session, false); /* Normally, this should make the session referenced * again, if it doesn't then let's get rid of it * immediately */ - if (session_may_gc(session, drop_not_started)) { + if (!session_check_gc(session, drop_not_started)) { session_finalize(session); session_free(session); } @@ -1028,11 +1029,11 @@ static void manager_gc(Manager *m, bool drop_not_started) { user->in_gc_queue = false; /* First step: queue stop jobs */ - if (user_may_gc(user, drop_not_started)) + if (!user_check_gc(user, drop_not_started)) user_stop(user, false); /* Second step: finalize user */ - if (user_may_gc(user, drop_not_started)) { + if (!user_check_gc(user, drop_not_started)) { user_finalize(user); user_free(user); }