chiark / gitweb /
cgroup: treat non-existing cgroups like empty ones, to deal with races
[elogind.git] / src / swap.c
index 663c568961b38519bf87c6b8c119da5c6296a37c..de468a0434ee0e0e4dfcaace2ff6cfa8111168ee 100644 (file)
@@ -38,7 +38,7 @@
 static const UnitActiveState state_translation_table[_SWAP_STATE_MAX] = {
         [SWAP_DEAD] = UNIT_INACTIVE,
         [SWAP_ACTIVE] = UNIT_ACTIVE,
-        [SWAP_MAINTENANCE] = UNIT_INACTIVE
+        [SWAP_MAINTENANCE] = UNIT_MAINTENANCE
 };
 
 static void swap_init(Unit *u) {
@@ -77,10 +77,7 @@ int swap_add_one_mount_link(Swap *s, Mount *m) {
         if (!path_startswith(s->what, m->where))
                 return 0;
 
-        if ((r = unit_add_dependency(UNIT(m), UNIT_BEFORE, UNIT(s), true)) < 0)
-                return r;
-
-        if ((r = unit_add_dependency(UNIT(s), UNIT_REQUIRES, UNIT(m), true)) < 0)
+        if ((r = unit_add_two_dependencies(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, UNIT(m), true)) < 0)
                 return r;
 
         return 0;
@@ -113,7 +110,7 @@ static int swap_add_target_links(Swap *s) {
         else
                 return 0;
 
-        if ((r = manager_load_unit(s->meta.manager, SPECIAL_SWAP_TARGET, NULL, &tu)) < 0)
+        if ((r = manager_load_unit(s->meta.manager, SPECIAL_SWAP_TARGET, NULL, NULL, &tu)) < 0)
                 return r;
 
         if (!p->noauto && p->handle && s->meta.manager->running_as == MANAGER_SYSTEM)
@@ -123,6 +120,24 @@ static int swap_add_target_links(Swap *s) {
         return unit_add_dependency(UNIT(s), UNIT_BEFORE, tu, true);
 }
 
+static int swap_add_default_dependencies(Swap *s) {
+        int r;
+
+        assert(s);
+
+        if (s->meta.manager->running_as == MANAGER_SYSTEM) {
+
+                if ((r = unit_add_dependency_by_name(UNIT(s), UNIT_AFTER, SPECIAL_SYSINIT_TARGET, NULL, true)) < 0)
+                        return r;
+
+                /* Note that by default we don't disable swap devices
+                 * on shutdown. i.e. there is no umount.target
+                 * conflicts here. */
+        }
+
+        return 0;
+}
+
 static int swap_verify(Swap *s) {
         bool b;
         char *e;
@@ -188,6 +203,10 @@ static int swap_load(Unit *u) {
 
                 if ((r = swap_add_target_links(s)) < 0)
                         return r;
+
+                if (s->meta.default_dependencies)
+                        if ((r = swap_add_default_dependencies(s)) < 0)
+                                return r;
         }
 
         return swap_verify(s);
@@ -550,6 +569,7 @@ const UnitVTable swap_vtable = {
 
         .no_instances = true,
         .no_isolate = true,
+        .show_status = true,
 
         .init = swap_init,
         .load = swap_load,