From: Lennart Poettering Date: Tue, 7 Jan 2025 08:28:57 +0000 (+0100) Subject: terminal-util: pidref'ify two terminal related calls X-Git-Tag: v258-rc1~1634^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b25430deab0beea34e04cc17bc073dcbcd67973f;p=thirdparty%2Fsystemd.git terminal-util: pidref'ify two terminal related calls --- diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index ab926a42142..b5dc3f21b87 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -1355,14 +1355,16 @@ static int ptsname_namespace(int pty, char **ret) { return 0; } -int openpt_allocate_in_namespace(pid_t pid, int flags, char **ret_peer_path) { +int openpt_allocate_in_namespace( + const PidRef *pidref, + int flags, + char **ret_peer_path) { + _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF, fd = -EBADF; _cleanup_close_pair_ int pair[2] = EBADF_PAIR; int r; - assert(pid > 0); - - r = namespace_open(pid, &pidnsfd, &mntnsfd, /* ret_netns_fd = */ NULL, &usernsfd, &rootfd); + r = pidref_namespace_open(pidref, &pidnsfd, &mntnsfd, /* ret_netns_fd = */ NULL, &usernsfd, &rootfd); if (r < 0) return r; @@ -1411,15 +1413,18 @@ int openpt_allocate_in_namespace(pid_t pid, int flags, char **ret_peer_path) { return TAKE_FD(fd); } -int open_terminal_in_namespace(pid_t pid, const char *name, int mode) { +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(pid > 0); assert(name); - r = namespace_open(pid, &pidnsfd, &mntnsfd, /* ret_netns_fd= */ NULL, &usernsfd, &rootfd); + r = pidref_namespace_open(pidref, &pidnsfd, &mntnsfd, /* ret_netns_fd= */ NULL, &usernsfd, &rootfd); if (r < 0) return r; diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index 75b32190976..7ebfe61eb4f 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -10,6 +10,7 @@ #include #include "macro.h" +#include "pidref.h" #include "time-util.h" /* Erase characters until the end of the line */ @@ -143,8 +144,8 @@ int getttyname_harder(int fd, char **ret); int ptsname_malloc(int fd, char **ret); int openpt_allocate(int flags, char **ret_peer); -int openpt_allocate_in_namespace(pid_t pid, int flags, char **ret_peer); -int open_terminal_in_namespace(pid_t pid, const char *name, int mode); +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 3fc2b58fdb4..918cf1f9521 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -681,7 +681,7 @@ int machine_openpt(Machine *m, int flags, char **ret_peer) { if (!pidref_is_set(&m->leader)) return -EINVAL; - return openpt_allocate_in_namespace(m->leader.pid, flags, ret_peer); + return openpt_allocate_in_namespace(&m->leader, flags, ret_peer); default: return -EOPNOTSUPP; @@ -700,7 +700,7 @@ int machine_open_terminal(Machine *m, const char *path, int mode) { if (!pidref_is_set(&m->leader)) return -EINVAL; - return open_terminal_in_namespace(m->leader.pid, path, mode); + return open_terminal_in_namespace(&m->leader, path, mode); default: return -EOPNOTSUPP;