createTempDir(): Don't do a chown on Linux

It's not needed and can cause problems in a user namespace.
This commit is contained in:
Eelco Dolstra 2016-06-02 18:17:30 +02:00
parent a24f2c9b84
commit a424ab0444

View file

@ -384,6 +384,7 @@ Path createTempDir(const Path & tmpRoot, const Path & prefix,
checkInterrupt(); checkInterrupt();
Path tmpDir = tempName(tmpRoot, prefix, includePid, counter); Path tmpDir = tempName(tmpRoot, prefix, includePid, counter);
if (mkdir(tmpDir.c_str(), mode) == 0) { if (mkdir(tmpDir.c_str(), mode) == 0) {
#if __FreeBSD__
/* Explicitly set the group of the directory. This is to /* Explicitly set the group of the directory. This is to
work around around problems caused by BSD's group work around around problems caused by BSD's group
ownership semantics (directories inherit the group of ownership semantics (directories inherit the group of
@ -394,6 +395,7 @@ Path createTempDir(const Path & tmpRoot, const Path & prefix,
have the setgid bit set on directories. */ have the setgid bit set on directories. */
if (chown(tmpDir.c_str(), (uid_t) -1, getegid()) != 0) if (chown(tmpDir.c_str(), (uid_t) -1, getegid()) != 0)
throw SysError(format("setting group of directory %1%") % tmpDir); throw SysError(format("setting group of directory %1%") % tmpDir);
#endif
return tmpDir; return tmpDir;
} }
if (errno != EEXIST) if (errno != EEXIST)