From: Jilles Tjoelker <jilles@stack.nl>
To: Ganael Laplanche <ganael.laplanche@martymac.org>
Cc: dash@vger.kernel.org
Subject: Re: Monitor mode handling (bug ?)
Date: Tue, 10 Jan 2023 22:28:42 +0100 [thread overview]
Message-ID: <20230110212842.GA2103@stack.nl> (raw)
In-Reply-To: <7091680.J8PY2HnTC3@home.martymac.org>
On Mon, Jan 09, 2023 at 04:18:02PM +0100, Ganael Laplanche wrote:
> Digging into a problem with a project of mine [1], I found dash (0.5.12)
> behaves differently from other POSIX-compliant shells when dealing with
> monitor mode when running in the background.
> In the following example, dash immediately sends a SIGTTIN signal that stops
> the process group:
> $ cat test.sh
> set -m
> $ dash test.sh &
> [1] + suspended (tty input) dash test.sh
> while other shells do not:
> $ bash test.sh &
> [1] + done bash test.sh
> $ sh test.sh & # (/bin/sh from FreeBSD 13.1-RELEASE)
> [1] + done sh test.sh
> $ ksh93 test.sh &
> [1] + done ksh93 test.sh
> Is that an intended behaviour ?
The loop with SIGTTIN is the right thing for an interactive job control
shell. It ensures that two job control shells do not interfere. The idea
is that the user can later 'fg' from the outer job control shell.
The loop also helps with suspending a job control shell, for example via
the funcs/suspend function from the ash source (containing 'local -',
'set +m' and 'kill -TSTP 0'): when trying to resume the inner shell via
'bg' in the outer shell, it is this loop that makes the inner shell stop
itself.
However, for a non-interactive shell, monitor mode is most useful for
its effect of placing jobs in their own process groups. This does not
necessarily imply any tty manipulation.
To make this possible, feature was added to FreeBSD sh in
https://cgit.freebsd.org/src/commit/?id=cd60e2c67d52e1f957841af19128c7227880743a
This commit allows using job control without a tty in non-interactive
mode. Where an interactive shell disables job control with the message
can't access tty; job control turned off
or stops itself because it is not in the foreground, a non-interactive
shell instead leaves a limited form of job control enabled that only
sets process group IDs on new processes and does not alter the
terminal's foreground process group ID.
> Also, the following test leads to dash looping indefinitely and eating 100%
> CPU:
> $ cat test2.sh
> trap '' 21
> set -m
> $ dash test2.sh &
> It remains stuck within the following loop:
> https://git.kernel.org/pub/scm/utils/dash/dash.git/tree/src/jobs.c?
> h=v0.5.12#n208
> Weird... Is that a dash bug or am I missing something?
Manipulating the disposition of TTIN/TTOU/TSTP with job control enabled
might be a question of "if it hurts, don't do that".
--
Jilles Tjoelker
next prev parent reply other threads:[~2023-01-10 21:28 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-09 15:18 Monitor mode handling (bug ?) Ganael Laplanche
2023-01-10 21:28 ` Jilles Tjoelker [this message]
2023-01-11 16:25 ` Ganael Laplanche
2023-01-11 16:37 ` Ganael Laplanche
2023-01-11 17:31 ` Steffen Nurpmeso
2023-01-12 11:40 ` Ganael Laplanche
2023-01-12 15:00 ` Steffen Nurpmeso
2023-01-13 11:44 ` Ganael Laplanche
2023-01-13 21:03 ` Steffen Nurpmeso
2023-01-16 11:15 ` Ganael Laplanche
2023-01-16 19:41 ` Steffen Nurpmeso
2023-01-17 15:05 ` Ganael Laplanche
2023-01-17 21:04 ` Steffen Nurpmeso
2023-01-18 11:40 ` Ganael Laplanche
2023-01-18 12:03 ` Ganael Laplanche
2023-01-18 23:15 ` Steffen Nurpmeso
2023-01-19 11:38 ` Ganael Laplanche
2023-01-19 18:33 ` Steffen Nurpmeso
2023-01-20 11:40 ` Ganael Laplanche
2023-01-27 10:21 ` Herbert Xu
2023-01-27 11:46 ` Ganael Laplanche
2023-01-30 7:21 ` Herbert Xu
2023-01-30 11:37 ` Ganael Laplanche
2023-01-31 3:20 ` Herbert Xu
2023-01-31 11:46 ` Ganael Laplanche
2023-03-08 11:47 ` Ganael Laplanche
2023-03-08 17:00 ` Steffen Nurpmeso
2023-03-09 5:55 ` Herbert Xu
2023-03-09 6:40 ` Ganael Laplanche
2023-03-09 9:22 ` Herbert Xu
2023-03-09 9:55 ` Herbert Xu
2023-03-09 11:34 ` Ganael Laplanche
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230110212842.GA2103@stack.nl \
--to=jilles@stack.nl \
--cc=dash@vger.kernel.org \
--cc=ganael.laplanche@martymac.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox