Re: New library: libpidfile.
From: Pawel Jakub Dawidek (pjd_at_FreeBSD.org)
Date: 08/23/05
- Previous message: Peter Jeremy: "Re: [CFR] reflect resolv.conf update to running application"
- In reply to: Hajimu UMEMOTO: "Re: New library: libpidfile."
- Next in thread: John-Mark Gurney: "Re: New library: libpidfile."
- Reply: John-Mark Gurney: "Re: New library: libpidfile."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 23 Aug 2005 10:07:54 +0200 To: Hajimu UMEMOTO <ume@FreeBSD.org>
On Tue, Aug 23, 2005 at 12:46:52PM +0900, Hajimu UMEMOTO wrote:
+> Hi,
+>
+> >>>>> On Mon, 22 Aug 2005 23:30:28 +0200
+> >>>>> Pawel Jakub Dawidek <pjd@FreeBSD.org> said:
+>
+> pjd> I'd like to commit a small library for handling "pidfiles".
+>
+> 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.
-- Pawel Jakub Dawidek http://www.wheel.pl pjd@FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am!
- application/pgp-signature attachment: stored
- Previous message: Peter Jeremy: "Re: [CFR] reflect resolv.conf update to running application"
- In reply to: Hajimu UMEMOTO: "Re: New library: libpidfile."
- Next in thread: John-Mark Gurney: "Re: New library: libpidfile."
- Reply: John-Mark Gurney: "Re: New library: libpidfile."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
- Re: New library: libpidfile.
... > running instance of the daemon, but some process which has the same PID.
... > function to remove just remove pidfile on exit, ... print out an error
message saying that another daemon is already ... (freebsd-arch) - Re: correct pid file handling
... > say you have a daemon which creates a pidfile. ... check pid
file size is 0 bytes, if not - fail to start with an error ... If you have multiple instances
of your daemons running concurrently as ... (comp.unix.programmer) - Re: pidfile_check() possible function
... +> I've just had a situation, where I want to know the pid of the already running
daemon, but i don't want to create the pidfile in case if there is no daemon running. ...
(freebsd-current) - Re: correct pid file handling
... > daemon to behave under different circumstances, how its pidfile
should be ... then i have the issue of whether a give pid is still bound the the process
... (comp.unix.programmer) - pidfile_check() possible function
... I've just had a situation, where I want to know the pid of the already running daemon,
but i don't want to create the pidfile in case if there is no daemon running. ... (freebsd-current)