From cd4d3e6e8ed846cd0494c078238fae1cd769c743 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 28 Sep 2013 08:10:32 +0200 Subject: [PATCH] Replace umask() with chmod() because it's not thread-safe. --- components/compat/externalcommandlistener.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/components/compat/externalcommandlistener.cpp b/components/compat/externalcommandlistener.cpp index 35bd95ccf..8167146eb 100644 --- a/components/compat/externalcommandlistener.cpp +++ b/components/compat/externalcommandlistener.cpp @@ -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;