[PATCH] ash: setsid and TIOCSCTTY when enabling job control.

Denys Vlasenko vda.linux at googlemail.com
Tue Mar 13 03:23:02 UTC 2012


On Tuesday 13 March 2012 01:18, Avery Pennarun wrote:
> On Mon, Mar 12, 2012 at 8:09 PM, Michael Conrad <mconrad at intellitree.com> wrote:
> > Would this have an effect on scripts being used as init which did not
> > previously have a controlling terminal?  There are quite a few commands
> > which change behavior when run with/without a tty.
> >
> > (the usual fix for enabling job control is to run agetty in your init
> > script)
> 
> It should be fine.  TIOCSCTTY only works if you're the session leader,
> which is the result of setsid().  And setsid() only works if there is
> not already a session leader for this terminal.

No. setsid() only works if your PID isn't a process group ID.
It does not depend on who is session leader and which session
has which terminal.

> Together, this means 
> neither call will do anything if there's already a controlling
> terminal.

I think you are wrong. setsid() in many cases will work, and
will do an unexpected thing (create a session no one asked for).

-- 
vda


More information about the busybox mailing list