From owner-freebsd-current@FreeBSD.ORG Wed May 23 16:43:59 2007 Return-Path: X-Original-To: current@FreeBSD.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7CAF816A400; Wed, 23 May 2007 16:43:59 +0000 (UTC) (envelope-from marcus@FreeBSD.org) Received: from creme-brulee.marcuscom.com (creme-brulee.marcuscom.com [24.172.16.118]) by mx1.freebsd.org (Postfix) with ESMTP id 1569C13C457; Wed, 23 May 2007 16:43:58 +0000 (UTC) (envelope-from marcus@FreeBSD.org) Received: from [IPv6:2001:470:1f00:2464::4] (shumai.marcuscom.com [IPv6:2001:470:1f00:2464::4]) by creme-brulee.marcuscom.com (8.14.1/8.14.1) with ESMTP id l4NGTtSN058290; Wed, 23 May 2007 12:29:55 -0400 (EDT) (envelope-from marcus@FreeBSD.org) From: Joe Marcus Clarke To: Dag-Erling =?ISO-8859-1?Q?Sm=F8rgrav?= In-Reply-To: <867ir0atfh.fsf@dwp.des.no> References: <46534301.10005@FreeBSD.org> <864pm4zkre.fsf@dwp.des.no> <46534EE2.3090107@FreeBSD.org> <867ir0atfh.fsf@dwp.des.no> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-2Rf1Lyd9u+PMxUZMWvc6" Organization: FreeBSD, Inc. Date: Wed, 23 May 2007 12:29:35 -0400 Message-Id: <1179937775.53308.6.camel@shumai.marcuscom.com> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 FreeBSD GNOME Team Port X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,NO_RELAYS autolearn=ham version=3.1.8 X-Spam-Checker-Version: SpamAssassin 3.1.8 (2007-02-13) on creme-brulee.marcuscom.com Cc: pjd@FreeBSD.org, "current@freebsd.org" Subject: Re: [Fwd: Serious problem with mount(8)] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 May 2007 16:43:59 -0000 --=-2Rf1Lyd9u+PMxUZMWvc6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Wed, 2007-05-23 at 09:30 +0200, Dag-Erling Sm=F8rgrav wrote: > Joe Marcus Clarke writes: > > Dag-Erling Sm=F8rgrav writes: > > > Better yet, extend the pidfile API with a function which reads the > > > contents of a PID file and also checks whether it's locked. > > I'd be happy to do this. Is my approach with this code sound (i.e. can > > I simply port this to pidfile(3)), or should I take another approach? > > Thanks. >=20 > You expose yourself to all sorts of race conditions by opening the file > twice... what you should do is something like (off the top of my head): >=20 > fd =3D open(pidfile, O_RDONLY); > fcntl(fd, F_GETLK, &fl) > if (fl.l_type =3D=3D F_UNLCK) > return (-1) > fstat(fd, &fsb); > read(fd, buf, fsb.st_len); > if (atoi(buf) !=3D fl.l_pid) > return (-1); > #ifdef OPTIONAL > stat(pidfile, &sb); > if (sb.st_dev !=3D fsb.st_dev || sb.st_ino !=3D fsb.st_ino) > return (-1); > #endif > return (fl.l_pid); >=20 > with appropriate error checking, of course. Thanks for the tip, but this is moot now that flopen(3) has been fixed, and pidfile_open(3) operates as documented. Joe --=20 Joe Marcus Clarke FreeBSD GNOME Team :: gnome@FreeBSD.org FreeNode / #freebsd-gnome http://www.FreeBSD.org/gnome --=-2Rf1Lyd9u+PMxUZMWvc6 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQBGVGvtb2iPiv4Uz4cRAh0yAKCwPo+37bGZBAMAlZ4jb8/MMbMBxACggk/m YVXvlI5YqjFXkuItF+leNKA= =SFK9 -----END PGP SIGNATURE----- --=-2Rf1Lyd9u+PMxUZMWvc6--