From: Zbigniew Jędrzejewski-Szmek Date: Sat, 23 Mar 2024 12:18:24 +0000 (+0100) Subject: Drop unnecessary path_equal_ptr() wrapper X-Git-Tag: v256-rc1~430^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1934242b72b8c41d80410948e075e5fa9c6f8a0b;p=thirdparty%2Fsystemd.git Drop unnecessary path_equal_ptr() wrapper path_equal already works with NULL pointers. --- diff --git a/src/basic/path-util.h b/src/basic/path-util.h index 47699e64142..6d88c54d7f0 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -105,10 +105,6 @@ static inline int path_simplify_alloc(const char *path, char **ret) { return 0; } -static inline bool path_equal_ptr(const char *a, const char *b) { - return !!a == !!b && (!a || path_equal(a, b)); -} - /* Note: the search terminates on the first NULL item. */ #define PATH_IN_SET(p, ...) path_strv_contains(STRV_MAKE(__VA_ARGS__), p) diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index c208d7c59dc..a833aa260cc 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -229,7 +229,7 @@ int null_or_empty_path_with_root(const char *fn, const char *root) { * When looking under root_dir, we can't expect /dev/ to be mounted, * so let's see if the path is a (possibly dangling) symlink to /dev/null. */ - if (path_equal_ptr(path_startswith(fn, root ?: "/"), "dev/null")) + if (path_equal(path_startswith(fn, root ?: "/"), "dev/null")) return true; r = chase_and_stat(fn, root, CHASE_PREFIX_ROOT, NULL, &st); diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index a1401f3e490..47339bddafc 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -1915,7 +1915,7 @@ static int build_environment( * to inherit the $TERM set for PID 1. This is useful for containers so that the $TERM the * container manager passes to PID 1 ends up all the way in the console login shown. */ - if (path_equal_ptr(tty_path, "/dev/console") && getppid() == 1) + if (path_equal(tty_path, "/dev/console") && getppid() == 1) term = getenv("TERM"); else if (tty_path && in_charset(skip_dev_prefix(tty_path), ALPHANUMERICAL)) { _cleanup_free_ char *key = NULL; diff --git a/src/core/import-creds.c b/src/core/import-creds.c index 18e4bce67f8..90d87e078d3 100644 --- a/src/core/import-creds.c +++ b/src/core/import-creds.c @@ -753,7 +753,7 @@ static int merge_credentials_trusted(const char *creds_dir) { return 0; /* Do not try to merge initrd credentials into foreign credentials directories */ - if (!path_equal_ptr(creds_dir, SYSTEM_CREDENTIALS_DIRECTORY)) { + if (!path_equal(creds_dir, SYSTEM_CREDENTIALS_DIRECTORY)) { log_debug("Not importing initrd credentials, as foreign $CREDENTIALS_DIRECTORY has been set."); return 0; } diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index d751b3316c4..be8907f2d19 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -249,7 +249,7 @@ int unit_is_likely_recursive_template_dependency(Unit *u, const char *name, cons /* Fragment paths should also be equal as a custom fragment for a specific template instance * wouldn't necessarily lead to infinite recursion. */ - if (!path_equal_ptr(u->fragment_path, fragment_path)) + if (!path_equal(u->fragment_path, fragment_path)) return false; if (!contains_instance_specifier_superset(format)) diff --git a/src/core/main.c b/src/core/main.c index 51f64bdc1de..1c57cce7483 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1476,7 +1476,7 @@ static int fixup_environment(void) { return -errno; /* The kernels sets HOME=/ for init. Let's undo this. */ - if (path_equal_ptr(getenv("HOME"), "/")) + if (path_equal(getenv("HOME"), "/")) assert_se(unsetenv("HOME") == 0); return 0; diff --git a/src/shared/install.c b/src/shared/install.c index 8fe0165225c..cd27baf3919 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -162,9 +162,9 @@ static int path_is_generator(const LookupPaths *lp, const char *path) { if (r < 0) return r; - return path_equal_ptr(parent, lp->generator) || - path_equal_ptr(parent, lp->generator_early) || - path_equal_ptr(parent, lp->generator_late); + return path_equal(parent, lp->generator) || + path_equal(parent, lp->generator_early) || + path_equal(parent, lp->generator_late); } static int path_is_transient(const LookupPaths *lp, const char *path) { @@ -178,7 +178,7 @@ static int path_is_transient(const LookupPaths *lp, const char *path) { if (r < 0) return r; - return path_equal_ptr(parent, lp->transient); + return path_equal(parent, lp->transient); } static int path_is_control(const LookupPaths *lp, const char *path) { @@ -192,8 +192,8 @@ static int path_is_control(const LookupPaths *lp, const char *path) { if (r < 0) return r; - return path_equal_ptr(parent, lp->persistent_control) || - path_equal_ptr(parent, lp->runtime_control); + return path_equal(parent, lp->persistent_control) || + path_equal(parent, lp->runtime_control); } static int path_is_config(const LookupPaths *lp, const char *path, bool check_parent) { @@ -214,8 +214,8 @@ static int path_is_config(const LookupPaths *lp, const char *path, bool check_pa path = parent; } - return path_equal_ptr(path, lp->persistent_config) || - path_equal_ptr(path, lp->runtime_config); + return path_equal(path, lp->persistent_config) || + path_equal(path, lp->runtime_config); } static int path_is_runtime(const LookupPaths *lp, const char *path, bool check_parent) { @@ -241,12 +241,12 @@ static int path_is_runtime(const LookupPaths *lp, const char *path, bool check_p path = parent; } - return path_equal_ptr(path, lp->runtime_config) || - path_equal_ptr(path, lp->generator) || - path_equal_ptr(path, lp->generator_early) || - path_equal_ptr(path, lp->generator_late) || - path_equal_ptr(path, lp->transient) || - path_equal_ptr(path, lp->runtime_control); + return path_equal(path, lp->runtime_config) || + path_equal(path, lp->generator) || + path_equal(path, lp->generator_early) || + path_equal(path, lp->generator_late) || + path_equal(path, lp->transient) || + path_equal(path, lp->runtime_control); } static int path_is_vendor_or_generator(const LookupPaths *lp, const char *path) { @@ -1038,7 +1038,7 @@ static int find_symlinks_in_scope( if (r > 0) { /* We found symlinks in this dir? Yay! Let's see where precisely it is enabled. */ - if (path_equal_ptr(*p, lp->persistent_config)) { + if (path_equal(*p, lp->persistent_config)) { /* This is the best outcome, let's return it immediately. */ *state = UNIT_FILE_ENABLED; return 1; @@ -1059,7 +1059,7 @@ static int find_symlinks_in_scope( enabled_at_all = true; } else if (same_name_link) { - if (path_equal_ptr(*p, lp->persistent_config)) + if (path_equal(*p, lp->persistent_config)) same_name_link_config = true; else { r = path_is_runtime(lp, *p, false); diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index b071623780a..52f4a47aa1f 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -1642,7 +1642,7 @@ static int item_equivalent(Item *a, Item *b) { const char *a_shell = pick_shell(a), *b_shell = pick_shell(b); - if (!path_equal_ptr(a_shell, b_shell) && + if (!path_equal(a_shell, b_shell) && !(is_nologin_shell(a_shell) && is_nologin_shell(b_shell))) { _cleanup_free_ char *pa = NULL, *pb = NULL; diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index ceff01967aa..5f36ae49f05 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -23,7 +23,7 @@ TEST(print_paths) { } TEST(path) { - assert_se(path_is_absolute("/")); + assert_se( path_is_absolute("/")); assert_se(!path_is_absolute("./")); assert_se(streq(basename("./aa/bb/../file.da."), "file.da.")); @@ -31,17 +31,19 @@ TEST(path) { assert_se(streq(basename("/aa///file..."), "file...")); assert_se(streq(basename("file.../"), "")); - assert_se(PATH_IN_SET("/bin", "/", "/bin", "/foo")); - assert_se(PATH_IN_SET("/bin", "/bin")); - assert_se(PATH_IN_SET("/bin", "/foo/bar", "/bin")); - assert_se(PATH_IN_SET("/", "/", "/", "/foo/bar")); + assert_se( PATH_IN_SET("/bin", "/", "/bin", "/foo")); + assert_se( PATH_IN_SET("/bin", "/bin")); + assert_se( PATH_IN_SET("/bin", "/foo/bar", "/bin")); + assert_se( PATH_IN_SET("/", "/", "/", "/foo/bar")); assert_se(!PATH_IN_SET("/", "/abc", "/def")); - assert_se(path_equal_ptr(NULL, NULL)); - assert_se(path_equal_ptr("/a", "/a")); - assert_se(!path_equal_ptr("/a", "/b")); - assert_se(!path_equal_ptr("/a", NULL)); - assert_se(!path_equal_ptr(NULL, "/a")); + assert_se( path_equal(NULL, NULL)); + assert_se( path_equal("/a", "/a")); + assert_se(!path_equal("/a", "/b")); + assert_se(!path_equal("/a", NULL)); + assert_se(!path_equal(NULL, "/a")); + assert_se(!path_equal("a", NULL)); + assert_se(!path_equal(NULL, "a")); } TEST(is_path) { @@ -759,11 +761,11 @@ static void test_prefix_root_one(const char *r, const char *p, const char *expec const char *t; assert_se(s = path_join(r, p)); - assert_se(path_equal_ptr(s, expected)); + assert_se(path_equal(s, expected)); t = prefix_roota(r, p); assert_se(t); - assert_se(path_equal_ptr(t, expected)); + assert_se(path_equal(t, expected)); } TEST(prefix_root) {