machined: introduce a ptsname_namespace() call and make use of it
The call is like ptsname() but does not assume the pty path was accessible in the local namespace. It uses the same internal ioctl though.
This commit is contained in:
@@ -1074,3 +1074,22 @@ int get_ctty(pid_t pid, dev_t *_devnr, char **r) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ptsname_namespace(int pty, char **ret) {
|
||||
int no = -1, r;
|
||||
|
||||
/* Like ptsname(), but doesn't assume that the path is
|
||||
* accessible in the local namespace. */
|
||||
|
||||
r = ioctl(pty, TIOCGPTN, &no);
|
||||
if (r < 0)
|
||||
return -errno;
|
||||
|
||||
if (no < 0)
|
||||
return -EIO;
|
||||
|
||||
if (asprintf(ret, "/dev/pts/%i", no) < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -107,3 +107,5 @@ int get_ctty(pid_t, dev_t *_devnr, char **r);
|
||||
|
||||
int getttyname_malloc(int fd, char **r);
|
||||
int getttyname_harder(int fd, char **r);
|
||||
|
||||
int ptsname_namespace(int pty, char **ret);
|
||||
|
||||
Reference in New Issue
Block a user