]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: Make ret_names param to unit_file_find_fragment() optional
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 27 Oct 2021 15:02:56 +0000 (16:02 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 27 Oct 2021 15:03:43 +0000 (16:03 +0100)
src/basic/unit-file.c
src/test/test-unit-file.c

index bbe439da05ac047c16da0b402ab0afba15e302d4..89bfeceae4f52bed47891cbff23e00a35704ca9b 100644 (file)
@@ -598,9 +598,11 @@ int unit_file_find_fragment(
         if (name_type < 0)
                 return name_type;
 
-        r = add_names(unit_ids_map, unit_name_map, unit_name, NULL, name_type, instance, &names, unit_name);
-        if (r < 0)
-                return r;
+        if (ret_names) {
+                r = add_names(unit_ids_map, unit_name_map, unit_name, NULL, name_type, instance, &names, unit_name);
+                if (r < 0)
+                        return r;
+        }
 
         /* First try to load fragment under the original name */
         r = unit_ids_map_get(unit_ids_map, unit_name, &fragment);
@@ -619,7 +621,7 @@ int unit_file_find_fragment(
                         return log_debug_errno(r, "Cannot load template %s: %m", template);
         }
 
-        if (fragment) {
+        if (fragment && ret_names) {
                 const char *fragment_basename = basename(fragment);
 
                 if (!streq(fragment_basename, unit_name)) {
@@ -631,7 +633,8 @@ int unit_file_find_fragment(
         }
 
         *ret_fragment_path = fragment;
-        *ret_names = TAKE_PTR(names);
+        if (ret_names)
+                *ret_names = TAKE_PTR(names);
 
         return 0;
 }
index 4fcd2e0efd0fbd7b0f0519d6717cddffc493af21..7900c1f460e76e84e7d6100ad3ebb14e529ab3bd 100644 (file)
@@ -71,6 +71,19 @@ static void test_unit_file_build_name_map(char **ids) {
                  SET_FOREACH(name, names)
                          log_info("    %s", name);
         }
+
+        /* Make sure everything still works if we don't collect names. */
+        STRV_FOREACH(id, ids) {
+                 const char *fragment;
+                 log_info("*** %s ***", *id);
+                 r = unit_file_find_fragment(unit_ids,
+                                             unit_names,
+                                             *id,
+                                             &fragment,
+                                             NULL);
+                 assert_se(r == 0);
+                 log_info("fragment: %s", fragment);
+        }
 }
 
 static void test_runlevel_to_target(void) {