]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount-util: extend umount_recursive() to optionally take list of dirs to exclude...
authorLennart Poettering <lennart@poettering.net>
Tue, 16 May 2023 13:54:10 +0000 (15:54 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 17 May 2023 08:28:09 +0000 (10:28 +0200)
src/shared/mount-util.c
src/shared/mount-util.h

index b7f3616a1dbbc5dfa8f7dff33090b3052631ae00..c97a7c3188e72b7a96cbec9e800b9287200bb692 100644 (file)
@@ -43,7 +43,7 @@
 #include "tmpfile-util.h"
 #include "user-util.h"
 
-int umount_recursive(const char *prefix, int flags) {
+int umount_recursive_full(const char *prefix, int flags, char **keep) {
         _cleanup_fclose_ FILE *f = NULL;
         int n = 0, r;
 
@@ -64,6 +64,7 @@ int umount_recursive(const char *prefix, int flags) {
                         return log_debug_errno(r, "Failed to parse /proc/self/mountinfo: %m");
 
                 for (;;) {
+                        bool shall_keep = false;
                         struct libmnt_fs *fs;
                         const char *path;
 
@@ -80,6 +81,17 @@ int umount_recursive(const char *prefix, int flags) {
                         if (!path_startswith(path, prefix))
                                 continue;
 
+                        STRV_FOREACH(k, keep)
+                                /* Match against anything in the path to the dirs to keep, or below the dirs to keep */
+                                if (path_startswith(path, *k) || path_startswith(*k, path)) {
+                                        shall_keep = true;
+                                        break;
+                                }
+                        if (shall_keep) {
+                                log_debug("Not unmounting %s, referenced by keep list.", path);
+                                continue;
+                        }
+
                         if (umount2(path, flags | UMOUNT_NOFOLLOW) < 0) {
                                 log_debug_errno(errno, "Failed to umount %s, ignoring: %m", path);
                                 continue;
index 8a84d6162205ede43044d3e8000b3cf131caa297..b33e739b42ad915d27ebffe002f63dc8dca5ed83 100644 (file)
 #include "macro.h"
 
 int repeat_unmount(const char *path, int flags);
-int umount_recursive(const char *target, int flags);
+
+int umount_recursive_full(const char *target, int flags, char **keep);
+
+static inline int umount_recursive(const char *target, int flags) {
+        return umount_recursive_full(target, flags, NULL);
+}
 
 int bind_remount_recursive_with_mountinfo(const char *prefix, unsigned long new_flags, unsigned long flags_mask, char **deny_list, FILE *proc_self_mountinfo);
 static inline int bind_remount_recursive(const char *prefix, unsigned long new_flags, unsigned long flags_mask, char **deny_list) {