Commit 7058a177 authored by Matthieu Herrb's avatar Matthieu Herrb

Avoid chmod() calls on directories

There are several reasons for that:
- the reason that triggered this patch is that the pledge() sandboxing
system on OpenBSD forbids chmod() by default in many pledged
applications. When one of these needs to rebuild the font cache it
will fail because of these unneeded chmod() calls.
- trying to change existing directories access rights isn't a good idea
- and lastly doing mkdir() && chmod() is racy. Use umask() to make shure
the directory is created with the proper access rights from start.
Signed-off-by: Matthieu Herrb's avatarMatthieu Herrb <matthieu@herrb.eu>
parent c9862b6e
Pipeline #74019 passed with stage
in 4 minutes and 48 seconds
......@@ -1323,16 +1323,6 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
break;
}
}
/*
* Otherwise, try making it writable
*/
else if (chmod ((char *) d, 0755) == 0)
{
cache_dir = FcStrCopyFilename (d);
/* Try to create CACHEDIR.TAG too */
FcDirCacheCreateTagFile (d);
break;
}
}
}
if (d)
......
......@@ -242,6 +242,7 @@ FcMakeDirectory (const FcChar8 *dir)
{
FcChar8 *parent;
FcBool ret;
mode_t oldmask = umask(022);
if (strlen ((char *) dir) == 0)
return FcFalse;
......@@ -250,12 +251,13 @@ FcMakeDirectory (const FcChar8 *dir)
if (!parent)
return FcFalse;
if (access ((char *) parent, F_OK) == 0)
ret = mkdir ((char *) dir, 0755) == 0 && chmod ((char *) dir, 0755) == 0;
ret = mkdir ((char *) dir, 0755) == 0;
else if (access ((char *) parent, F_OK) == -1)
ret = FcMakeDirectory (parent) && (mkdir ((char *) dir, 0755) == 0) && chmod ((char *) dir, 0755) == 0;
ret = FcMakeDirectory (parent) && (mkdir ((char *) dir, 0755) == 0);
else
ret = FcFalse;
FcStrFree (parent);
umask(oldmask);
return ret;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment