Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Apr 2006 09:50:28 +0200
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        Colin Percival <cperciva@freebsd.org>
Cc:        John-Mark Gurney <jmg@FreeBSD.org>, cvs-src@FreeBSD.org, src-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/lib/libutil pidfile.c
Message-ID:  <20060412075028.GF7031@garage.freebsd.pl>
In-Reply-To: <443CACCD.2080208@freebsd.org>
References:  <200604112310.k3BNA2DL029129@repoman.freebsd.org> <20060412071124.GC7031@garage.freebsd.pl> <443CACCD.2080208@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--XStn23h1fwudRqtG
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Apr 12, 2006 at 12:31:25AM -0700, Colin Percival wrote:
+> Pawel Jakub Dawidek wrote:
+> > On Tue, Apr 11, 2006 at 11:10:02PM +0000, John-Mark Gurney wrote:
+> > +>   use pwrite to always write at the begining of the file..  If mult=
iple calls
+> > +>   to pidfile_write happen, the pidfile will have nul characters pre=
pended
+> > +>   due to the cached file descriptor offset...
+> >=20
+> > Multiple pidfile_write()s from the same process? If not, then we must
+> > truncate the file before writting the PID.
+>=20
+> We already do -- there's a call to ftruncate(fd, 0) a few lines earlier.

Right. Hmm, when I placed this ftruncate(2) there, I must thought that
it will reset the file position indicator...

+> > Imagine a situation, where PID 10000 is written first and then we
+> > overwrite it with 9999. The result will be 99990.
+>=20
+> The only way this can happen is if two different processes call
+> pidfile_write simultaneously and both ftruncate calls complete
+> before either pwrite call starts; I don't think this is really
+> worth worrying about.

That's not possible, because we lock the file.

I was more thinking about situation, like:
1. daemon()
2. pidfile_write()
3. SIGHUP
4. fork()/daemon()
5. pidfile_write()

--=20
Pawel Jakub Dawidek                       http://www.wheel.pl
pjd@FreeBSD.org                           http://www.FreeBSD.org
FreeBSD committer                         Am I Evil? Yes, I Am!

--XStn23h1fwudRqtG
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (FreeBSD)

iD8DBQFEPLFEForvXbEpPzQRAmLnAKDcX79o5KTB1iNnj/OhRgdTw1NFSACg4YsX
Rz/YvmCfltRPQxemm6eM3Xo=
=X4eV
-----END PGP SIGNATURE-----

--XStn23h1fwudRqtG--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060412075028.GF7031>