Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Aug 2005 10:07:54 +0200
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        Hajimu UMEMOTO <ume@FreeBSD.org>
Cc:        FreeBSD-arch <freebsd-arch@FreeBSD.org>
Subject:   Re: New library: libpidfile.
Message-ID:  <20050823080754.GA47261@garage.freebsd.pl>
In-Reply-To: <ygek6id48nn.wl%ume@mahoroba.org>
References:  <20050822213028.GB4812@garage.freebsd.pl> <ygek6id48nn.wl%ume@mahoroba.org>

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

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

On Tue, Aug 23, 2005 at 12:46:52PM +0900, Hajimu UMEMOTO wrote:
+> Hi,
+>=20
+> >>>>> On Mon, 22 Aug 2005 23:30:28 +0200
+> >>>>> Pawel Jakub Dawidek <pjd@FreeBSD.org> said:
+>=20
+> pjd> I'd like to commit a small library for handling "pidfiles".
+>=20
+> NetBSD and OpenBSD has similar functions already in libutil.  I think
+> we alone have a different API is bad idea.  So, it is good to bring
+> them into FreeBSD from NetBSD or OpenBSD, IMHO.

I assume you're talking about NetBSD's pidlock(3).

This is exactly an example of a bad way of doing it, as I understand the
code.

It doesn't use flock(2), instead, it reads PID from the file and checks
if process with this PID is alive. *SOME* process, not necessarily already
running instance of the daemon, but some process which has the same PID.
This is most important in case of pkill(1), when we don't want to kill
some random process.

This of course is also racy - daamon could be started between checking
is process is alive and renaming (lock|pid)file.

It only provides one function which writes the PID of the current process
into the file. With libpidfile(3), you can open the pidfile before
fork()ing, so daemon can report if another copy is already running before
going into the background.

In general NetBSD's pidlock(3) isn't a complete solution (there is no
function to remove just remove pidfile on exit, etc.

In OpenBSD pidfile(3) exists, but it is even worser. It doesn't even check
if daemon is already running...
It also doesn't support any pidfile name, you may specify only 'basename'
and it creates pidfile in a form "/var/run/<basename>.pid", so it won't
work if most of our daemon where you can specify alternate pidfile location.

Anyway. There is no one API they share and none of them is a sufficient
solution.

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

--7JfCtLOvnd9MIVvH
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iD8DBQFDCtlaForvXbEpPzQRAv+9AJ47qctXXJ5wuri2kjOhntJk+o3eAwCg5N7u
MImy9zs00ROvV7ALDHWjl6c=
=YdgF
-----END PGP SIGNATURE-----

--7JfCtLOvnd9MIVvH--



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