All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steffen Nurpmeso <steffen@sdaoden.eu>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: dash@vger.kernel.org,
	Ganael Laplanche <ganael.laplanche@martymac.org>,
	Jilles Tjoelker <jilles@stack.nl>
Subject: Re: [PATCH] Allow enabling job control without a tty in non-interactive mode..
Date: Sun, 07 Apr 2024 01:07:04 +0200	[thread overview]
Message-ID: <20240406230704.Tr-SBJb2@steffen%sdaoden.eu> (raw)
In-Reply-To: <ZhD4JcqNct+rmxca@gondor.apana.org.au>

Herbert Xu wrote in
 <ZhD4JcqNct+rmxca@gondor.apana.org.au>:
 |On Mon, Jan 30, 2023 at 10:15:40PM +0100, Steffen Nurpmeso wrote:
 |> This is a take-over of the FreeBSD bin/sh
 |> 
 |>   commit cd60e2c67d52e1f957841af19128c7227880743a
 |>   Author:     Jilles Tjoelker <jilles@FreeBSD.org>
 |>   AuthorDate: 2014-09-04 21:48:33 +0000
 |>   Commit:     Jilles Tjoelker <jilles@FreeBSD.org>
 |>   CommitDate: 2014-09-04 21:48:33 +0000
 |> 
 |>       sh: Allow enabling job control without a tty in non-interactive \
 |>       mode.
 |> 
 |>       If no tty is available, 'set -m' is still useful to put jobs \
 |>       in their own
 |>       process groups.
 |
 |I don't see why dash needs this.  Please keep in mind that one
 |of the primary goals of dash it to be minimal.

Isn't that standardized answer a bit misplaced for that patch?
It was about Ganael Laplanche having problems with creating
process groups in backgrounded jobs (2023-01-12):

  The problem is when the main script is started *in the
  background*. Can your test script successfully be run in the
  background with dash if $JOBMON is not empty ? I think you'll
  face the same problem as I do.

  I could not find Jilles' commit (cd60e2c) equivalent in dash
  code, so I presume enabling job control without a tty in
  non-interactive mode is just not possible with dash, am I right

And i stated that another indirection fixes that problem and he
then said

  It is not clear for me why that extra fork fixes the problem,
  but it works, thanks!

  Unfortunately, my initial goal is to get a new process group for
  later children processes, but FreeBSD's sh (as well as dash)
  requires 'set -m' to be executed from the first process [1]. The
  extra fork breaks that requirement.  The following example shows
  that the new process' PGID remains the same as the initial
  shell:

which let me baffled

  Thanks for this information, that i did not expect.
  Indeed .. it seems no new process group is used for the child
  shell.  That thoroughly i have not looked.

and

  So i think i am out of ideas except doing what Jilles suggested
[Tjoelker]
  in the message, enwrapping the inner thing with sh -c '..'.  And
  that seems to work a bit as

and Ganael ended (without the patch) like

  Yes, I am afraid it's the only syntax that works (but it is not
  very convenient).

etc. etc. etc.

Full stop.

Please consider this script:

  cat > t.sh <<'_EOT'
  set -m
  (
  sleep 1
  ) &
  i=$!
  set +m
  echo >&2 "inner Main shell has: $(ps -o pid,pgid $$)"
  echo >&2 "inner Sub-shell has: $(ps -o pid,pgid $i)"
  wait $i
  _EOT

Current dash:

  #?0|kent:dash.git$ dash t.sh </dev/null >.X 2>&1 &
  [3] 28719
  #?0|kent:dash.git$
^RETURN

  [3]+  Stopped                 dash t.sh < /dev/null > .X 2>&1
  #?0|kent:dash.git$ fg
  dash t.sh < /dev/null > .X 2>&1

Patched dash:

  #?0|kent:dash.git$ src/dash t.sh </dev/null >.X 2>&1 &
  [3] 28749
  #?0|kent:dash.git$
^RETURN
  [3]   Done                    src/dash t.sh < /dev/null > .X 2>&1

Comparison:

  #?0|kent:dash.git$ bash t.sh </dev/null >.X 2>&1 &
  [3] 28766
  #?0|kent:dash.git$
^RETURN
  [3]   Done                    bash t.sh < /dev/null > .X 2>&1

A nice Sunday everybody!
Ciao from Germany,

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)

  reply	other threads:[~2024-04-06 23:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-30 21:15 [PATCH] Allow enabling job control without a tty in non-interactive mode Steffen Nurpmeso
2024-04-06  7:22 ` Herbert Xu
2024-04-06 23:07   ` Steffen Nurpmeso [this message]
2024-04-07  5:21     ` Herbert Xu
2024-04-07  9:04 ` [v2 PATCH] jobs: Allow monitor mode " Herbert Xu
2024-04-08 22:54   ` Steffen Nurpmeso
2024-04-09 10:11     ` 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=20240406230704.Tr-SBJb2@steffen%sdaoden.eu \
    --to=steffen@sdaoden.eu \
    --cc=dash@vger.kernel.org \
    --cc=ganael.laplanche@martymac.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=jilles@stack.nl \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.