Subject: Re: another parallel-make race
To: Christos Zoulas <christos@astron.com>
From: Chuck Silvers <chuq@chuq.com>
List: current-users
Date: 09/16/2005 09:07:51
--/04w6evG8XlLl3ft
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Tue, Sep 13, 2005 at 03:50:42PM +0000, Christos Zoulas wrote:
> >please try the attached patch (which both fixes the above problem and
> >updates pax's copy of mkpath() with the race-avoiding version from mkdir.c).
> >
> 
> I committed it with minor changes. Many thanks.

I hit the same problem again even after those fixes.
there's another similar race in pax, in chk_path(),
which is probably the one that was actually causing the trouble.
here's another patch.

-Chuck

--/04w6evG8XlLl3ft
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="diff.pax.race2"

Index: src/bin/pax/file_subs.c
===================================================================
RCS file: /cvsroot/src/bin/pax/file_subs.c,v
retrieving revision 1.55
diff -u -p -r1.55 file_subs.c
--- src/bin/pax/file_subs.c	13 Sep 2005 20:09:55 -0000	1.55
+++ src/bin/pax/file_subs.c	16 Sep 2005 16:07:30 -0000
@@ -731,11 +731,21 @@ chk_path(char *name, uid_t st_uid, gid_t
 		 * needed directory and continue on
 		 */
 		if (mkdir(name, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
+
+			/*
+			 * check if someone created the directory in between
+			 * our lstat() and mkdir() calls, and if so,
+			 * proceed as if our mkdir() succeeded.
+			 */
+			if (stat(name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
+				goto raced;
+			}
 			*spt = '/';
 			retval = -1;
 			break;
 		}
 
+raced:
 		/*
 		 * we were able to create the directory. We will tell the
 		 * caller that we found something to fix, and it is ok to try

--/04w6evG8XlLl3ft--