mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-08 08:16:20 +00:00
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 <dlezcano@fr.ibm.com>
This commit is contained in:
parent
63376d7db3
commit
e0dc0de76e
@ -158,6 +158,7 @@ struct lxc_console {
|
|||||||
int master;
|
int master;
|
||||||
int peer;
|
int peer;
|
||||||
char name[MAXPATHLEN];
|
char name[MAXPATHLEN];
|
||||||
|
struct termios *tios;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -140,6 +141,8 @@ out_close:
|
|||||||
|
|
||||||
int lxc_create_console(struct lxc_console *console)
|
int lxc_create_console(struct lxc_console *console)
|
||||||
{
|
{
|
||||||
|
struct termios tios;
|
||||||
|
|
||||||
if (openpty(&console->master, &console->slave,
|
if (openpty(&console->master, &console->slave,
|
||||||
console->name, NULL, NULL)) {
|
console->name, NULL, NULL)) {
|
||||||
SYSERROR("failed to allocate a pty");
|
SYSERROR("failed to allocate a pty");
|
||||||
@ -156,7 +159,41 @@ int lxc_create_console(struct lxc_console *console)
|
|||||||
goto err;
|
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;
|
return 0;
|
||||||
|
|
||||||
|
err_free:
|
||||||
|
free(console->tios);
|
||||||
err:
|
err:
|
||||||
close(console->master);
|
close(console->master);
|
||||||
close(console->slave);
|
close(console->slave);
|
||||||
@ -165,6 +202,9 @@ err:
|
|||||||
|
|
||||||
void lxc_delete_console(const struct lxc_console *console)
|
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->master);
|
||||||
close(console->slave);
|
close(console->slave);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user