terminal-util: introduce openpt_allocate()
Allocating a pty is done in a couple of places so let's introduce a new helper which does the job. Also the new function, as well as openpt_in_namespace(), returns both pty master and slave so the callers don't need to know about the pty slave allocation details. For the same reasons machine_openpt() prototype has also been changed to return both pty master and slave so callers don't need to allocate a pty slave which might be in a different namespace. Finally openpt_in_namespace() has been renamed into openpt_allocate_in_namespace().
This commit is contained in:
+4
-13
@@ -530,29 +530,20 @@ int machine_kill(Machine *m, KillWho who, int signo) {
|
||||
return manager_kill_unit(m->manager, m->unit, signo, NULL);
|
||||
}
|
||||
|
||||
int machine_openpt(Machine *m, int flags) {
|
||||
int machine_openpt(Machine *m, int flags, char **ret_slave) {
|
||||
assert(m);
|
||||
|
||||
switch (m->class) {
|
||||
|
||||
case MACHINE_HOST: {
|
||||
int fd;
|
||||
case MACHINE_HOST:
|
||||
|
||||
fd = posix_openpt(flags);
|
||||
if (fd < 0)
|
||||
return -errno;
|
||||
|
||||
if (unlockpt(fd) < 0)
|
||||
return -errno;
|
||||
|
||||
return fd;
|
||||
}
|
||||
return openpt_allocate(flags, ret_slave);
|
||||
|
||||
case MACHINE_CONTAINER:
|
||||
if (m->leader <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
return openpt_in_namespace(m->leader, flags);
|
||||
return openpt_allocate_in_namespace(m->leader, flags, ret_slave);
|
||||
|
||||
default:
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
Reference in New Issue
Block a user