chiark / gitweb /
logind/machined: properly notice when units are gc'ed
authorLennart Poettering <lennart@poettering.net>
Wed, 3 Jul 2013 13:12:58 +0000 (15:12 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 3 Jul 2013 13:14:47 +0000 (15:14 +0200)
src/login/logind-dbus.c
src/login/logind.c
src/machine/machined-dbus.c
src/machine/machined.c

index a52f020..eeff843 100644 (file)
@@ -2411,6 +2411,44 @@ DBusHandlerResult bus_message_filter(
                         if (u)
                                 user_add_to_gc_queue(u);
                 }
+        } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "UnitRemoved")) {
+
+                const char *path, *unit;
+                Session *session;
+                User *user;
+
+                if (!dbus_message_get_args(message, &error,
+                                           DBUS_TYPE_STRING, &unit,
+                                           DBUS_TYPE_OBJECT_PATH, &path,
+                                           DBUS_TYPE_INVALID)) {
+                        log_error("Failed to parse UnitRemoved message: %s", bus_error_message(&error));
+                        goto finish;
+                }
+
+                session = hashmap_get(m->session_units, unit);
+                if (session) {
+                        hashmap_remove(m->session_units, session->scope);
+                        free(session->scope);
+                        session->scope = NULL;
+
+                        session_add_to_gc_queue(session);
+                }
+
+                user = hashmap_get(m->user_units, unit);
+                if (user) {
+
+                        if (streq_ptr(unit, user->service)) {
+                                hashmap_remove(m->user_units, user->service);
+                                free(user->service);
+                                user->service = NULL;
+                        } else if (streq_ptr(unit, user->slice)) {
+                                hashmap_remove(m->user_units, user->slice);
+                                free(user->slice);
+                                user->slice = NULL;
+                        }
+
+                        user_add_to_gc_queue(user);
+                }
         }
 
 finish:
index e37a107..fcb3ccf 100644 (file)
@@ -1023,6 +1023,18 @@ static int manager_connect_bus(Manager *m) {
         dbus_bus_add_match(m->bus,
                            "type='signal',"
                            "sender='org.freedesktop.systemd1',"
+                           "interface='org.freedesktop.systemd1.Manager',"
+                           "member='UnitRemoved',"
+                           "path='/org/freedesktop/systemd1'",
+                           &error);
+        if (dbus_error_is_set(&error)) {
+                log_error("Failed to add match for UnitRemoved: %s", bus_error_message(&error));
+                dbus_error_free(&error);
+        }
+
+        dbus_bus_add_match(m->bus,
+                           "type='signal',"
+                           "sender='org.freedesktop.systemd1',"
                            "interface='org.freedesktop.DBus.Properties',"
                            "member='PropertiesChanged'",
                            &error);
index a81f37c..1b1eb3a 100644 (file)
@@ -531,7 +531,6 @@ DBusHandlerResult bus_message_filter(
                         goto finish;
                 }
 
-
                 mm = hashmap_get(m->machine_units, unit);
                 if (mm) {
                         if (streq_ptr(path, mm->scope_job)) {
@@ -570,6 +569,27 @@ DBusHandlerResult bus_message_filter(
                         if (mm)
                                 machine_add_to_gc_queue(mm);
                 }
+
+        } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "UnitRemoved")) {
+                const char *path, *unit;
+                Machine *mm;
+
+                if (!dbus_message_get_args(message, &error,
+                                           DBUS_TYPE_STRING, &unit,
+                                           DBUS_TYPE_OBJECT_PATH, &path,
+                                           DBUS_TYPE_INVALID)) {
+                        log_error("Failed to parse UnitRemoved message: %s", bus_error_message(&error));
+                        goto finish;
+                }
+
+                mm = hashmap_get(m->machine_units, unit);
+                if (mm) {
+                        hashmap_remove(m->machine_units, mm->scope);
+                        free(mm->scope);
+                        mm->scope = NULL;
+
+                        machine_add_to_gc_queue(mm);
+                }
         }
 
 finish:
index 86f8de9..f2803a1 100644 (file)
@@ -213,6 +213,18 @@ static int manager_connect_bus(Manager *m) {
         dbus_bus_add_match(m->bus,
                            "type='signal',"
                            "sender='org.freedesktop.systemd1',"
+                           "interface='org.freedesktop.systemd1.Manager',"
+                           "member='UnitRemoved',"
+                           "path='/org/freedesktop/systemd1'",
+                           &error);
+        if (dbus_error_is_set(&error)) {
+                log_error("Failed to add match for UnitRemoved: %s", bus_error_message(&error));
+                dbus_error_free(&error);
+        }
+
+        dbus_bus_add_match(m->bus,
+                           "type='signal',"
+                           "sender='org.freedesktop.systemd1',"
                            "interface='org.freedesktop.DBus.Properties',"
                            "member='PropertiesChanged'",
                            &error);