]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
automount: move generically userful call repeat_mount() into mount-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 13:25:58 +0000 (14:25 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 13:25:58 +0000 (14:25 +0100)
src/basic/mount-util.c
src/basic/mount-util.h
src/core/automount.c

index d04e7492e56ca251aa9028ac20a15596d5203c97..29997b1ce7414b5f77dc337324f51bc6f0abaca8 100644 (file)
@@ -506,3 +506,24 @@ bool fstype_is_network(const char *fstype) {
 
         return nulstr_contains(table, fstype);
 }
+
+int repeat_unmount(const char *path, int flags) {
+        bool done = false;
+
+        assert(path);
+
+        /* If there are multiple mounts on a mount point, this
+         * removes them all */
+
+        for (;;) {
+                if (umount2(path, flags) < 0) {
+
+                        if (errno == EINVAL)
+                                return done;
+
+                        return -errno;
+                }
+
+                done = true;
+        }
+}
index c87ae93e557032cc106a1bada3bca16e2720cb64..48954c2d67710c677eaa6ef20cc0fc14313c419b 100644 (file)
@@ -32,6 +32,8 @@
 int fd_is_mount_point(int fd, const char *filename, int flags);
 int path_is_mount_point(const char *path, int flags);
 
+int repeat_unmount(const char *path, int flags);
+
 int umount_recursive(const char *target, int flags);
 int bind_remount_recursive(const char *prefix, bool ro);
 
index 715e52e794755952fa87c69774cb8d812dbffd77..4c229247c57eab475401dd1384fa4d698e4129b9 100644 (file)
@@ -89,26 +89,11 @@ static void automount_init(Unit *u) {
         UNIT(a)->ignore_on_isolate = true;
 }
 
-static void repeat_unmount(const char *path) {
-        assert(path);
-
-        for (;;) {
-                /* If there are multiple mounts on a mount point, this
-                 * removes them all */
-
-                if (umount2(path, MNT_DETACH) >= 0)
-                        continue;
-
-                if (errno != EINVAL)
-                        log_error_errno(errno, "Failed to unmount: %m");
-
-                break;
-        }
-}
-
 static int automount_send_ready(Automount *a, Set *tokens, int status);
 
 static void unmount_autofs(Automount *a) {
+        int r;
+
         assert(a);
 
         if (a->pipe_fd < 0)
@@ -124,8 +109,11 @@ static void unmount_autofs(Automount *a) {
          * around */
         if (a->where &&
             (UNIT(a)->manager->exit_code != MANAGER_RELOAD &&
-             UNIT(a)->manager->exit_code != MANAGER_REEXECUTE))
-                repeat_unmount(a->where);
+             UNIT(a)->manager->exit_code != MANAGER_REEXECUTE)) {
+                r = repeat_unmount(a->where, MNT_DETACH);
+                if (r < 0)
+                        log_error_errno(r, "Failed to unmount: %m");
+        }
 }
 
 static void automount_done(Unit *u) {
@@ -615,12 +603,16 @@ static void automount_enter_waiting(Automount *a) {
         return;
 
 fail:
+        log_unit_error_errno(UNIT(a), r, "Failed to initialize automounter: %m");
+
         safe_close_pair(p);
 
-        if (mounted)
-                repeat_unmount(a->where);
+        if (mounted) {
+                r = repeat_unmount(a->where, MNT_DETACH);
+                if (r < 0)
+                        log_error_errno(r, "Failed to unmount, ignoring: %m");
+        }
 
-        log_unit_error_errno(UNIT(a), r, "Failed to initialize automounter: %m");
         automount_enter_dead(a, AUTOMOUNT_FAILURE_RESOURCES);
 }