tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: rc.d and non daemon servers

On Wed, Mar 04, 2009 at 02:03:13PM -0600, David Young wrote:
> > 
> > nohup isn't enough, the process also needs to lose its controlling
> > terminal.
> Is this sufficient?
> program < /dev/null > /dev/null 2>&1 &

Nothing like it!
The code needs to call:
    if (fork()) _exit(); /* Ensure we aren't a process group/session leader */
    setsid();            /* Lose any existing controlling terminal */
    if (fork()) _exit(); /* Stop ourselves picking up a ctty */

The above is especially important on SYSV - which doesn't have revoke()
and remembers the ctty by major/minor - and won't let you access the
device that was your ctty if you just ignore SIGHUP.
So you can write to every terminal EXECEPT the one used to start the program!
Worse, given that your ctty can be a network clone device, you can
get the same major/minor back later ...


David Laight:

Home | Main Index | Thread Index | Old Index