[Toybox] [PATCH] setsid: document -w.

enh enh at google.com
Fri Jan 10 22:06:06 PST 2020


On Fri, Jan 10, 2020 at 9:41 PM Rob Landley <rob at landley.net> wrote:
>
> On 1/10/20 6:17 PM, enh via Toybox wrote:
> > -w was added recently. The change in behavior so we now always fork
> > means that it's needed in more cases too: other implementations of
> > setsid(1) only fork if getpgrp() != getpid(). This broke a script, which
> > is what made me notice the missing help.
>
> I can change how it works? But I thought the point is it wanted a _new_ session
> leader. (You'd have to exec setsid in order to inherit the previous session
> leader, is this a common thing to do? Otherwise you get a new pid...)

http://man7.org/linux/man-pages/man1/setsid.1.html says:

       The command calls fork(2) if
       already a process group leader.  Otherwise, it executes a program in
       the current process.  This default behavior is possible to override
       by the --fork option.

and strace concurs.

> > This seems to have been an accidental change, and is contrary to what
> > the util-linux setsid(1) man page says: "The command calls fork(2) if
> > already a process group leader.  Otherwise, it executes a program
> > in the current process", but whether we change our behavior or not, we
> > should document the new option.
>
> My logic was "you just ran a new command, it has a new pid, that's the common
> case". If "exec setsid" is the common case, I can add another test? (Does mksh
> setsid() children after fork() by default?)

this wasn't mksh because it wasn't on the device --- this was actually
bash on the host.

basically they called `setsid ...` and then did a shell `wait`, which
only works if there's no fork.

> Sorry, I'm unclear on what "success" looks like here with some of the stranger
> inputs.

yeah, i think -w is what they really wanted here (and we're going to
change the script to explicitly use -w), but at least one script
(three identical copies thereof :-/) was relying on the util-linux
semantics.

> Rob
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net



More information about the Toybox mailing list