From le@univie.ac.at  Fri Jul  4 13:50:37 2003
Return-Path: <le@univie.ac.at>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 5F3DE37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  4 Jul 2003 13:50:37 -0700 (PDT)
Received: from mailbox.univie.ac.at (mailbox.univie.ac.at [131.130.1.27])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 01C1A43FAF
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  4 Jul 2003 13:50:36 -0700 (PDT)
	(envelope-from le@univie.ac.at)
Received: from korben.in.tern (adslle.cc.univie.ac.at [131.130.102.11])
	by mailbox.univie.ac.at (8.12.2/8.12.2) with ESMTP id h64KoLdS167670
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 4 Jul 2003 22:50:27 +0200
Received: from korben.in.tern (korben.in.tern [127.0.0.1])
	by korben.in.tern (8.12.9/8.12.9) with ESMTP id h64KoIRR001050
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 4 Jul 2003 22:50:19 +0200 (CEST)
	(envelope-from le@korben.in.tern)
Received: (from le@localhost)
	by korben.in.tern (8.12.9/8.12.9/Submit) id h64KoI9m001049;
	Fri, 4 Jul 2003 22:50:18 +0200 (CEST)
	(envelope-from le)
Message-Id: <200307042050.h64KoI9m001049@korben.in.tern>
Date: Fri, 4 Jul 2003 22:50:18 +0200 (CEST)
From: Lukas Ertl <l.ertl@univie.ac.at>
Reply-To: Lukas Ertl <l.ertl@univie.ac.at>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] devd(8) doesn't write correct pid into /var/run/devd.pid
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         54113
>Category:       bin
>Synopsis:       [PATCH] devd(8) doesn't write correct pid into /var/run/devd.pid
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 04 14:00:27 PDT 2003
>Closed-Date:    Fri Jul 18 23:18:57 MDT 2003
>Last-Modified:  Fri Jul 18 23:18:57 MDT 2003
>Originator:     Lukas Ertl
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
Vienna University Computer Center
>Environment:
System: FreeBSD korben 5.1-CURRENT FreeBSD 5.1-CURRENT #20: Fri Jul 4 18:38:33 CEST 2003 le@korben:/usr/obj/usr/src/sys/KORBEN i386


	
>Description:

devd(8) writes its pid into /var/run/devd.pid, but the pid there is 1 
lower than the actual pid of devd. This is because devd is started by
default without the -n switch, so it writes the pidfile before calling
daemon(8).

>How-To-Repeat:

# devd
# cat /var/run/devd.pid
720
# ps auxww | grep devd
root    721  0,0  0,2   772  532  ??  Is   10:22pm   0:00,00 devd

>Fix:

Simply write the pidfile again after calling daemon(3).

--- devd.diff begins here ---
Index: sbin/devd/devd.cc
===================================================================
RCS file: /usr/local/bsdcvs/src/sbin/devd/devd.cc,v
retrieving revision 1.14
diff -u -r1.14 devd.cc
--- sbin/devd/devd.cc	2 May 2003 17:38:08 -0000	1.14
+++ sbin/devd/devd.cc	4 Jul 2003 20:42:21 -0000
@@ -596,6 +596,7 @@
 				if (Dflag)
 					fprintf(stderr, "Calling daemon\n");
 				daemon(0, 0);
+				cfg.drop_pidfile();
 				once++;
 			}
 		}
--- devd.diff ends here ---


>Release-Note:
>Audit-Trail:

From: Ruslan Ermilov <ru@FreeBSD.org>
To: Lukas Ertl <l.ertl@univie.ac.at>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/54113: [PATCH] devd(8) doesn't write correct pid into /var/run/devd.pid
Date: Sat, 5 Jul 2003 00:22:05 +0300

 A better fix might be:
 
 %%%
 Index: devd.cc
 ===================================================================
 RCS file: /home/ncvs/src/sbin/devd/devd.cc,v
 retrieving revision 1.14
 diff -u -p -r1.14 devd.cc
 --- devd.cc	2 May 2003 17:38:08 -0000	1.14
 +++ devd.cc	4 Jul 2003 21:18:19 -0000
 @@ -596,6 +596,7 @@ event_loop(void)
  				if (Dflag)
  					fprintf(stderr, "Calling daemon\n");
  				daemon(0, 0);
 +				cfg.drop_pidfile();
  				once++;
  			}
  		}
 @@ -743,9 +744,10 @@ main(int argc, char **argv)
  	}
  
  	cfg.parse();
 -	if (!dflag && nflag)
 +	if (!dflag && nflag) {
  		daemon(0, 0);
 -	cfg.drop_pidfile();
 +		cfg.drop_pidfile();
 +	}
  	signal(SIGHUP, gensighand);
  	signal(SIGINT, gensighand);
  	signal(SIGTERM, gensighand);
 %%%
 
 -- 
 Ruslan Ermilov		Sysadmin and DBA,
 ru@sunbay.com		Sunbay Software Ltd,
 ru@FreeBSD.org		FreeBSD committer
Responsible-Changed-From-To: freebsd-bugs->imp 
Responsible-Changed-By: ru 
Responsible-Changed-When: Fri Jul 4 14:39:13 PDT 2003 
Responsible-Changed-Why:  
Over to an author of the code. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=54113 

From: Lukas Ertl <l.ertl@univie.ac.at>
To: Ruslan Ermilov <ru@FreeBSD.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/54113: [PATCH] devd(8) doesn't write correct pid into
 /var/run/devd.pid
