summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2025-01-15 21:05:59 +0100
committerGitHub <noreply@github.com>2025-01-15 21:05:59 +0100
commit2ca0f3ed2e03de891759f9115c9fdf79ef0022b9 (patch)
treea3c93f0299810991e191b830dbb4642dd79a53f2
parentpam-systemd: introduce "user-light" session type, and make "background-light"... (diff)
parentterminal-util: drop unused open_terminal_in_namespace() (diff)
downloadsystemd-2ca0f3ed2e03de891759f9115c9fdf79ef0022b9.tar.xz
systemd-2ca0f3ed2e03de891759f9115c9fdf79ef0022b9.zip
pty_open_peer() follow-up (#36027)
-rw-r--r--src/basic/terminal-util.c50
-rw-r--r--src/basic/terminal-util.h1
-rw-r--r--src/machine/machine.c19
-rw-r--r--src/machine/machine.h1
-rw-r--r--src/run/run.c28
5 files changed, 7 insertions, 92 deletions
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index f1967a15c0..eeeb657623 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -1413,56 +1413,6 @@ int openpt_allocate_in_namespace(
return TAKE_FD(fd);
}
-int open_terminal_in_namespace(
- const PidRef *pidref,
- const char *name,
- int mode) {
-
- _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF;
- _cleanup_close_pair_ int pair[2] = EBADF_PAIR;
- int r;
-
- assert(name);
-
- r = pidref_namespace_open(pidref, &pidnsfd, &mntnsfd, /* ret_netns_fd= */ NULL, &usernsfd, &rootfd);
- if (r < 0)
- return r;
-
- if (socketpair(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, pair) < 0)
- return -errno;
-
- r = namespace_fork(
- "(sd-terminalns)",
- "(sd-terminal)",
- /* except_fds= */ NULL,
- /* n_except_fds= */ 0,
- FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGKILL|FORK_WAIT,
- pidnsfd,
- mntnsfd,
- /* netnsd_fd= */ -EBADF,
- usernsfd,
- rootfd,
- /* ret_pid= */ NULL);
- if (r < 0)
- return r;
- if (r == 0) {
- pair[0] = safe_close(pair[0]);
-
- int pty_fd = open_terminal(name, mode|O_NOCTTY|O_CLOEXEC);
- if (pty_fd < 0)
- _exit(EXIT_FAILURE);
-
- if (send_one_fd(pair[1], pty_fd, 0) < 0)
- _exit(EXIT_FAILURE);
-
- _exit(EXIT_SUCCESS);
- }
-
- pair[1] = safe_close(pair[1]);
-
- return receive_one_fd(pair[0], 0);
-}
-
static bool on_dev_null(void) {
struct stat dst, ost, est;
diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h
index a9c8ba7789..d6dd394bcf 100644
--- a/src/basic/terminal-util.h
+++ b/src/basic/terminal-util.h
@@ -145,7 +145,6 @@ int ptsname_malloc(int fd, char **ret);
int openpt_allocate(int flags, char **ret_peer);
int openpt_allocate_in_namespace(const PidRef *pidref, int flags, char **ret_peer);
-int open_terminal_in_namespace(const PidRef *pidref, const char *name, int mode);
int vt_restore(int fd);
int vt_release(int fd, bool restore_vt);
diff --git a/src/machine/machine.c b/src/machine/machine.c
index 3bb7a94ddd..76467f1bf6 100644
--- a/src/machine/machine.c
+++ b/src/machine/machine.c
@@ -688,25 +688,6 @@ int machine_openpt(Machine *m, int flags, char **ret_peer) {
}
}
-int machine_open_terminal(Machine *m, const char *path, int mode) {
- assert(m);
-
- switch (m->class) {
-
- case MACHINE_HOST:
- return open_terminal(path, mode);
-
- case MACHINE_CONTAINER:
- if (!pidref_is_set(&m->leader))
- return -EINVAL;
-
- return open_terminal_in_namespace(&m->leader, path, mode);
-
- default:
- return -EOPNOTSUPP;
- }
-}
-
static int machine_bus_new(Machine *m, sd_bus_error *error, sd_bus **ret) {
int r;
diff --git a/src/machine/machine.h b/src/machine/machine.h
index 614d295bca..6d972c1533 100644
--- a/src/machine/machine.h
+++ b/src/machine/machine.h
@@ -102,7 +102,6 @@ const char* kill_whom_to_string(KillWhom k) _const_;
KillWhom kill_whom_from_string(const char *s) _pure_;
int machine_openpt(Machine *m, int flags, char **ret_peer);
-int machine_open_terminal(Machine *m, const char *path, int mode);
int machine_start_getty(Machine *m, const char *ptmx_name, sd_bus_error *error);
int machine_start_shell(Machine *m, int ptmx_fd, const char *ptmx_name, const char *user, const char *path, char **args, char **env, sd_bus_error *error);
#define machine_default_shell_path() ("/bin/sh")
diff --git a/src/run/run.c b/src/run/run.c
index 7538029548..af28d60858 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -1188,7 +1188,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)
@@ -1239,22 +1239,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);
@@ -2041,10 +2030,7 @@ 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_debug_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
+ return log_error_errno(peer_fd, "Failed to open PTY peer: %m");
} else
assert_not_reached();
}