From owner-freebsd-stable Sun Jun 23 6: 9:59 2002 Delivered-To: freebsd-stable@freebsd.org Received: from sea-incorporated.com (caribbean.sea-incorporated.com [209.74.10.130]) by hub.freebsd.org (Postfix) with ESMTP id 6494737B429 for ; Sun, 23 Jun 2002 06:08:54 -0700 (PDT) Received: from sea-incorporated.com (localhost [127.0.0.1]) by sea-incorporated.com (8.12.3/8.12.3) with ESMTP id g5ND7F0t029776; Sun, 23 Jun 2002 09:07:15 -0400 (EDT) (envelope-from geoff@sea-incorporated.com) Received: from localhost (geoff@localhost) by sea-incorporated.com (8.12.3/8.12.3/Submit) with ESMTP id g5ND7Fcx029773; Sun, 23 Jun 2002 09:07:15 -0400 (EDT) Date: Sun, 23 Jun 2002 09:07:15 -0400 (EDT) From: "Geoffrey C. Speicher" To: "Matthew D. Fuller" Cc: freebsd-stable@freebsd.org, Matt Simerson , Paul Herman Subject: Re: bug in pw, -STABLE [patch] In-Reply-To: <20020623024804.GB95458@over-yonder.net> Message-ID: <20020623084607.H29729-100000@sea-incorporated.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sat, 22 Jun 2002, Matthew D. Fuller wrote: > 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... Using a library does leave the door open for the following scenario, which ultimately stems from the fact that pids get reused: 1. a process p1 writes his pid in /var/run/file.pid 2. p1 dies a miserable death, leaving /var/run/file.pid intact 3. a long time passes, and nobody notices that p1 left a pid file 4. a new, unrelated process comes around with the same pid as p1 5. another process p2 wants /var/run/file.pid and finds that it exists and a process with the pid inside exists as well, except p2 has no way of knowing that the process has nothing to do with the pid file Actually, now that I think about it, even a daemon wouldn't guarantee better results in every such scenario. At first it would seem that the daemon would get a chance to clean up the pid file long before another process wanted it (during step 4). However, if the timing is just right then p1 can die the moment that its pid would be reused, and chances are that the daemon wouldn't catch it in time. > 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 I think you must've figured it out judging by your post that just came through as I was writing that previous paragraph. :) Geoff To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message