]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homectl: Acquire bus connection after querying for user input 34447/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 18 Sep 2024 15:02:28 +0000 (17:02 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 2 Oct 2024 13:08:50 +0000 (15:08 +0200)
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

index d1883f7421adf37ea2a56566dc9d7fa62726097a..d1cc8146b6a88c64fabdb65f7909ea7569604ff9 100644 (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 (;;) {