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".
This commit is contained in:
Daan De Meyer
2024-10-02 15:08:50 +02:00
parent 84edd52121
commit 5f44675120
+6 -13
View File
@@ -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 (;;) {