From owner-freebsd-rc@FreeBSD.ORG Tue Feb 14 02:26:16 2006 Return-Path: X-Original-To: freebsd-rc@freebsd.org Delivered-To: freebsd-rc@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BCA5616A420 for ; Tue, 14 Feb 2006 02:26:16 +0000 (GMT) (envelope-from jofsama@yahoo.com) Received: from smtp004.mail.ukl.yahoo.com (smtp004.mail.ukl.yahoo.com [217.12.11.35]) by mx1.FreeBSD.org (Postfix) with SMTP id 01CCA43D45 for ; Tue, 14 Feb 2006 02:26:15 +0000 (GMT) (envelope-from jofsama@yahoo.com) Received: (qmail 63066 invoked from network); 14 Feb 2006 02:26:14 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:Message-ID:Date:From:User-Agent:X-Accept-Language:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=qkIv+LRZf5Pe+9OC6GmRVsGOZFUCNomgD0a/rW1ZRLJT3ZPcVRmq7uUzz+nENz5MsJQcb6nqyOEwZJ2ZzxFv5dPGQ+qL1cFhcnaFVUCBSd/xc09JzaS8pTswSPBKUvei6XPeq8FdBYWMg3pUB0+xcAcC8wU9iybFWwrkujATjFQ= ; Received: from unknown (HELO ?192.168.11.3?) (jofsama@220.99.4.57 with plain) by smtp004.mail.ukl.yahoo.com with SMTP; 14 Feb 2006 02:26:14 -0000 Message-ID: <43F1401F.30102@yahoo.com> Date: Tue, 14 Feb 2006 11:27:43 +0900 From: Jarrod User-Agent: Mozilla Thunderbird 1.0.7 (X11/20060107) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Yar Tikhiy References: <43EAFDB9.9040106@yahoo.com> <20060210085607.GF66940@comp.chem.msu.su> In-Reply-To: <20060210085607.GF66940@comp.chem.msu.su> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-rc@freebsd.org Subject: Re: EKPD daemon in /usr/local/etc/rc.d getting killed before login X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Feb 2006 02:26:17 -0000 Hi Yar, Thanks a lot for you comments. I've inserted some responses below. Yar Tikhiy wrote: >On Thu, Feb 09, 2006 at 05:30:49PM +0900, Jarrod wrote: > > >>Looking around at some of the system daemons I ended up taking a leaf >>out of lpd.c and changing the daemon's startup code from doing a regular >>"fork()" to doing a "daemon(0, 0)" call instead. >> >>At this stage it looks like the problem is solved. >> >>My question is: Is there some documentation or warning somewhere which >>would have aided me in resolving this problem? >> >> > >Perhaps the ekpd daemon hits some configuration/communication problems >and chooses to terminate? Most daemons can log their activity, so you >may want to investigate if it is possible by means of a configuration >file or command-line arguments to tell ekpd to log its actions to a file >or to a syslog facility. In the latter case (syslog) you'll need to >make sure that the facility used really gets logged to a file -- see >syslog(8) and syslog.conf(5). > > The code for the ekpd daemon does not appear to do much in the way of logging. I put a liberal amount of trace statements in using the syslog command to try and determine where and why it was shutting down, but without much success. >>I read all the material I could find on the rc.d system and but I didn't >>see anything that suggested just doing a regular fork() would get you in >>trouble. I assume the problem has something to do with why the >>"daemon()" function exists in the first place? >> >>Is there any possibility that there could be a check somewhere in the rc >>system or ports system to prevent programs that don't call "daemon()" to >>initialize from being installed in rc.d? >> >> > >This is hardly possible. The only case I can think of is when a >program forks into background and then tries to do terminal IO -- >it will receive a signal. The daemon() function closes standard >IO descriptors and thus prevents the program from doing any IO on >them later. If this is the case, ekpd will die if started manually >by running "/usr/local/etc/rc.d/ekpd start", too. > > Thanks for the help here. I went and had a look at the daemon() function itself: http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/gen/daemon.c in the CVS repository. It seems to do three main things as far as I can tell: 1. Catches a signal that (possibly?) gets thrown when the parent exits. 2. Calls the setsid() function. 3. Closes the stdio file descriptors. Since I couldn't see the EKPD daemon doing much IO I decided to play around with the setsid() function. I let EKPD do the usual fork() (taking out my daemon() call) and then did a setsid() straight after. Voila! This seems to work. The daemon no longer bails at the end of startup. I'm not much of an expert on UNIX processes, but is it possible that when the parent shell process running all the scripts in rc.d/ finishes, any child processes that haven't detached, using setsid() or similar, are killed off? From a useability perspective is it worth raising a PR? I just wonder if it might not be nice to have a warning printed up somewhere when you installed a script into the rc.d directory to save newbies (like me) getting unnecessarily frustrated! :) Cheers, Jarrod.