chiark / gitweb /
machined: implement exit-on-idle
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Dec 2013 20:15:08 +0000 (21:15 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 19 Dec 2013 21:18:39 +0000 (22:18 +0100)
src/machine/machined.c

index 6550075..6eeb053 100644 (file)
@@ -275,26 +275,23 @@ int manager_startup(Manager *m) {
         return 0;
 }
 
-int manager_run(Manager *m) {
-        int r;
-
-        assert(m);
+static bool check_idle(void *userdata) {
+        Manager *m = userdata;
 
-        for (;;) {
-                r = sd_event_get_state(m->event);
-                if (r < 0)
-                        return r;
-                if (r == SD_EVENT_FINISHED)
-                        return 0;
+        manager_gc(m, true);
 
-                manager_gc(m, true);
+        return hashmap_isempty(m->machines);
+}
 
-                r = sd_event_run(m->event, (uint64_t) -1);
-                if (r < 0)
-                        return r;
-        }
+int manager_run(Manager *m) {
+        assert(m);
 
-        return 0;
+        return bus_event_loop_with_idle(
+                        m->event,
+                        m->bus,
+                        "org.freedesktop.machine1",
+                        DEFAULT_EXIT_USEC,
+                        check_idle, m);
 }
 
 int main(int argc, char *argv[]) {