Some program started in a large script is doing stty -echo
. I'm not sure which program it is so I have to try to find it by trial and error. Is </dev/null 2>&1 | tee /dev/null
sufficient to block programs from accessing the terminal, or is there another way to get access to the terminal?
Actually I was unable to determine which program accesses the terminal (attempts to strace
the entire script produced a 17MB file without tcsetattr
, so I assume the terminal modifications are just writes of control characters). The problem was also non-deterministic; it was sometimes interfering with the terminal and sometimes not.
Placing the following prelude in the script seemed to stop interference with the terminal doesn't fix the problem. However, it's not clear why it doesn't fix the problem: are processes still accessing the terminal through /dev/tty
, or are escape codes written by the programs still being dumped to the terminal by cat
.
MKTEMP="$(mktemp)"
mkfifo "$MKTEMP".fifo
(
set +o xtrace
cat "$MKTEMP".fifo
rm -f "$MKTEMP".fifo "$MKTEMP"
) </dev/null 2>&1 &
exec 1>"$MKTEMP".fifo
exec 2>&1
exec 0</dev/null
strace
orsysdig
to find out what is runningstty
or otherwise making relevant system calls (e.g.tcsetattr
)?/dev/tty
and do what it wants to do with it. Seeman 4 tty
. Use thrig's recommendation.man 4 tty
indicatesTIOCNOTTY
can be used to detach from the tty, after which open of/dev/tty
will fail. Is there a wrapper program that does this? It sounds like a good idea for non-ncurses batch scripts that shouldn't be doing strange things to the terminal.strace
, or read the script. And TIOCNOTTY applies to the procees which calls it, not to the shell. You can also try to enter blindly <Enter>reset
<Enter> after the script terminates. Or open another terminal and watch the processes. Seriously, use thrig's suggestion.