Date: Fri, 4 Jul 2003 23:34:44 +0200 (CEST)

 On Sat, 5 Jul 2003, Ruslan Ermilov wrote:
 
 > A better fix might be:
 >
 > %%%
 > Index: devd.cc
 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 > RCS file: /home/ncvs/src/sbin/devd/devd.cc,v
 > retrieving revision 1.14
 > diff -u -p -r1.14 devd.cc
 > --- devd.cc=092 May 2003 17:38:08 -0000=091.14
 > +++ devd.cc=094 Jul 2003 21:18:19 -0000
 > @@ -596,6 +596,7 @@ event_loop(void)
 >  =09=09=09=09if (Dflag)
 >  =09=09=09=09=09fprintf(stderr, "Calling daemon\n");
 >  =09=09=09=09daemon(0, 0);
 > +=09=09=09=09cfg.drop_pidfile();
 >  =09=09=09=09once++;
 >  =09=09=09}
 >  =09=09}
 > @@ -743,9 +744,10 @@ main(int argc, char **argv)
 >  =09}
 >
 >  =09cfg.parse();
 > -=09if (!dflag && nflag)
 > +=09if (!dflag && nflag) {
 >  =09=09daemon(0, 0);
 > -=09cfg.drop_pidfile();
 > +=09=09cfg.drop_pidfile();
 > +=09}
 >  =09signal(SIGHUP, gensighand);
 >  =09signal(SIGINT, gensighand);
 >  =09signal(SIGTERM, gensighand);
 > %%%
 
 Yes, so the pidfile isn't written twice. Please commit :-)
 
 regards,
 le
 
 --=20
 Lukas Ertl                             eMail: l.ertl@univie.ac.at
 UNIX-Systemadministrator               Tel.:  (+43 1) 4277-14073
 Zentraler Informatikdienst (ZID)       Fax.:  (+43 1) 4277-9140
 der Universit=E4t Wien                   http://mailbox.univie.ac.at/~le/

From: Ruslan Ermilov <ru@FreeBSD.org>
To: "M. Warner Losh" <imp@bsdimp.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/54113: [PATCH] devd(8) doesn't write correct pid into /var/run/devd.pid
Date: Sat, 5 Jul 2003 03:00:47 +0300

 --F8dlzb82+Fcn6AgP
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Sat, Jul 05, 2003 at 08:16:20AM +0900, M. Warner Losh wrote:
 > This patch won't work.  the -d case never writes the pid file.  There
 > are minor issues with it, but I think I've fixed them and will commit
 > the fix soon.
 >=20
 Hm, usually /var/run/*.pid files are only created for daemons.
 At least natd(8) (which I know very well) behaves this way.
 
 
 Cheers,
 --=20
 Ruslan Ermilov		Sysadmin and DBA,
 ru@sunbay.com		Sunbay Software Ltd,
 ru@FreeBSD.org		FreeBSD committer
 
 --F8dlzb82+Fcn6AgP
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.2.1 (FreeBSD)
 
 iD8DBQE/BhUuUkv4P6juNwoRAkz+AJ42iiDB2B77UYIMkvTXh9gpoi/wfQCfRIfE
 1xi8IuHeB8oJfRum0rG9U+E=
 =MLS5
 -----END PGP SIGNATURE-----
 
 --F8dlzb82+Fcn6AgP--

From: Ruslan Ermilov <ru@FreeBSD.org>
To: "M. Warner Losh" <imp@bsdimp.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/54113: [PATCH] devd(8) doesn't write correct pid into /var/run/devd.pid
Date: Sat, 5 Jul 2003 03:07:39 +0300

 On Sat, Jul 05, 2003 at 03:00:46AM +0300, Ruslan Ermilov wrote:
 > On Sat, Jul 05, 2003 at 08:16:20AM +0900, M. Warner Losh wrote:
 > > This patch won't work.  the -d case never writes the pid file.  There
 > > are minor issues with it, but I think I've fixed them and will commit
 > > the fix soon.
 > > 
 > Hm, usually /var/run/*.pid files are only created for daemons.
 > At least natd(8) (which I know very well) behaves this way.
 > 
 moused(8) and inetd(8) also behave this way, and inetd(8) even
 has this documented in its manpages.  JFYI.
 
 
 Cheers,
 -- 
 Ruslan Ermilov		Sysadmin and DBA,
 ru@sunbay.com		Sunbay Software Ltd,
 ru@FreeBSD.org		FreeBSD committer

From: "M. Warner Losh" <imp@bsdimp.com>
To: ru@FreeBSD.org
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/54113: [PATCH] devd(8) doesn't write correct pid into
 /var/run/devd.pid
Date: Sat, 05 Jul 2003 10:00:08 +0900 (JST)

 In message: <20030705000046.GC44741@sunbay.com>
             Ruslan Ermilov <ru@FreeBSD.org> writes:
 : On Sat, Jul 05, 2003 at 08:16:20AM +0900, M. Warner Losh wrote:
 : > This patch won't work.  the -d case never writes the pid file.  There
 : > are minor issues with it, but I think I've fixed them and will commit
 : > the fix soon.
 : > 
 : Hm, usually /var/run/*.pid files are only created for daemons.
 : At least natd(8) (which I know very well) behaves this way.
 
 OK.  I'm convinced...
 
 Warner
State-Changed-From-To: open->closed 
State-Changed-By: imp 
State-Changed-When: Fri Jul 18 23:18:41 MDT 2003 
State-Changed-Why:  
fix commited a while ago. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=54113 
>Unformatted:
