From f60671860e1dd0b94d8b384f4102640c25018123 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 Jan 2021 15:00:29 +0100 Subject: [PATCH 1/5] unit-file: fix indentation --- src/shared/unit-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/unit-file.c b/src/shared/unit-file.c index 4c307199e6..283895d8be 100644 --- a/src/shared/unit-file.c +++ b/src/shared/unit-file.c @@ -262,7 +262,7 @@ int unit_file_build_name_map( * If yes, do nothing. */ if (cache_timestamp_hash && lookup_paths_timestamp_hash_same(lp, *cache_timestamp_hash, ×tamp_hash)) - return 0; + return 0; /* The timestamp hash is now set based on the mtimes from before when we start reading files. * If anything is modified concurrently, we'll consider the cache outdated. */ From 98fac96c102f96819059686fe6329c08cfd8f6c0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 Jan 2021 15:00:41 +0100 Subject: [PATCH 2/5] unit-file: downgrade log message to debug In the other error paths unit_file_find_fragment() doesn't log beyond debug level, i.e. is of the non-logging library-like kind. Make sure this error path is handled the same, so that the caller can log. --- src/shared/unit-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/unit-file.c b/src/shared/unit-file.c index 283895d8be..f27352905d 100644 --- a/src/shared/unit-file.c +++ b/src/shared/unit-file.c @@ -511,7 +511,7 @@ int unit_file_find_fragment( r = unit_name_template(unit_name, &template); if (r < 0) - return log_error_errno(r, "Failed to determine template name: %m"); + return log_debug_errno(r, "Failed to determine template name: %m"); r = unit_ids_map_get(unit_ids_map, template, &fragment); if (r < 0 && !IN_SET(r, -ENOENT, -ENXIO)) From d5427dd29796a1ea464ed95e5ed3f0a0941ce01a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 Jan 2021 15:01:55 +0100 Subject: [PATCH 3/5] systemctl: properly initialize return params in all success cases --- src/systemctl/systemctl-util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/systemctl/systemctl-util.c b/src/systemctl/systemctl-util.c index 9713fce7af..aff247a881 100644 --- a/src/systemctl/systemctl-util.c +++ b/src/systemctl/systemctl-util.c @@ -477,7 +477,7 @@ int unit_find_paths( return -ERFKILL; if (streq(load_state, "not-found")) { r = 0; - goto not_found; + goto finish; } if (!STR_IN_SET(load_state, "loaded", "bad-setting")) return -EKEYREJECTED; @@ -534,6 +534,7 @@ int unit_find_paths( } } + finish: if (isempty(path)) { *ret_fragment_path = NULL; r = 0; @@ -550,7 +551,6 @@ int unit_find_paths( *ret_dropin_paths = NULL; } - not_found: if (r == 0 && !arg_force) log_error("No files found for %s.", unit_name); From 1842c1b2abbe46ab4b874e9eb7fa041f4ce8def6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 Jan 2021 15:02:27 +0100 Subject: [PATCH 4/5] systemctl: explicitly comment two cases where we don't log on error cases, on purpose --- src/systemctl/systemctl-util.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/systemctl/systemctl-util.c b/src/systemctl/systemctl-util.c index aff247a881..262854537d 100644 --- a/src/systemctl/systemctl-util.c +++ b/src/systemctl/systemctl-util.c @@ -439,12 +439,15 @@ int unit_find_paths( /** * Finds where the unit is defined on disk. Returns 0 if the unit is not found. Returns 1 if it is * found, and sets: + * * - the path to the unit in *ret_frament_path, if it exists on disk, + * * - and a strv of existing drop-ins in *ret_dropin_paths, if the arg is not NULL and any dropins * were found. * * Returns -ERFKILL if the unit is masked, and -EKEYREJECTED if the unit file could not be loaded for - * some reason (the latter only applies if we are going through the service manager). + * some reason (the latter only applies if we are going through the service manager). As special + * exception it won't log for these two error cases. */ assert(unit_name); @@ -474,13 +477,13 @@ int unit_find_paths( return log_error_errno(r, "Failed to get LoadState: %s", bus_error_message(&error, r)); if (streq(load_state, "masked")) - return -ERFKILL; + return -ERFKILL; /* special case: no logging */ if (streq(load_state, "not-found")) { r = 0; goto finish; } if (!STR_IN_SET(load_state, "loaded", "bad-setting")) - return -EKEYREJECTED; + return -EKEYREJECTED; /* special case: no logging */ r = sd_bus_get_property_string( bus, From b420e6f0ced5393db5337afe5bcfbd0f0f9cf291 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 Jan 2021 15:02:33 +0100 Subject: [PATCH 5/5] systemctl: unit_file_find_fragment() doesn't log about errors, hence do it in the caller --- src/systemctl/systemctl-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systemctl/systemctl-util.c b/src/systemctl/systemctl-util.c index 262854537d..a854107cc8 100644 --- a/src/systemctl/systemctl-util.c +++ b/src/systemctl/systemctl-util.c @@ -520,7 +520,7 @@ int unit_find_paths( r = unit_file_find_fragment(*cached_id_map, *cached_name_map, unit_name, &_path, &names); if (r < 0) - return r; + return log_error_errno(r, "Failed to find fragment for '%s': %m", unit_name); if (_path) { path = strdup(_path);