From: Daniel Lezcano Date: Wed, 24 Feb 2010 09:57:43 +0000 (+0100) Subject: set terminal settings when console is a tty X-Git-Tag: lxc-0.7.0~131 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0dc0de76ed1ad9e284a37bd01268227d4eae8c9;p=thirdparty%2Flxc.git set terminal settings when console is a tty As the console output can be a tty, we want to have the terminal to be set as a specific manner to not echo and receive signals from the keyboard. Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/conf.h b/src/lxc/conf.h index 39cb0ecf6..eede2b086 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -158,6 +158,7 @@ struct lxc_console { int master; int peer; char name[MAXPATHLEN]; + struct termios *tios; }; /* diff --git a/src/lxc/console.c b/src/lxc/console.c index 8e66665e6..c14a38bc0 100644 --- a/src/lxc/console.c +++ b/src/lxc/console.c @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -140,6 +141,8 @@ out_close: int lxc_create_console(struct lxc_console *console) { + struct termios tios; + if (openpty(&console->master, &console->slave, console->name, NULL, NULL)) { SYSERROR("failed to allocate a pty"); @@ -156,7 +159,41 @@ int lxc_create_console(struct lxc_console *console) goto err; } + if (!isatty(console->peer)) + return 0; + + console->tios = malloc(sizeof(tios)); + if (!console->tios) { + SYSERROR("failed to allocate memory"); + goto err; + } + + /* Get termios */ + if (tcgetattr(console->peer, console->tios)) { + SYSERROR("failed to get current terminal settings"); + goto err_free; + } + + tios = *console->tios; + + /* Remove the echo characters and signal reception, the echo + * will be done below with master proxying */ + tios.c_iflag &= ~IGNBRK; + tios.c_iflag &= BRKINT; + tios.c_lflag &= ~(ECHO|ICANON|ISIG); + tios.c_cc[VMIN] = 1; + tios.c_cc[VTIME] = 0; + + /* Set new attributes */ + if (tcsetattr(console->peer, TCSAFLUSH, &tios)) { + ERROR("failed to set new terminal settings"); + goto err_free; + } + return 0; + +err_free: + free(console->tios); err: close(console->master); close(console->slave); @@ -165,6 +202,9 @@ err: void lxc_delete_console(const struct lxc_console *console) { + if (console->tios && + tcsetattr(console->peer, TCSAFLUSH, console->tios)) + WARN("failed to set old terminal settings"); close(console->master); close(console->slave); }