]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: at start-up automatically clean up orphaned inhibitors
authorLennart Poettering <lennart@poettering.net>
Tue, 23 Jul 2019 08:33:39 +0000 (10:33 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 23 Jul 2019 14:08:07 +0000 (16:08 +0200)
src/login/logind-inhibit.c
src/login/logind-inhibit.h
src/login/logind.c

index ca2088150e8946dca1112548488e562f286cd134..8a361551159f69373e1a99f7cbb6337c13318c2d 100644 (file)
@@ -13,6 +13,7 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "format-util.h"
+#include "io-util.h"
 #include "logind-dbus.h"
 #include "logind-inhibit.h"
 #include "mkdir.h"
@@ -350,6 +351,24 @@ static void inhibitor_remove_fifo(Inhibitor *i) {
         }
 }
 
+bool inhibitor_is_orphan(Inhibitor *i) {
+        assert(i);
+
+        if (!i->started)
+                return true;
+
+        if (!i->fifo_path)
+                return true;
+
+        if (i->fifo_fd < 0)
+                return true;
+
+        if (pipe_eof(i->fifo_fd) != 0)
+                return true;
+
+        return false;
+}
+
 InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm) {
         Inhibitor *i;
         Iterator j;
index e04bc81a8681e7a7232241f3516985b1f428aac4..c00578a86e7665c48606a7ec3abaad36d93d95a2 100644 (file)
@@ -60,6 +60,8 @@ void inhibitor_stop(Inhibitor *i);
 
 int inhibitor_create_fifo(Inhibitor *i);
 
+bool inhibitor_is_orphan(Inhibitor *i);
+
 InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm);
 bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending);
 
index 175db697e529e372b04cb0411113fec24e71a146..3a16e6c8712a89740a1ae1e173e74f39d8180975 100644 (file)
@@ -1145,8 +1145,15 @@ static int manager_startup(Manager *m) {
         HASHMAP_FOREACH(session, m->sessions, i)
                 (void) session_start(session, NULL, NULL);
 
-        HASHMAP_FOREACH(inhibitor, m->inhibitors, i)
-                inhibitor_start(inhibitor);
+        HASHMAP_FOREACH(inhibitor, m->inhibitors, i) {
+                (void) inhibitor_start(inhibitor);
+
+                /* Let's see if the inhibitor is dead now, then remove it */
+                if (inhibitor_is_orphan(inhibitor)) {
+                        inhibitor_stop(inhibitor);
+                        inhibitor_free(inhibitor);
+                }
+        }
 
         HASHMAP_FOREACH(button, m->buttons, i)
                 button_check_switches(button);