chiark / gitweb /
mount: add automatic start ordering dependencies for mounts
[elogind.git] / src / automount.c
index 39eb3dd01aafd677e64624c8f1b8745b0e422acc..00f3736b2fc148c9eb5bf0bb223eca8073177dd3 100644 (file)
@@ -36,6 +36,7 @@
 #include "unit-name.h"
 #include "dbus-automount.h"
 #include "bus-errors.h"
+#include "special.h"
 
 static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
         [AUTOMOUNT_DEAD] = UNIT_INACTIVE,
@@ -145,6 +146,23 @@ static int automount_add_mount_links(Automount *a) {
         return 0;
 }
 
+static int automount_add_default_dependencies(Automount *a) {
+        int r;
+
+        assert(a);
+
+        if (a->meta.manager->running_as == MANAGER_SYSTEM) {
+
+                if ((r = unit_add_dependency_by_name(UNIT(a), UNIT_AFTER, SPECIAL_SYSINIT_TARGET, NULL, true)) < 0)
+                        return r;
+
+                if ((r = unit_add_two_dependencies_by_name(UNIT(a), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true)) < 0)
+                        return r;
+        }
+
+        return 0;
+}
+
 static int automount_verify(Automount *a) {
         bool b;
         char *e;
@@ -153,6 +171,11 @@ static int automount_verify(Automount *a) {
         if (a->meta.load_state != UNIT_LOADED)
                 return 0;
 
+        if (path_equal(a->where, "/")) {
+                log_error("Cannot have an automount unit for the root directory. Refusing.");
+                return -EINVAL;
+        }
+
         if (!(e = unit_name_from_path(a->where, ".automount")))
                 return -ENOMEM;
 
@@ -194,6 +217,10 @@ static int automount_load(Unit *u) {
 
                 if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount), true)) < 0)
                         return r;
+
+                if (a->meta.default_dependencies)
+                        if ((r = automount_add_default_dependencies(a)) < 0)
+                                return r;
         }
 
         return automount_verify(a);