Hi,
on current RHEL9 and Fedora40, and also on s-nail git master, I ran
into an issue that halts a backgrounded script connected to a tty.
as an example on RHEL9 ->
$ ( echo blah | Mail root ) &
[1] 2754649
$ ^M^M^M^M^C^C
[1]+ Stopped ( echo blah | Mail root )
$ fg
( echo blah | Mail root )
$
the mail is sent, but the calling script (just a subshell in this case)
is Stopped. the calling tty is confused and shows control characters.
^C is needed to get back to the shell.
I dug a bit deeper and it seems s-nail mistakenly tries to set
terminal options in this use-case?
I gather that tcsetattr causes the backgrounded script to get sent
SIGTTOU and the entire script (not just s-nail) goes to Stopped state.
mail gets sent, but the calling script is halted.
scripts launched via cron and systemd work fine, presumably because
those scripts are detached from a tty.
I've narrowed the problem down to the below part of git master, but I
don't know enough about s-nail (or signals, ttys, ...) to fix it.
diff --git a/src/mx/child.c b/src/mx/child.c
index ccdbf09a..f868319a 100644
--- a/src/mx/child.c
+++ b/src/mx/child.c
@@ -377,6 +377,7 @@ mx_child_fork(struct mx_child_ctx *ccp){
/* If this child takes the terminal, adjust termios now, but do not yet
* install our handler */
+// here
if(cep->ce_tios)
mx_termios_cmdx(mx_TERMIOS_CMD_PUSH | mx_TERMIOS_CMD_HANDS_OFF);
diff --git a/src/mx/termios.c b/src/mx/termios.c
index 733974eb..5d870a31 100644
--- a/src/mx/termios.c
+++ b/src/mx/termios.c
@@ -559,6 +559,7 @@ mx_termios_cmd(u32 tiosc, uz a1){
}
/* FALLTHRU */
case mx_TERMIOS_CMD_NORMAL:
+ // here
rv = (tcsetattr(fileno(mx_tty_fp), TCSADRAIN, &tiosep->tiose_state
) == 0);
break;
where the PUSH mode allows the FALLTHRU to a tcsetattr.
can you please help?
is there an internal mode that describes this style of usage of s-nail?
if so, maybe that could be used to avoid all tcsetattr entirely?
cheers,
robin