From: Daan De Meyer Date: Wed, 18 Sep 2024 15:02:28 +0000 (+0200) Subject: homectl: Acquire bus connection after querying for user input X-Git-Tag: v257-rc1~337^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F34447%2Fhead;p=thirdparty%2Fsystemd.git 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". --- 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 (;;) {