Commit 1c478a2e authored by Andrei Vagin's avatar Andrei Vagin Committed by Pavel Emelyanov

tty: split pty_open_ptmx_index()

We are going to create slave pty-s to bind-mount them,
but at this moment we don't have file_desc-s and actually
can't open /dev/ptmx by path.
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 129b18d3
...@@ -543,8 +543,9 @@ static int do_open_tty_reg(int ns_root_fd, struct reg_file_info *rfi, void *arg) ...@@ -543,8 +543,9 @@ static int do_open_tty_reg(int ns_root_fd, struct reg_file_info *rfi, void *arg)
return fd; return fd;
} }
static int open_tty_reg(struct file_desc *reg_d, u32 flags) static int open_tty_reg(void *arg, int flags)
{ {
struct file_desc *reg_d = arg;
/* /*
* Never set as a control terminal automatically, all * Never set as a control terminal automatically, all
* ctty magic happens only in tty_set_sid(). * ctty magic happens only in tty_set_sid().
...@@ -559,7 +560,8 @@ static char *path_from_reg(struct file_desc *d) ...@@ -559,7 +560,8 @@ static char *path_from_reg(struct file_desc *d)
return rfi->path; return rfi->path;
} }
static int pty_open_ptmx_index(struct file_desc *d, int index, int flags) static int __pty_open_ptmx_index(int index, int flags,
int (*cb)(void *arg, int flags), void *arg, char *path)
{ {
int fds[32], i, ret = -1, cur_idx; int fds[32], i, ret = -1, cur_idx;
...@@ -568,15 +570,15 @@ static int pty_open_ptmx_index(struct file_desc *d, int index, int flags) ...@@ -568,15 +570,15 @@ static int pty_open_ptmx_index(struct file_desc *d, int index, int flags)
mutex_lock(tty_mutex); mutex_lock(tty_mutex);
for (i = 0; i < ARRAY_SIZE(fds); i++) { for (i = 0; i < ARRAY_SIZE(fds); i++) {
fds[i] = open_tty_reg(d, flags); fds[i] = cb(arg, flags);
if (fds[i] < 0) { if (fds[i] < 0) {
pr_err("Can't open %s\n", path_from_reg(d)); pr_err("Can't open %s\n", path);
break; break;
} }
if (ioctl(fds[i], TIOCGPTN, &cur_idx)) { if (ioctl(fds[i], TIOCGPTN, &cur_idx)) {
pr_perror("Can't obtain current index on %s", pr_perror("Can't obtain current index on %s",
path_from_reg(d)); path);
break; break;
} }
...@@ -597,7 +599,7 @@ static int pty_open_ptmx_index(struct file_desc *d, int index, int flags) ...@@ -597,7 +599,7 @@ static int pty_open_ptmx_index(struct file_desc *d, int index, int flags)
continue; continue;
pr_err("Unable to open %s with specified index %d\n", pr_err("Unable to open %s with specified index %d\n",
path_from_reg(d), index); path, index);
break; break;
} }
...@@ -611,6 +613,12 @@ static int pty_open_ptmx_index(struct file_desc *d, int index, int flags) ...@@ -611,6 +613,12 @@ static int pty_open_ptmx_index(struct file_desc *d, int index, int flags)
return ret; return ret;
} }
static int pty_open_ptmx_index(struct file_desc *d, struct tty_info *info, int flags)
{
return __pty_open_ptmx_index(info->tie->pty->index, flags,
open_tty_reg, d, path_from_reg(d));
}
static int unlock_pty(int fd) static int unlock_pty(int fd)
{ {
const int lock = 0; const int lock = 0;
...@@ -965,7 +973,7 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave) ...@@ -965,7 +973,7 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave)
fake = pty_alloc_fake_master(slave); fake = pty_alloc_fake_master(slave);
if (!fake) if (!fake)
goto err; goto err;
master = pty_open_ptmx_index(&fake->d, slave->tie->pty->index, O_RDONLY); master = pty_open_ptmx_index(&fake->d, slave, O_RDONLY);
if (master < 0) { if (master < 0) {
pr_err("Can't open master pty %#x (index %d)\n", pr_err("Can't open master pty %#x (index %d)\n",
slave->tfe->id, slave->tie->pty->index); slave->tfe->id, slave->tie->pty->index);
...@@ -1026,7 +1034,7 @@ static int pty_open_ptmx(struct tty_info *info) ...@@ -1026,7 +1034,7 @@ static int pty_open_ptmx(struct tty_info *info)
{ {
int master = -1; int master = -1;
master = pty_open_ptmx_index(info->reg_d, info->tie->pty->index, info->tfe->flags); master = pty_open_ptmx_index(info->reg_d, info, info->tfe->flags);
if (master < 0) { if (master < 0) {
pr_err("Can't open master pty %#x (index %d)\n", pr_err("Can't open master pty %#x (index %d)\n",
info->tfe->id, info->tie->pty->index); info->tfe->id, info->tie->pty->index);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment