chiark / gitweb /
shutdown: avoid malloc() if we can
[elogind.git] / src / core / unit.c
index acc575b6e0adc1691d4bed568f745a8d18dc8183..5bc57e25c6bb2cc8753913bf25ac9c2ba4a52a0b 100644 (file)
@@ -311,9 +311,6 @@ void unit_add_to_gc_queue(Unit *u) {
         u->in_gc_queue = true;
 
         u->manager->n_in_gc_queue ++;
-
-        if (u->manager->gc_queue_timestamp <= 0)
-                u->manager->gc_queue_timestamp = now(CLOCK_MONOTONIC);
 }
 
 void unit_add_to_dbus_queue(Unit *u) {
@@ -436,7 +433,11 @@ void unit_free(Unit *u) {
         if (u->in_cgroup_queue)
                 LIST_REMOVE(Unit, cgroup_queue, u->manager->cgroup_queue, u);
 
-        free(u->cgroup_path);
+        if (u->cgroup_path) {
+                hashmap_remove(u->manager->cgroup_unit, u->cgroup_path);
+                free(u->cgroup_path);
+        }
+
         free(u->description);
         strv_free(u->documentation);
         free(u->fragment_path);
@@ -2131,7 +2132,8 @@ int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs) {
         if (!unit_can_serialize(u))
                 return 0;
 
-        if ((r = UNIT_VTABLE(u)->serialize(u, f, fds)) < 0)
+        r = UNIT_VTABLE(u)->serialize(u, f, fds);
+        if (r < 0)
                 return r;
 
 
@@ -2310,6 +2312,8 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
 
                         free(u->cgroup_path);
                         u->cgroup_path = s;
+
+                        hashmap_put(u->manager->cgroup_unit, s, u);
                         continue;
                 }