From 978cecd629b38d2fc0b6aecea0e66f963eaae556 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Fri, 14 Sep 2012 17:50:41 +0400 Subject: [PATCH] tty: Make termios and winsize being optional params The dangling slave peers might have no data associate with them if master peer is closed and link is hanging up. Thus make this parameters optional to not blow the image with data which never will be used. Signed-off-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov --- protobuf/tty.proto | 6 +++--- tty.c | 32 +++++++++++++++++++------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/protobuf/tty.proto b/protobuf/tty.proto index dd3eec8c5..c9760a018 100644 --- a/protobuf/tty.proto +++ b/protobuf/tty.proto @@ -47,9 +47,9 @@ message tty_info_entry { */ required uint32 rdev = 8; - required termios_entry termios = 9; - required termios_entry termios_locked = 10; - required winsize_entry winsize = 11; + optional termios_entry termios = 9; + optional termios_entry termios_locked = 10; + optional winsize_entry winsize = 11; /* * These are optional fields which presense depends on diff --git a/tty.c b/tty.c index ae8045c45..139f2946c 100644 --- a/tty.c +++ b/tty.c @@ -412,20 +412,26 @@ static int restore_tty_params(int fd, struct tty_info *info) * never be extended. */ - memzero(&t, sizeof(t)); - termios_copy(&t, info->tie->termios_locked); - if (ioctl(fd, TIOCSLCKTRMIOS, &t) < 0) - goto err; + if (info->tie->termios_locked) { + memzero(&t, sizeof(t)); + termios_copy(&t, info->tie->termios_locked); + if (ioctl(fd, TIOCSLCKTRMIOS, &t) < 0) + goto err; + } - memzero(&t, sizeof(t)); - termios_copy(&t, info->tie->termios); - if (ioctl(fd, TCSETS, &t) < 0) - goto err; + if (info->tie->termios) { + memzero(&t, sizeof(t)); + termios_copy(&t, info->tie->termios); + if (ioctl(fd, TCSETS, &t) < 0) + goto err; + } - memzero(&w, sizeof(w)); - winsize_copy(&w, info->tie->winsize); - if (ioctl(fd, TIOCSWINSZ, &w) < 0) - goto err; + if (info->tie->winsize) { + memzero(&w, sizeof(w)); + winsize_copy(&w, info->tie->winsize); + if (ioctl(fd, TIOCSWINSZ, &w) < 0) + goto err; + } return 0; err: @@ -632,7 +638,7 @@ static int tty_setup_slavery(void) static int veirfy_termios(u32 id, TermiosEntry *e) { - if (e->n_c_cc < TERMIOS_NCC) { + if (e && e->n_c_cc < TERMIOS_NCC) { pr_err("pty ID %#x n_c_cc (%d) has wrong value\n", id, (int)e->n_c_cc); return -1;