From: Daan De Meyer Date: Mon, 5 May 2025 12:13:11 +0000 (+0200) Subject: rm-rf: Reduce transitive includes X-Git-Tag: v258-rc1~672^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dc7b1512645f0c7a275bac6eba8acd6bfb14e95e;p=thirdparty%2Fsystemd.git rm-rf: Reduce transitive includes --- diff --git a/src/analyze/analyze-verify.c b/src/analyze/analyze-verify.c index 3b463f2ac77..02a9dbc6462 100644 --- a/src/analyze/analyze-verify.c +++ b/src/analyze/analyze-verify.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "analyze.h" #include "analyze-verify.h" #include "analyze-verify-util.h" diff --git a/src/core/generator-setup.c b/src/core/generator-setup.c index b16211e8f46..7510fc3c610 100644 --- a/src/core/generator-setup.c +++ b/src/core/generator-setup.c @@ -2,6 +2,7 @@ #include +#include "errno-util.h" #include "generator-setup.h" #include "macro.h" #include "mkdir-label.h" diff --git a/src/import/import-tar.c b/src/import/import-tar.c index a2e7eda51b7..ac6925f30bd 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -6,6 +6,7 @@ #include "alloc-util.h" #include "btrfs-util.h" #include "copy.h" +#include "errno-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c index 8c9e4f33954..10f3ea0497a 100644 --- a/src/import/pull-tar.c +++ b/src/import/pull-tar.c @@ -9,6 +9,7 @@ #include "btrfs-util.h" #include "copy.h" #include "curl-util.h" +#include "errno-util.h" #include "fd-util.h" #include "fs-util.h" #include "hostname-util.h" diff --git a/src/nsresourced/test-userns-restrict.c b/src/nsresourced/test-userns-restrict.c index 1dcf0bd91b5..0aff1c87fbd 100644 --- a/src/nsresourced/test-userns-restrict.c +++ b/src/nsresourced/test-userns-restrict.c @@ -3,6 +3,7 @@ #include #include +#include "errno-util.h" #include "fd-util.h" #include "log.h" #include "main-func.h" diff --git a/src/nsresourced/userns-registry.c b/src/nsresourced/userns-registry.c index 5e39c3844e5..be314231aec 100644 --- a/src/nsresourced/userns-registry.c +++ b/src/nsresourced/userns-registry.c @@ -3,7 +3,9 @@ #include "sd-json.h" #include "sd-netlink.h" +#include "alloc-util.h" #include "chase.h" +#include "errno-util.h" #include "fd-util.h" #include "fileio.h" #include "format-util.h" diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index d296ac682ca..0615b27a02a 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -21,6 +21,7 @@ #include "chase.h" #include "chattr-util.h" #include "copy.h" +#include "errno-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" diff --git a/src/shared/copy.c b/src/shared/copy.c index 4288bae1cea..fb006e38ed2 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -17,6 +17,7 @@ #include "chattr-util.h" #include "copy.h" #include "dirent-util.h" +#include "errno-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" diff --git a/src/shared/rm-rf.c b/src/shared/rm-rf.c index 39866e2258c..08c76a384ea 100644 --- a/src/shared/rm-rf.c +++ b/src/shared/rm-rf.c @@ -9,6 +9,7 @@ #include "alloc-util.h" #include "btrfs-util.h" #include "dirent-util.h" +#include "errno-util.h" #include "fd-util.h" #include "fs-util.h" #include "log.h" @@ -517,3 +518,33 @@ int rm_rf_child(int fd, const char *name, RemoveFlags flags) { return rm_rf_inner_child(fd, name, -1, flags, NULL, true); } + +const char* rm_rf_safe(const char *p) { + PROTECT_ERRNO; + + if (!p) + return NULL; + + (void) rm_rf(p, REMOVE_ROOT|REMOVE_MISSING_OK|REMOVE_CHMOD); + return NULL; +} + +char* rm_rf_physical_and_free(char *p) { + PROTECT_ERRNO; + + if (!p) + return NULL; + + (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_MISSING_OK|REMOVE_CHMOD); + return mfree(p); +} + +char* rm_rf_subvolume_and_free(char *p) { + PROTECT_ERRNO; + + if (!p) + return NULL; + + (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME|REMOVE_MISSING_OK|REMOVE_CHMOD); + return mfree(p); +} diff --git a/src/shared/rm-rf.h b/src/shared/rm-rf.h index 2e107da0e1a..a965df5f8e3 100644 --- a/src/shared/rm-rf.h +++ b/src/shared/rm-rf.h @@ -4,8 +4,7 @@ #include #include -#include "alloc-util.h" -#include "errno-util.h" +#include "memory-util.h" typedef enum RemoveFlags { REMOVE_ONLY_DIRECTORIES = 1 << 0, /* Only remove empty directories, no files */ @@ -35,37 +34,13 @@ static inline int rm_rf(const char *path, RemoveFlags flags) { } /* Useful for using with _cleanup_(), destroys a directory on a temporary file system. */ -static inline const char* rm_rf_safe(const char *p) { - PROTECT_ERRNO; - - if (!p) - return NULL; - - (void) rm_rf(p, REMOVE_ROOT|REMOVE_MISSING_OK|REMOVE_CHMOD); - return NULL; -} +const char* rm_rf_safe(const char *p); DEFINE_TRIVIAL_CLEANUP_FUNC(const char*, rm_rf_safe); /* Similar as above, but allow to destroy a directory on a physical file system, and also frees the pointer. */ -static inline char* rm_rf_physical_and_free(char *p) { - PROTECT_ERRNO; - - if (!p) - return NULL; - - (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_MISSING_OK|REMOVE_CHMOD); - return mfree(p); -} +char* rm_rf_physical_and_free(char *p); DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rm_rf_physical_and_free); /* Similar as above, but also has magic btrfs subvolume powers. */ -static inline char* rm_rf_subvolume_and_free(char *p) { - PROTECT_ERRNO; - - if (!p) - return NULL; - - (void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME|REMOVE_MISSING_OK|REMOVE_CHMOD); - return mfree(p); -} +char* rm_rf_subvolume_and_free(char *p); DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rm_rf_subvolume_and_free);