[CRIU] [PATCH 3/9] tty: Parse slave peer index from fd_parms
Cyrill Gorcunov
gorcunov at openvz.org
Thu Oct 16 03:27:22 PDT 2014
We will use this path in reg-files engine anyway
so simply switch to this ability now.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
files.c | 5 +++++
tty.c | 22 +++++++---------------
2 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/files.c b/files.c
index 8c0ff1da6e43..04f6a0127b59 100644
--- a/files.c
+++ b/files.c
@@ -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;
}
diff --git a/tty.c b/tty.c
index 07978fcd99bd..78f9fd3fb4f9 100644
--- a/tty.c
+++ b/tty.c
@@ -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;
--
1.9.3
More information about the CRIU
mailing list