]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: pidref'ify two terminal related calls
authorLennart Poettering <lennart@poettering.net>
Tue, 7 Jan 2025 08:28:57 +0000 (09:28 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 10 Jan 2025 13:09:48 +0000 (14:09 +0100)
src/basic/terminal-util.c
src/basic/terminal-util.h
src/machine/machine.c

index ab926a42142c0ba8798ef941d84dcaa0e00c30cf..b5dc3f21b877fb1dd036f6aad601d6d606442079 100644 (file)
@@ -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;
 
index 75b32190976a2f43d1bb3a8a05bb81ea1a591f5d..7ebfe61eb4f6f84cb589af650e73e96e9147bd57 100644 (file)
@@ -10,6 +10,7 @@
 #include <unistd.h>
 
 #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);
index 3fc2b58fdb45c8fe6763893aa5b9c3a40fd2970d..918cf1f95218fe7d1bd50542a1acba6d5984ad59 100644 (file)
@@ -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;