]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: with TIOCGPTPEER there's no longer need to acquire pty peer through IPC
authorMike Yuan <me@yhndnzj.com>
Wed, 15 Jan 2025 16:27:25 +0000 (17:27 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 15 Jan 2025 16:46:10 +0000 (17:46 +0100)
src/run/run.c

index f1564b522e091d95a7bd67a643fb50402e1dd12e..0de5e4e491b99611c36e29be5b03293f965d398d 100644 (file)
@@ -1153,7 +1153,7 @@ static int transient_service_set_properties(sd_bus_message *m, const char *pty_p
         bool use_ex_prop = !arg_expand_environment;
 
         assert(m);
-        assert(pty_path || pty_fd < 0);
+        assert((!!pty_path) == (pty_fd >= 0));
 
         r = transient_unit_set_properties(m, UNIT_SERVICE, arg_property);
         if (r < 0)
@@ -1204,22 +1204,11 @@ static int transient_service_set_properties(sd_bus_message *m, const char *pty_p
         }
 
         if (pty_path) {
-                r = sd_bus_message_append(m, "(sv)", "TTYPath", "s", pty_path);
-                if (r < 0)
-                        return bus_log_create_error(r);
-
-                if (pty_fd >= 0)
-                        r = sd_bus_message_append(m,
-                                                  "(sv)(sv)(sv)",
-                                                  "StandardInputFileDescriptor", "h", pty_fd,
-                                                  "StandardOutputFileDescriptor", "h", pty_fd,
-                                                  "StandardErrorFileDescriptor", "h", pty_fd);
-                else
-                        r = sd_bus_message_append(m,
-                                                  "(sv)(sv)(sv)",
-                                                  "StandardInput", "s", "tty",
-                                                  "StandardOutput", "s", "tty",
-                                                  "StandardError", "s", "tty");
+                r = sd_bus_message_append(m, "(sv)(sv)(sv)(sv)",
+                                          "TTYPath", "s", pty_path,
+                                          "StandardInputFileDescriptor", "h", pty_fd,
+                                          "StandardOutputFileDescriptor", "h", pty_fd,
+                                          "StandardErrorFileDescriptor", "h", pty_fd);
                 if (r < 0)
                         return bus_log_create_error(r);
 
@@ -1967,9 +1956,6 @@ static int start_transient_service(sd_bus *bus) {
                         peer_fd = pty_open_peer(pty_fd, O_RDWR|O_NOCTTY|O_CLOEXEC);
                         if (peer_fd < 0)
                                 return log_error_errno(peer_fd, "Failed to open PTY peer: %m");
-
-                        // FIXME: Introduce OpenMachinePTYEx() that accepts ownership/permission as param
-                        // and additionally returns the pty fd, for #33216 and #32999
                 } else
                         assert_not_reached();
         }