[CRIU] [PATCH 12/12] tty: Move general parameters filling into separate routine
Cyrill Gorcunov
gorcunov at openvz.org
Fri Oct 3 00:50:05 PDT 2014
To eliminate code duplication.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
tty.c | 100 +++++++++++++++++++++++++++---------------------------------------
1 file changed, 41 insertions(+), 59 deletions(-)
diff --git a/tty.c b/tty.c
index 029849333bf9..03d03d11231d 100644
--- a/tty.c
+++ b/tty.c
@@ -1254,6 +1254,45 @@ int dump_verify_tty_sids(void)
return ret;
}
+static int tty_fill_general(int lfd, u32 id, TtyInfoEntry *info)
+{
+ struct termios t;
+ struct winsize w;
+ int ret = -1;
+
+ /*
+ * Make sure the structures the system provides us
+ * correlates well with protobuf templates.
+ */
+ BUILD_BUG_ON(ARRAY_SIZE(t.c_cc) < TERMIOS_NCC);
+ BUILD_BUG_ON(sizeof(info->termios->c_cc) != sizeof(void *));
+ BUILD_BUG_ON((sizeof(info->termios->c_cc) * TERMIOS_NCC) < sizeof(t.c_cc));
+
+ memzero(&t, sizeof(t));
+ if (ioctl(lfd, TCGETS, &t) < 0) {
+ pr_perror("Can't get tty params on %x", id);
+ goto out;
+ }
+ termios_copy(info->termios, &t);
+
+ memzero(&t, sizeof(t));
+ if (ioctl(lfd, TIOCGLCKTRMIOS, &t) < 0) {
+ pr_perror("Can't get tty locked params on %x", id);
+ goto out;
+ }
+ termios_copy(info->termios_locked, &t);
+
+ memzero(&w, sizeof(w));
+ if (ioctl(lfd, TIOCGWINSZ, &w) < 0) {
+ pr_perror("Can't get tty window params on %x", id);
+ goto out;
+ }
+ winsize_copy(info->winsize, &w);
+ ret = 0;
+out:
+ return ret;
+}
+
static int dump_pty_info(int lfd, u32 id, const struct fd_parms *p, const struct mount_info *m, int major, int minor, int index)
{
TtyInfoEntry info = TTY_INFO_ENTRY__INIT;
@@ -1264,19 +1303,8 @@ static int dump_pty_info(int lfd, u32 id, const struct fd_parms *p, const struct
struct parasite_tty_args *pti;
struct tty_dump_info *dinfo;
- struct termios t;
- struct winsize w;
-
int ret = -1;
- /*
- * Make sure the structures the system provides us
- * correlates well with protobuf templates.
- */
- BUILD_BUG_ON(ARRAY_SIZE(t.c_cc) < TERMIOS_NCC);
- BUILD_BUG_ON(sizeof(termios.c_cc) != sizeof(void *));
- BUILD_BUG_ON((sizeof(termios.c_cc) * TERMIOS_NCC) < sizeof(t.c_cc));
-
pti = parasite_dump_tty(p->ctl, p->fd);
if (!pti)
return -1;
@@ -1339,26 +1367,8 @@ static int dump_pty_info(int lfd, u32 id, const struct fd_parms *p, const struct
if (!termios.c_cc || !termios_locked.c_cc)
goto out;
- memzero(&t, sizeof(t));
- if (ioctl(lfd, TCGETS, &t) < 0) {
- pr_perror("Can't get tty params on %x", id);
- goto out;
- }
- termios_copy(&termios, &t);
-
- memzero(&t, sizeof(t));
- if (ioctl(lfd, TIOCGLCKTRMIOS, &t) < 0) {
- pr_perror("Can't get tty locked params on %x", id);
- goto out;
- }
- termios_copy(&termios_locked, &t);
-
- memzero(&w, sizeof(w));
- if (ioctl(lfd, TIOCGWINSZ, &w) < 0) {
- pr_perror("Can't get tty window params on %x", id);
+ if (tty_fill_general(lfd, id, &info))
goto out;
- }
- winsize_copy(&winsize, &w);
ret = pb_write_one(img_from_set(glob_imgset, CR_FD_TTY_INFO), &info, PB_TTY_INFO);
out:
@@ -1434,9 +1444,6 @@ static int dump_ext_tty(int lfd, u32 id, const struct fd_parms *p, int major, in
WinsizeEntry winsize = WINSIZE_ENTRY__INIT;
TtyExtEntry ety = TTY_EXT_ENTRY__INIT;
- struct termios t;
- struct winsize w;
-
ext_tty_range_t *ext;
char path[PATH_MAX];
char link[32];
@@ -1465,13 +1472,6 @@ static int dump_ext_tty(int lfd, u32 id, const struct fd_parms *p, int major, in
e.flags = p->flags;
e.fown = (FownEntry *)&p->fown;
- /*
- * FIXME Merge with dump_pty_info()
- */
- BUILD_BUG_ON(ARRAY_SIZE(t.c_cc) < TERMIOS_NCC);
- BUILD_BUG_ON(sizeof(termios.c_cc) != sizeof(void *));
- BUILD_BUG_ON((sizeof(termios.c_cc) * TERMIOS_NCC) < sizeof(t.c_cc));
-
info.id = e.tty_info_id;
info.type = TTY_TYPE__EXT;
info.sid = 0;
@@ -1493,26 +1493,8 @@ static int dump_ext_tty(int lfd, u32 id, const struct fd_parms *p, int major, in
if (!termios.c_cc || !termios_locked.c_cc)
goto out;
- memzero(&t, sizeof(t));
- if (ioctl(lfd, TCGETS, &t) < 0) {
- pr_perror("Can't get tty params on %x", id);
- goto out;
- }
- termios_copy(&termios, &t);
-
- memzero(&t, sizeof(t));
- if (ioctl(lfd, TIOCGLCKTRMIOS, &t) < 0) {
- pr_perror("Can't get tty locked params on %x", id);
- goto out;
- }
- termios_copy(&termios_locked, &t);
-
- memzero(&w, sizeof(w));
- if (ioctl(lfd, TIOCGWINSZ, &w) < 0) {
- pr_perror("Can't get tty window params on %x", id);
+ if (tty_fill_general(lfd, id, &info))
goto out;
- }
- winsize_copy(&winsize, &w);
ret = pb_write_one(img_from_set(glob_imgset, CR_FD_TTY_INFO), &info, PB_TTY_INFO);
--
1.9.3
More information about the CRIU
mailing list