mirror of
https://github.com/systemd/systemd
synced 2024-09-06 08:46:19 +00:00
basic: Make ret_names param to unit_file_find_fragment() optional
This commit is contained in:
parent
97c373c7de
commit
11e9347bc6
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue