Commit 09aa15c7 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

tty: Parse slave peer index from fd_parms

We will use this path in reg-files engine anyway
so simply switch to this ability now.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Acked-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent d6e231ae
......@@ -282,6 +282,11 @@ static int dump_chrdev(struct fd_parms *p, int lfd, struct cr_img *img)
char more[32];
if (is_tty(maj, minor(p->stat.st_rdev))) {
struct fd_link link;
if (fill_fdlink(lfd, p, &link))
return -1;
p->link = &link;
ops = &tty_dump_ops;
break;
}
......
......@@ -199,7 +199,7 @@ int tty_verify_active_pairs(void)
return 0;
}
static int parse_pty_index(u32 id, int lfd, int type)
static int parse_pty_index(u32 id, int lfd, const struct fd_parms *p, int type)
{
int index = -1;
......@@ -212,22 +212,14 @@ static int parse_pty_index(u32 id, int lfd, int type)
break;
case TTY_TYPE_PTS: {
char path[PATH_MAX];
char link[32];
int len;
snprintf(link, sizeof(link), "/proc/self/fd/%d", lfd);
len = readlink(link, path, sizeof(path) - 1);
if (len < 0) {
pr_perror("Can't readlink %s", link);
return -1;
}
path[len] = '\0';
const struct fd_link *link = p->link;
char *pos = strrchr(link->name, '/');
if (sscanf(path, PTS_FMT, &index) != 1) {
pr_err("Unexpected format on path %s\n", path);
if (!pos || pos == (link->name + link->len - 1)) {
pr_err("Unexpected format on path %s\n", link->name + 1);
return -1;
}
index = atoi(pos + 1);
break;
}
}
......@@ -1175,7 +1167,7 @@ static int dump_one_pty(int lfd, u32 id, const struct fd_parms *p)
pr_info("Dumping tty %d with id %#x\n", lfd, id);
type = tty_type(major(p->stat.st_rdev), minor(p->stat.st_rdev));
index = parse_pty_index(id, lfd, type);
index = parse_pty_index(id, lfd, p, type);
if (index < 0)
return -1;
......
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