]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use path_simplify_alloc() more 29491/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 7 Oct 2023 06:53:44 +0000 (15:53 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 7 Oct 2023 07:00:03 +0000 (16:00 +0900)
src/core/unit.c
src/shared/install.c
src/shared/varlink.c

index 2d096cbaefb795f0c9272b8ae8f5a626f3ab70a5..8d652354eb0c5e07f7b35c8f3da3f52eb85fa9d4 100644 (file)
@@ -4935,14 +4935,14 @@ int unit_require_mounts_for(Unit *u, const char *path, UnitDependencyMask mask)
         if (hashmap_contains(u->requires_mounts_for, path)) /* Exit quickly if the path is already covered. */
                 return 0;
 
-        _cleanup_free_ char *p = strdup(path);
-        if (!p)
-                return -ENOMEM;
-
         /* Use the canonical form of the path as the stored key. We call path_is_normalized()
          * only after simplification, since path_is_normalized() rejects paths with '.'.
          * path_is_normalized() also verifies that the path fits in PATH_MAX. */
-        path = path_simplify(p);
+        _cleanup_free_ char *p = NULL;
+        r = path_simplify_alloc(path, &p);
+        if (r < 0)
+                return r;
+        path = p;
 
         if (!path_is_normalized(path))
                 return -EPERM;
index ba3be0e99d0460d50948ed49c8b2c92f24ae01ad..8b0705eb9ef1d79c650e5ad387fed0953ba916ea 100644 (file)
@@ -581,11 +581,9 @@ static int mark_symlink_for_removal(
         if (r < 0)
                 return r;
 
-        n = strdup(p);
-        if (!n)
-                return -ENOMEM;
-
-        path_simplify(n);
+        r = path_simplify_alloc(p, &n);
+        if (r < 0)
+                return r;
 
         r = set_consume(*remove_symlinks_to, n);
         if (r == -EEXIST)
index 1d6e7fb64ebfc797e27f952dff392413982cb465..121de882bbfa326ee30cefb97b1a356e05c5b0b3 100644 (file)
@@ -501,6 +501,7 @@ int varlink_connect_url(Varlink **ret, const char *url) {
         _cleanup_free_ char *c = NULL;
         const char *p;
         bool exec;
+        int r;
 
         assert_return(ret, -EINVAL);
         assert_return(url, -EINVAL);
@@ -533,11 +534,9 @@ int varlink_connect_url(Varlink **ret, const char *url) {
                 if (!path_is_absolute(p))
                         return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Specified path not absolute, refusing.");
 
-                c = strdup(p);
-                if (!c)
-                        return log_oom_debug();
-
-                path_simplify(c);
+                r = path_simplify_alloc(p, &c);
+                if (r < 0)
+                        return r;
 
                 if (!path_is_normalized(c))
                         return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Specified path is not normalized, refusing.");