Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Jun 2001 18:55:09 +0300
From:      Valentin Nechayev <netch@iv.nn.kiev.ua>
To:        Gregory Bond <gnb@itga.com.au>
Cc:        stable@FreeBSD.ORG
Subject:   Re: Who's HUPing my daemon?
Message-ID:  <20010603185509.C891@iv.nn.kiev.ua>
In-Reply-To: <200106010210.MAA26759@lightning.itga.com.au>; from gnb@itga.com.au on Fri, Jun 01, 2001 at 12:10:35PM %2B1000
References:  <200106010210.MAA26759@lightning.itga.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
 Fri, Jun 01, 2001 at 12:10:35, gnb (Gregory Bond) wrote about "Who's HUPing my daemon?": 

Proper daemonization consists of many steps, some of them are:

1) chdir("/"), to prevent staying on file system which must be unmounted.
(But let's consider changing sysctl kern.corefile to absolute path.)
2) Close all unneeded file handles, including 0,1,2, and reopen
/dev/null or log files on them.
3) Setup own session with setsid(). This is exact what you need now.

Of course, daemon() will do the same in one call of itself, but it is
unportable.

> I'm trying to get a daemon running at boot time from rc.d.  When the system
> boots, the script is run, the daemon is started, and all is fine. Then a few
> seconds later, (possibly at the same time that rc finishes and getty is
> launched), the daemon gets a SIGHUP and cleans itself up and exits.  Running
> the start script by hand after logging in works and the daemon stays active 
> more or less forever as you expect.
> Some hackery with ktrace shows that it is a SIGHUP that is killing it, and it 
> is waiting in select() at the time (which is the expected state).
> 
> The relevent code in main() is like this:
>         if(makedaemon && fork())
>                 exit(0);
> 
>         openlog("bpalogin",LOG_PID,LOG_DAEMON);
> 
> I'm suspicious that just a plain fork() is not enough to disconnect from the 
> boot sequence but I can't work out what's causing the HUP.  Suggestions?
> 
> (I suspect replacing the code with
> 	if (makedaemon) daemon(0,0); 
> will fix it...  bloody Linux hackers, no respect for real Unix!)


/netch

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010603185509.C891>