Merge pull request #31917 from keszybz/path-equal-ptr-drop
Drop unnecessary path_equal_ptr() wrapper
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+20
-16
@@ -162,9 +162,10 @@ 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_IN_SET(parent,
|
||||
lp->generator,
|
||||
lp->generator_early,
|
||||
lp->generator_late);
|
||||
}
|
||||
|
||||
static int path_is_transient(const LookupPaths *lp, const char *path) {
|
||||
@@ -178,7 +179,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 +193,9 @@ 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_IN_SET(parent,
|
||||
lp->persistent_control,
|
||||
lp->runtime_control);
|
||||
}
|
||||
|
||||
static int path_is_config(const LookupPaths *lp, const char *path, bool check_parent) {
|
||||
@@ -214,8 +216,9 @@ 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_IN_SET(path,
|
||||
lp->persistent_config,
|
||||
lp->runtime_config);
|
||||
}
|
||||
|
||||
static int path_is_runtime(const LookupPaths *lp, const char *path, bool check_parent) {
|
||||
@@ -241,12 +244,13 @@ 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_IN_SET(path,
|
||||
lp->runtime_config,
|
||||
lp->generator,
|
||||
lp->generator_early,
|
||||
lp->generator_late,
|
||||
lp->transient,
|
||||
lp->runtime_control);
|
||||
}
|
||||
|
||||
static int path_is_vendor_or_generator(const LookupPaths *lp, const char *path) {
|
||||
@@ -1038,7 +1042,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 +1063,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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+14
-12
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user