summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-06-27 10:38:07 +0200
committerLennart Poettering <lennart@poettering.net>2020-07-07 11:20:42 +0200
commite49ee28522d4cf24b03359ba30eb2a3a0054e085 (patch)
treed126f867bb5af3dd62d014862a4438ad9e5a40b1
parente2ec9c4d3abf49e95565574214f8979d819e3f48 (diff)
downloadsystemd-e49ee28522d4cf24b03359ba30eb2a3a0054e085.tar.gz
mount-util: add destructor helper that umounts + rmdirs a path
-rw-r--r--src/shared/mount-util.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/shared/mount-util.h b/src/shared/mount-util.h
index bcbd32c840..5934d71678 100644
--- a/src/shared/mount-util.h
+++ b/src/shared/mount-util.h
@@ -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);