Skip to content

Commit

Permalink
Merge pull request #8794 from garazdawi/lukas/erts/fix-stdout-tty-cle…
Browse files Browse the repository at this point in the history
…anup/OTP-19232

erts: Require both stdin and stdout to be ttys to restore
  • Loading branch information
garazdawi authored Sep 19, 2024
2 parents b0fd5d7 + 08fea31 commit 918294d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions erts/emulator/sys/unix/erl_child_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ main(int argc, char *argv[])

SET_CLOEXEC(uds_fd);

if (isatty(0)) {
if (isatty(0) && isatty(1)) {
ssize_t res = read_all(uds_fd, (char*)&initial_tty_mode, sizeof(struct termios));
if (res <= 0) {
ABORT("Failed to read initial_tty_mode: %d (%d)", res, errno);
Expand Down Expand Up @@ -560,7 +560,7 @@ main(int argc, char *argv[])
pipes, 3, MSG_DONTWAIT)) < 0) {
if (errno == EINTR)
continue;
if (isatty(0)) {
if (isatty(0) && isatty(1)) {
tcsetattr(0,TCSANOW,&initial_tty_mode);
}
DEBUG_PRINT("erl_child_setup failed to read from uds: %d, %d", res, errno);
Expand All @@ -569,7 +569,7 @@ main(int argc, char *argv[])

if (res == 0) {
DEBUG_PRINT("uds was closed!");
if (isatty(0)) {
if (isatty(0) && isatty(1)) {
tcsetattr(0,TCSANOW,&initial_tty_mode);
}
_exit(0);
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/sys/unix/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void sys_tty_reset(int exit_code)
if (using_oldshell && !replace_intr) {
SET_BLOCKING(0);
}
else if (isatty(0)) {
else if (isatty(0) && isatty(1)) {
tcsetattr(0,TCSANOW,&erl_sys_initial_tty_mode);
}
}
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/sys/unix/sys_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ static ErlDrvData forker_start(ErlDrvPort port_num, char* name,
/* If stdin is a tty then we need to restore its settings when we exit.
So we send the tty mode to erl_child_setup so that it can cleanup
in case the emulator is terminated with SIGKILL. */
if (isatty(0)) {
if (isatty(0) && isatty(1)) {
ssize_t res, pos = 0;
size_t size = sizeof(struct termios);
byte *buff = (byte *)&erl_sys_initial_tty_mode;
Expand Down

0 comments on commit 918294d

Please sign in to comment.