]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount-util: add destructor helper that umounts + rmdirs a path
authorLennart Poettering <lennart@poettering.net>
Sat, 27 Jun 2020 08:38:07 +0000 (10:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 7 Jul 2020 09:20:42 +0000 (11:20 +0200)
src/shared/mount-util.h

index bcbd32c8404b605e7016923c4f3381a895258656..5934d716786e5ec8e745236d10723f35db3cfe23 100644 (file)
@@ -3,7 +3,9 @@
 
 #include <mntent.h>
 #include <stdio.h>
+#include <unistd.h>
 
+#include "errno-util.h"
 #include "macro.h"
 
 /* 4MB for contents of regular files, 64k inodes for directories, symbolic links and device specials,
@@ -53,3 +55,12 @@ int mount_option_mangle(
                 char **ret_remaining_options);
 
 int mode_to_inaccessible_node(const char *runtime_dir, mode_t mode, char **dest);
+
+/* Useful for usage with _cleanup_(), unmounts, removes a directory and frees the pointer */
+static inline void umount_and_rmdir_and_free(char *p) {
+        PROTECT_ERRNO;
+        (void) umount_recursive(p, 0);
+        (void) rmdir(p);
+        free(p);
+}
+DEFINE_TRIVIAL_CLEANUP_FUNC(char*, umount_and_rmdir_and_free);