chiark / gitweb /
login,user-sessions: always warn when we fail to remove nologin file
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 16 Feb 2018 05:58:33 +0000 (06:58 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:58:58 +0000 (07:58 +0200)
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.

src/basic/fs-util.c
src/basic/fs-util.h
src/login/logind-dbus.c
src/login/logind.c

index a72f47912ee5d972404a5ac2f7839c7673b6265c..87116d61866fb0b42ab6a60ea46f146b2e5155ab 100644 (file)
@@ -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];
index e66a8651e742e5a82ee1b13522e6f30817c83542..0e9fea9919defbfc557c46a4ac1fdf31ce413ab9 100644 (file)
@@ -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) \
index dd441ccc1b2e1f3934cd5eb0728b39b4783f6f23..87734d8e562e5279c340942c24c02e77757cc214 100644 (file)
@@ -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;
         }
 
index cd6fa96cf0b786949f9fd8204f71590fd0a060e3..10cec356605232eba56e90836dc520cd4a396c0c 100644 (file)
@@ -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);
                 }