stty sane causes problems in certain non-interactive or non-shell uses
If you use termux sudo in another script AND from an incoming non-login ssh, then the stty sane command at the end of termux sudo will generate an error message and an error exit code, as follows
stty: standard input: Not a typewriter
My particular case involved having a local script that calls rsync with sudo. Specifically the local script looks like this (from /data/data/com.termux/files/usr/bin/rsync-with-sudo.sh):
#! /data/data/com.termux/files/usr/bin/bash /data/data/com.termux/files/usr/bin/sudo /data/data/com.termux/files/usr/bin/rsync "$@"
From my remote machine, I am running something like
rsync --rsh=ssh --rsync-path=/data/data/com.termux/files/usr/bin/rsync-with-sudo.sh morearguments.........
In termux, ssh starts the rsync-with-sudo.sh script and while the rsync will finish there is always an error exit due to the "stty sane" thing.
Not sure what is the best fix, maybe an option not to run stty sane? Or is there a way to check whether the parent process of a script is an interactive shell with a tty attached?