From e49ee28522d4cf24b03359ba30eb2a3a0054e085 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 27 Jun 2020 10:38:07 +0200 Subject: [PATCH] mount-util: add destructor helper that umounts + rmdirs a path --- src/shared/mount-util.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/shared/mount-util.h b/src/shared/mount-util.h index bcbd32c8404..5934d716786 100644 --- a/src/shared/mount-util.h +++ b/src/shared/mount-util.h @@ -3,7 +3,9 @@ #include #include +#include +#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); -- 2.47.3