summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Ferrari <nekkodroid404@gmail.com>2024-09-16 19:54:53 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-09-17 20:21:11 +0200
commit91ea3dcf35e4e3fdfe360069819517436c3ae3c7 (patch)
tree301ee052cd10fed175fa45ba48e251b6c2d48308
parentUse correct error code in log message in output_waiting_jobs (#34404) (diff)
downloadsystemd-91ea3dcf35e4e3fdfe360069819517436c3ae3c7.tar.xz
systemd-91ea3dcf35e4e3fdfe360069819517436c3ae3c7.zip
homed: wait for user input during firstboot
This mirrors the behavior of `systemd-firstboot` and allows bootup messages to settle down before user input is actually processed. See: https://github.com/systemd/systemd/issues/34448
-rw-r--r--src/basic/terminal-util.c19
-rw-r--r--src/basic/terminal-util.h1
-rw-r--r--src/firstboot/firstboot.c18
-rw-r--r--src/home/homectl.c2
4 files changed, 24 insertions, 16 deletions
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index 94720c9adf..cff1d50e42 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -255,6 +255,25 @@ int ask_string(char **ret, const char *text, ...) {
return 0;
}
+bool any_key_to_proceed(void) {
+ char key = 0;
+ bool need_nl = true;
+
+ /*
+ * Insert a new line here as well as to when the user inputs, as this is also used during the
+ * boot up sequence when status messages may be interleaved with the current program output.
+ * This ensures that the status messages aren't appended on the same line as this message.
+ */
+ puts("-- Press any key to proceed --");
+
+ (void) read_one_char(stdin, &key, USEC_INFINITY, &need_nl);
+
+ if (need_nl)
+ putchar('\n');
+
+ return key != 'q';
+}
+
int open_terminal(const char *name, int mode) {
_cleanup_close_ int fd = -EBADF;
unsigned c = 0;
diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h
index f8a30bbb64..180ca24ef4 100644
--- a/src/basic/terminal-util.h
+++ b/src/basic/terminal-util.h
@@ -78,6 +78,7 @@ int chvt(int vt);
int read_one_char(FILE *f, char *ret, usec_t timeout, bool *need_nl);
int ask_char(char *ret, const char *replies, const char *text, ...) _printf_(3, 4);
int ask_string(char **ret, const char *text, ...) _printf_(2, 3);
+bool any_key_to_proceed(void);
int vt_disallocate(const char *name);
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index 85ceffa13b..f4601c0210 100644
--- a/src/firstboot/firstboot.c
+++ b/src/firstboot/firstboot.c
@@ -93,20 +93,6 @@ STATIC_DESTRUCTOR_REGISTER(arg_root_shell, freep);
STATIC_DESTRUCTOR_REGISTER(arg_kernel_cmdline, freep);
STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep);
-static bool press_any_key(void) {
- char k = 0;
- bool need_nl = true;
-
- puts("-- Press any key to proceed --");
-
- (void) read_one_char(stdin, &k, USEC_INFINITY, &need_nl);
-
- if (need_nl)
- putchar('\n');
-
- return k != 'q';
-}
-
static void print_welcome(int rfd) {
_cleanup_free_ char *pretty_name = NULL, *os_name = NULL, *ansi_color = NULL;
static bool done = false;
@@ -141,7 +127,7 @@ static void print_welcome(int rfd) {
printf("\nPlease configure your system!\n\n");
- press_any_key();
+ any_key_to_proceed();
done = true;
}
@@ -184,7 +170,7 @@ static int show_menu(char **x, unsigned n_columns, unsigned width, unsigned perc
/* on the first screen we reserve 2 extra lines for the title */
if (i % break_lines == break_modulo) {
- if (!press_any_key())
+ if (!any_key_to_proceed())
return 0;
}
}
diff --git a/src/home/homectl.c b/src/home/homectl.c
index 83deeac123..a52bc6d464 100644
--- a/src/home/homectl.c
+++ b/src/home/homectl.c
@@ -2434,6 +2434,8 @@ static int create_interactively(void) {
return 0;
}
+ any_key_to_proceed();
+
r = acquire_bus(&bus);
if (r < 0)
return r;