Fix a race condtition in the server startup

Francois Gouget fgouget at codeweavers.com
Sun Feb 27 19:14:28 CST 2005


Bill Medland wrote:
[...]
> How about simply mkdir and if the error is already existed then fine.?
> 
> Unchecked, but something like:
>     if (mkdir (name, 0700) == -1) 
>     {
>         if (errno != EEXIST) fatal_perror ("Ensuring directory %s", name)
>     }

I guess you mean this:

static void create_dir( const char *name, struct stat *st )
{
     if (mkdir( name, 0700 ) == -1 && errno != EEXIST) fatal_perror( 
"mkdir %s", name );
     if (lstat( name, st ) == -1) fatal_perror( "lstat %s", name );
...

Yes, I think this would work fine. It makes the common case (the 
directory already exists) a tiny bit less efficient but this is 
non-critical code and it makes the code simpler.
So here's a patch based on this variant.


Changelog:

  * server/request.c
    Francois Gouget <fgouget at codeweavers.com>
    Fix a race condition in create_dir().

-- 
Francois Gouget
fgouget at codeweavers.com
-------------- next part --------------
Index: server/request.c
===================================================================
RCS file: /var/cvs/wine/server/request.c,v
retrieving revision 1.83
diff -u -p -r1.83 request.c
--- server/request.c	3 Feb 2005 10:46:15 -0000	1.83
+++ server/request.c	28 Feb 2005 01:02:32 -0000
@@ -506,12 +506,8 @@ static void socket_cleanup(void)
 /* create a directory and check its permissions */
 static void create_dir( const char *name, struct stat *st )
 {
-    if (lstat( name, st ) == -1)
-    {
-        if (errno != ENOENT) fatal_perror( "lstat %s", name );
-        if (mkdir( name, 0700 ) == -1) fatal_perror( "mkdir %s", name );
-        if (lstat( name, st ) == -1) fatal_perror( "lstat %s", name );
-    }
+    if (mkdir( name, 0700 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", name );
+    if (lstat( name, st ) == -1) fatal_perror( "lstat %s", name );
     if (!S_ISDIR(st->st_mode)) fatal_error( "%s is not a directory\n", name );
     if (st->st_uid != getuid()) fatal_error( "%s is not owned by you\n", name );
     if (st->st_mode & 077) fatal_error( "%s must not be accessible by other users\n", name );


More information about the wine-patches mailing list