]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/unit-file: expose function to check .wants/.requires symlink validity
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 20 Dec 2019 18:12:34 +0000 (19:12 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 10 Jan 2020 11:20:18 +0000 (12:20 +0100)
No functional change.

src/core/load-dropin.c
src/shared/unit-file.c
src/shared/unit-file.h

index a50b200f5bdcb877b2bbd042eebde39458dc3377..492e816e91aeb5d7908e14cf0ffe71fe9aa26340 100644 (file)
 #include "unit-name.h"
 #include "unit.h"
 
-static int unit_name_compatible(const char *a, const char *b) {
-        _cleanup_free_ char *template = NULL;
-        int r;
-
-        /* The straightforward case: the symlink name matches the target */
-        if (streq(a, b))
-                return 1;
-
-        r = unit_name_template(a, &template);
-        if (r == -EINVAL)
-                return 0; /* Not a template */
-        if (r < 0)
-                return r; /* OOM, or some other failure. Just skip the warning. */
-
-        /* An instance name points to a target that is just the template name */
-        return streq(template, b);
-}
-
 static int process_deps(Unit *u, UnitDependency dependency, const char *dir_suffix) {
         _cleanup_strv_free_ char **paths = NULL;
         char **p;
@@ -83,9 +65,10 @@ static int process_deps(Unit *u, UnitDependency dependency, const char *dir_suff
 
                 /* We don't treat this as an error, especially because we didn't check this for a
                  * long time. Nevertheless, we warn, because such mismatch can be mighty confusing. */
-                r = unit_name_compatible(entry, basename(target));
+                r = unit_symlink_name_compatible(entry, basename(target));
                 if (r < 0) {
-                        log_unit_warning_errno(u, r, "Can't check if names %s and %s are compatible, ignoring: %m", entry, basename(target));
+                        log_unit_warning_errno(u, r, "Can't check if names %s and %s are compatible, ignoring: %m",
+                                               entry, basename(target));
                         continue;
                 }
                 if (r == 0)
index 28cd3c860091e4ddc5bf3b64ac49d85d56a7cdec..dc0ec784640691528bf32d2acc3a4ca69576ff99 100644 (file)
@@ -31,6 +31,24 @@ bool unit_type_may_template(UnitType type) {
                       UNIT_PATH);
 }
 
+int unit_symlink_name_compatible(const char *symlink, const char *target) {
+        _cleanup_free_ char *template = NULL;
+        int r;
+
+        /* The straightforward case: the symlink name matches the target */
+        if (streq(symlink, target))
+                return 1;
+
+        r = unit_name_template(symlink, &template);
+        if (r == -EINVAL)
+                return 0; /* Not a template */
+        if (r < 0)
+                return r;
+
+        /* An instance name points to a target that is just the template name */
+        return streq(template, target);
+}
+
 int unit_validate_alias_symlink_and_warn(const char *filename, const char *target) {
         const char *src, *dst;
         _cleanup_free_ char *src_instance = NULL, *dst_instance = NULL;
index 98ba677f3f641bae584ad697db96f4345de5be00..83f78618d3073a2d11d5daadfea57a24e527efce 100644 (file)
@@ -39,6 +39,7 @@ enum UnitFileScope {
 bool unit_type_may_alias(UnitType type) _const_;
 bool unit_type_may_template(UnitType type) _const_;
 
+int unit_symlink_name_compatible(const char *symlink, const char *target);
 int unit_validate_alias_symlink_and_warn(const char *filename, const char *target);
 
 int unit_file_build_name_map(