[lxc-devel] [PATCH 1/5] start child in its own process group, and put it into the foreground

Greg Kurz gkurz at fr.ibm.com
Fri Jun 11 13:24:08 UTC 2010


On Thu, 2010-06-10 at 21:53 +0200, Daniel Lezcano wrote:
> > +     if (setpgid(handler->pid, 0)) {
> > +             SYSERROR("failed to create new process group");
> > +             goto out_delete_net;
> > +     }
> > +     DEBUG("created new process group %d", handler->pid);
> > +     ctty = open("/dev/tty", O_RDONLY);
> > +     if (ctty != -1) {
> > +             int ret = tcsetpgrp(ctty, handler->pid);
> > +             close(ctty);
> > +             if (ret) {
> > +                     SYSERROR("failed to set terminal foreground
> process group");
> > +                     goto out_delete_net;
> > +             }
> > +             DEBUG("set terminal foreground process group");
> > +     }
> >    
> 
> Is there a particular reason to do that from the parent and not from
> the 
> child ?
> 

Yes, because otherwise the new process group creation would be racy from
the parent POV. It's important because there's a window between the call
to setpgid() and the call to tcsetpgrp() where the child won't receive
tty signals, for example: it's up to the parent to forward signals to
the new process group in this case.
Usually, both the parent and the child call setpgid() to ensure they
have a consistent view, without the need to be synchronized.

-- 
Gregory Kurz                                     gkurz at fr.ibm.com
Software Engineer @ IBM/Meiosys                  http://www.ibm.com
Tel +33 (0)534 638 479                           Fax +33 (0)561 400 420

"Anarchy is about taking complete responsibility for yourself."
        Alan Moore.





More information about the lxc-devel mailing list