From b498f250b25c4f7d93cdf257de140e150c7a1ba7 Mon Sep 17 00:00:00 2001 From: Ivan Shapovalov Date: Wed, 17 Jul 2024 10:50:27 +0200 Subject: [PATCH 1/5] systemctl: cat: do not exit(1) on missing units if `--force` We are eating the error message if `--force` is set, so do not return a non-zero exit code either. --- src/systemctl/systemctl-edit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index b7bd3851fd0..880bd4d742e 100644 --- a/src/systemctl/systemctl-edit.c +++ b/src/systemctl/systemctl-edit.c @@ -69,8 +69,9 @@ int verb_cat(int argc, char *argv[], void *userdata) { return r; if (r == 0) { /* Skip units which have no on-disk counterpart, but propagate the error to the - * user */ - rc = -ENOENT; + * user (if --force is set, eat the error, just like unit_find_paths()) */ + if (!arg_force) + rc = -ENOENT; continue; } From c47f2a26b03b7ec5e8e7dbec896e8da568d57214 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 3 Sep 2024 11:46:45 +0900 Subject: [PATCH 2/5] test: add test cases of "systemctl cat" for nonexistent units --- test/units/TEST-26-SYSTEMCTL.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/units/TEST-26-SYSTEMCTL.sh b/test/units/TEST-26-SYSTEMCTL.sh index 1471f3fd9e4..ed7b9f64bff 100755 --- a/test/units/TEST-26-SYSTEMCTL.sh +++ b/test/units/TEST-26-SYSTEMCTL.sh @@ -340,6 +340,8 @@ done systemctl is-active "*-journald.service" systemctl cat "*udevd*" systemctl cat "$UNIT_NAME" +(! systemctl cat hopefully-nonexistent-unit.service) +systemctl cat --force hopefully-nonexistent-unit.service systemctl help "$UNIT_NAME" systemctl service-watchdogs systemctl service-watchdogs "$(systemctl service-watchdogs)" From b7c0d924bd9802cb3dee0f463d7027dd67d61b2c Mon Sep 17 00:00:00 2001 From: Michael Ferrari Date: Wed, 5 Jun 2024 19:33:19 +0200 Subject: [PATCH 3/5] firstboot: add newline before key wait When sd-firstboot is ran during first boot of a new system this missing newline leads to a bootup message being appended on the same line as the message instructing to press a key. --- src/firstboot/firstboot.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index c452ca59756..af17b527c15 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -97,8 +97,7 @@ static bool press_any_key(void) { char k = 0; bool need_nl = true; - printf("-- Press any key to proceed --"); - fflush(stdout); + puts("-- Press any key to proceed --"); (void) read_one_char(stdin, &k, USEC_INFINITY, &need_nl); From 3f084827fff476367b3a6f045c7cb5ca0ed848a1 Mon Sep 17 00:00:00 2001 From: Michael Ferrari Date: Wed, 5 Jun 2024 19:40:57 +0200 Subject: [PATCH 4/5] firstboot: reduce empty input log level The user knows they pressed `Enter`, no need to inform them again about that they skipped the prompt. --- src/firstboot/firstboot.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index af17b527c15..cdd416b5714 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -209,7 +209,7 @@ static int prompt_loop(const char *text, char **l, unsigned percentage, bool (*i return log_error_errno(r, "Failed to query user: %m"); if (isempty(p)) { - log_warning("No data entered, skipping."); + log_info("No data entered, skipping."); return 0; } @@ -681,7 +681,7 @@ static int prompt_hostname(int rfd) { return log_error_errno(r, "Failed to query hostname: %m"); if (isempty(h)) { - log_warning("No hostname entered, skipping."); + log_info("No hostname entered, skipping."); break; } @@ -808,7 +808,7 @@ static int prompt_root_password(int rfd) { "Received multiple passwords, where we expected one."); if (isempty(*a)) { - log_warning("No password entered, skipping."); + log_info("No password entered, skipping."); break; } @@ -888,7 +888,7 @@ static int prompt_root_shell(int rfd) { return log_error_errno(r, "Failed to query root shell: %m"); if (isempty(s)) { - log_warning("No shell entered, skipping."); + log_info("No shell entered, skipping."); break; } From 87e0eafe032727c45d0dc36bfa70c31934dd2269 Mon Sep 17 00:00:00 2001 From: Michael Ferrari Date: Thu, 6 Jun 2024 16:06:34 +0200 Subject: [PATCH 5/5] firstboot: reduce log level of timezone validation An error message is already printed directly after, so the user already knows that the validation failed. This also isn't done for the other validation functions. --- src/firstboot/firstboot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index cdd416b5714..85ceffa13b8 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -559,8 +559,8 @@ static int process_keymap(int rfd) { return 1; } -static bool timezone_is_valid_log_error(const char *name) { - return timezone_is_valid(name, LOG_ERR); +static bool timezone_is_valid_log_debug(const char *name) { + return timezone_is_valid(name, LOG_DEBUG); } static int prompt_timezone(int rfd) { @@ -592,7 +592,7 @@ static int prompt_timezone(int rfd) { print_welcome(rfd); r = prompt_loop("Please enter timezone name or number", - zones, 30, timezone_is_valid_log_error, &arg_timezone); + zones, 30, timezone_is_valid_log_debug, &arg_timezone); if (r < 0) return r;