Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Jun 2002 21:48:04 -0500
From:      "Matthew D. Fuller" <fullermd@over-yonder.net>
To:        "Geoffrey C. Speicher" <geoff@sea-incorporated.com>
Cc:        freebsd-stable@freebsd.org, Matt Simerson <freebsd@blockads.com>, Paul Herman <pherman@frenchfries.net>
Subject:   Re: bug in pw, -STABLE [patch]
Message-ID:  <20020623024804.GB95458@over-yonder.net>
In-Reply-To: <20020622180011.V80651-100000@sea-incorporated.com>
References:  <20020622071722.GA57065@over-yonder.net> <20020622180011.V80651-100000@sea-incorporated.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Jun 22, 2002 at 08:17:54PM -0400 I heard the voice of
Geoffrey C. Speicher, and lo! it spake thus:
> 
> I think that B1 is already taken care of by init(8) and other
> solutions.  That leaves A1 and A2 (or B2 if you prefer), and what
> I'm thinking is that it should probably just be implemented as a
> library whose API consists of two functions that look something
> like this:

Hrm.
I looked at this, and there was something that I couldn't make work
(mentally, that is) with library functions that I could with a daemon,
but I've totally lost it.  OK, let's see...


> SYNOPSIS
>     int
>     pid_begin(const char* path, int flags=0);
> 
>     int
>     pid_end(const char* path);

Good, good...  libutil, you think?


>     pid_begin() will check for existence of the pid file named
>     _path_, and if it exists, determine whether the process whose
>     pid is contained therein is still running.
> 
>     If the file does not exist, or the contained pid is no
>     longer valid, then pid_begin() will create the file, write
>     the current pid, and return 0 (success).

Now, this is a problem.  There's a race condition here.  It's a very
small window, to be sure, but I'm not quite sure how to close it.  After
all, neither creating, nor reading (and then checking PID) are atomic.
Perhaps using flock() to lock accesses to the file, and requiring that
you hold the lock on it to remove it?  I'll have to fiddle a bit to see
if there's any edge cases on that...

We might also want to put in logic of the type "If PID file is less than
X old (5 seconds?  1 minute?), don't bother testing PID" as an
optimization as well as as a bit of insurance against the common cases
where the race would come up.


> What do you think about that?

Unless I can remember why I dismissed library functions in the first
place, it looks like the way to go; at least, once we address the race
possibilities.



-- 
Matthew Fuller     (MF4839)   |  fullermd@over-yonder.net
Systems/Network Administrator |  http://www.over-yonder.net/~fullermd/

"The only reason I'm burning my candle at both ends, is because I
      haven't figured out how to light the middle yet"

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




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