mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 16:37:19 +09:00
terminal-util: pidref'ify two terminal related calls
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user