Re: New library: libpidfile.

From: Pawel Jakub Dawidek (pjd_at_FreeBSD.org)
Date: 08/23/05

  • Next message: Pawel Jakub Dawidek: "Re: New library: libpidfile."
    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!
    
    



  • Next message: Pawel Jakub Dawidek: "Re: New library: libpidfile."

    Relevant Pages