Replace umask() with chmod() because it's not thread-safe.

This commit is contained in:
Gunnar Beutner 2013-09-28 08:10:32 +02:00
parent be5078c9aa
commit cd4d3e6e8e
1 changed files with 9 additions and 7 deletions

View File

@ -77,11 +77,7 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
}
}
/*
* process would override group write permissions
* so reset them. man 3 mkfifo: (mode & ~umask)
*/
mode_t oldMask = umask(S_IWOTH);
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
if (!fifo_ok && mkfifo(commandPath.CStr(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0) {
BOOST_THROW_EXCEPTION(posix_error()
@ -90,8 +86,14 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
<< boost::errinfo_file_name(commandPath));
}
/* restore old umask */
umask(oldMask);
/* mkfifo() uses umask to mask off some bits, which means we need to chmod() the
* fifo to get the right mask. */
if (chmod(commandPath.CStr(), mode) < 0) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("chmod")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(commandPath));
}
for (;;) {
int fd;