Commit 4dc96430 by Thomas Jarosch Committed by Christian Brauner

lxc_setup_tios(): Ignore SIGTTOU and SIGTTIN signals

Prevent an endless loop while executing lxc-attach in the background: The kernel might fire SIGTTOU while an ioctl() in tcsetattr() is executed. When the ioctl() is resumed and retries, the signal handler interrupts it again. We can't configure the TTY to stop sending the signals in the first place since that is a modification/write to the TTY already. Still we clear the TOSTOP flag to prevent further signals. Command to reproduce the hang: ---------------------------- cat > lxc_hang.sh << EOF /usr/bin/timeout 5s /usr/bin/lxc-attach -n SOMECONTAINER -- /bin/true EOF sh lxc_hang.sh # hangs ---------------------------- Signed-off-by: 's avatarThomas Jarosch <thomas.jarosch@intra2net.com>
parent 920da314
...@@ -257,6 +257,14 @@ int lxc_setup_tios(int fd, struct termios *oldtios) ...@@ -257,6 +257,14 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
return -1; return -1;
} }
/* ensure we don't end up in an endless loop:
* The kernel might fire SIGTTOU while an
* ioctl() in tcsetattr() is executed. When the ioctl()
* is resumed and retries, the signal handler interrupts it again.
*/
signal (SIGTTIN, SIG_IGN);
signal (SIGTTOU, SIG_IGN);
newtios = *oldtios; newtios = *oldtios;
/* We use the same settings that ssh does. */ /* We use the same settings that ssh does. */
...@@ -265,7 +273,7 @@ int lxc_setup_tios(int fd, struct termios *oldtios) ...@@ -265,7 +273,7 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
#ifdef IUCLC #ifdef IUCLC
newtios.c_iflag &= ~IUCLC; newtios.c_iflag &= ~IUCLC;
#endif #endif
newtios.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL); newtios.c_lflag &= ~(TOSTOP | ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
#ifdef IEXTEN #ifdef IEXTEN
newtios.c_lflag &= ~IEXTEN; newtios.c_lflag &= ~IEXTEN;
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment