Date: Wed, 23 May 2007 12:29:35 -0400 From: Joe Marcus Clarke <marcus@FreeBSD.org> To: Dag-Erling =?ISO-8859-1?Q?Sm=F8rgrav?= <des@des.no> Cc: pjd@FreeBSD.org, "current@freebsd.org" <current@FreeBSD.org> Subject: Re: [Fwd: Serious problem with mount(8)] Message-ID: <1179937775.53308.6.camel@shumai.marcuscom.com> 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>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --] On Wed, 2007-05-23 at 09:30 +0200, Dag-Erling Smørgrav wrote: > Joe Marcus Clarke <marcus@FreeBSD.org> writes: > > Dag-Erling Smørgrav <des@des.no> 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. > > 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): > > fd = open(pidfile, O_RDONLY); > fcntl(fd, F_GETLK, &fl) > if (fl.l_type == F_UNLCK) > return (-1) > fstat(fd, &fsb); > read(fd, buf, fsb.st_len); > if (atoi(buf) != fl.l_pid) > return (-1); > #ifdef OPTIONAL > stat(pidfile, &sb); > if (sb.st_dev != fsb.st_dev || sb.st_ino != fsb.st_ino) > return (-1); > #endif > return (fl.l_pid); > > 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 -- Joe Marcus Clarke FreeBSD GNOME Team :: gnome@FreeBSD.org FreeNode / #freebsd-gnome http://www.FreeBSD.org/gnome [-- Attachment #2 --] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQBGVGvtb2iPiv4Uz4cRAh0yAKCwPo+37bGZBAMAlZ4jb8/MMbMBxACggk/m YVXvlI5YqjFXkuItF+leNKA= =SFK9 -----END PGP SIGNATURE-----home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1179937775.53308.6.camel>
