From 5f446751205e28b2cd68b9ec7e1125176c3783e0 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 18 Sep 2024 17:02:28 +0200 Subject: [PATCH] homectl: Acquire bus connection after querying for user input Otherwise when the user takes a long time to enter input the operation to create the user's home will fail with "transport endpoint not connected". --- src/home/homectl.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/home/homectl.c b/src/home/homectl.c index d1883f7421a..d1cc8146b6a 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -1411,12 +1411,6 @@ static int create_home_common(sd_json_variant *input) { _cleanup_hashmap_free_ Hashmap *blobs = NULL; int r; - r = acquire_bus(&bus); - if (r < 0) - return r; - - (void) polkit_agent_open_if_enabled(arg_transport, arg_ask_password); - r = acquire_new_home_record(input, &hr); if (r < 0) return r; @@ -1462,6 +1456,12 @@ static int create_home_common(sd_json_variant *input) { log_warning_errno(r, "Specified password does not pass quality checks (%s), proceeding anyway.", bus_error_message(&error, r)); } + r = acquire_bus(&bus); + if (r < 0) + return r; + + (void) polkit_agent_open_if_enabled(arg_transport, arg_ask_password); + for (;;) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; @@ -2477,7 +2477,6 @@ static int acquire_group_list(char ***ret) { } static int create_interactively(void) { - _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_free_ char *username = NULL; int r; @@ -2488,12 +2487,6 @@ static int create_interactively(void) { any_key_to_proceed(); - r = acquire_bus(&bus); - if (r < 0) - return r; - - (void) polkit_agent_open_if_enabled(arg_transport, arg_ask_password); - (void) terminal_reset_defensive_locked(STDOUT_FILENO, /* switch_to_text= */ false); for (;;) { -- 2.47.3