From owner-freebsd-stable Sun Jun 3 8:59: 6 2001 Delivered-To: freebsd-stable@freebsd.org Received: from segfault.kiev.ua (segfault.kiev.ua [193.193.193.4]) by hub.freebsd.org (Postfix) with ESMTP id C5C5C37B401 for ; Sun, 3 Jun 2001 08:59:00 -0700 (PDT) (envelope-from netch@iv.nn.kiev.ua) Received: (from uucp@localhost) by segfault.kiev.ua (8) with UUCP id SWP72773; Sun, 3 Jun 2001 18:58:42 +0300 (EEST) (envelope-from netch@iv.nn.kiev.ua) Received: (from netch@localhost) by iv.nn.kiev.ua (8.11.3/8.11.3) id f53FtAP01470; Sun, 3 Jun 2001 18:55:10 +0300 (EEST) (envelope-from netch) Date: Sun, 3 Jun 2001 18:55:09 +0300 From: Valentin Nechayev To: Gregory Bond Cc: stable@FreeBSD.ORG Subject: Re: Who's HUPing my daemon? Message-ID: <20010603185509.C891@iv.nn.kiev.ua> References: <200106010210.MAA26759@lightning.itga.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200106010210.MAA26759@lightning.itga.com.au>; from gnb@itga.com.au on Fri, Jun 01, 2001 at 12:10:35PM +1000 X-42: On Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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