diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-08-22 12:34:34 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-08-23 15:10:15 +0200 |
commit | 45519d13a4f2a3c3585e672595762ca621abe65e (patch) | |
tree | 8680b032714ce1b7f823049d1e71b6ecb4b7e308 /src/shared/install.c | |
parent | 0f74ca8668ea7ebf920b4ccc4618d37bed5d0822 (diff) | |
download | systemd-45519d13a4f2a3c3585e672595762ca621abe65e.tar.gz |
tree-wide: port things dirname_malloc() → path_extract_directory()
Diffstat (limited to 'src/shared/install.c')
-rw-r--r-- | src/shared/install.c | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/src/shared/install.c b/src/shared/install.c index 5ae39f6a04..1a0a536080 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -102,12 +102,13 @@ DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(unit_file_type, UnitFileType); static int in_search_path(const LookupPaths *lp, const char *path) { _cleanup_free_ char *parent = NULL; + int r; assert(path); - parent = dirname_malloc(path); - if (!parent) - return -ENOMEM; + r = path_extract_directory(path, &parent); + if (r < 0) + return r; return path_strv_contains(lp->search_path, parent); } @@ -135,13 +136,14 @@ static const char* skip_root(const char *root_dir, const char *path) { static int path_is_generator(const LookupPaths *lp, const char *path) { _cleanup_free_ char *parent = NULL; + int r; assert(lp); assert(path); - parent = dirname_malloc(path); - if (!parent) - return -ENOMEM; + r = path_extract_directory(path, &parent); + if (r < 0) + return r; return path_equal_ptr(parent, lp->generator) || path_equal_ptr(parent, lp->generator_early) || @@ -150,26 +152,28 @@ static int path_is_generator(const LookupPaths *lp, const char *path) { static int path_is_transient(const LookupPaths *lp, const char *path) { _cleanup_free_ char *parent = NULL; + int r; assert(lp); assert(path); - parent = dirname_malloc(path); - if (!parent) - return -ENOMEM; + r = path_extract_directory(path, &parent); + if (r < 0) + return r; return path_equal_ptr(parent, lp->transient); } static int path_is_control(const LookupPaths *lp, const char *path) { _cleanup_free_ char *parent = NULL; + int r; assert(lp); assert(path); - parent = dirname_malloc(path); - if (!parent) - return -ENOMEM; + r = path_extract_directory(path, &parent); + if (r < 0) + return r; return path_equal_ptr(parent, lp->persistent_control) || path_equal_ptr(parent, lp->runtime_control); @@ -177,6 +181,7 @@ static int path_is_control(const LookupPaths *lp, const char *path) { static int path_is_config(const LookupPaths *lp, const char *path, bool check_parent) { _cleanup_free_ char *parent = NULL; + int r; assert(lp); assert(path); @@ -185,9 +190,9 @@ static int path_is_config(const LookupPaths *lp, const char *path, bool check_pa * them we couldn't discern configuration from transient or generated units */ if (check_parent) { - parent = dirname_malloc(path); - if (!parent) - return -ENOMEM; + r = path_extract_directory(path, &parent); + if (r < 0) + return r; path = parent; } @@ -199,6 +204,7 @@ static int path_is_config(const LookupPaths *lp, const char *path, bool check_pa static int path_is_runtime(const LookupPaths *lp, const char *path, bool check_parent) { _cleanup_free_ char *parent = NULL; const char *rpath; + int r; assert(lp); assert(path); @@ -211,9 +217,9 @@ static int path_is_runtime(const LookupPaths *lp, const char *path, bool check_p return true; if (check_parent) { - parent = dirname_malloc(path); - if (!parent) - return -ENOMEM; + r = path_extract_directory(path, &parent); + if (r < 0) + return r; path = parent; } @@ -1793,9 +1799,9 @@ int unit_file_verify_alias( path_alias ++; /* skip over slash */ - dir = dirname_malloc(dst); - if (!dir) - return log_oom(); + r = path_extract_directory(dst, &dir); + if (r < 0) + return log_error_errno(r, "Failed to extract parent directory from '%s': %m", dst); p = endswith(dir, ".wants"); if (!p) |