aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/blaze_util.cc
diff options
context:
space:
mode:
authorGravatar Han-Wen Nienhuys <hanwen@google.com>2015-06-01 13:22:10 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2015-06-01 15:50:12 +0000
commitf4a3d4f0a6a5f2194bf3f53ecf2aae913eff01fa (patch)
tree3cbe8ba69a6036f457a5ace2f2361d445af843db /src/main/cpp/blaze_util.cc
parent30f421821c8cf9b7111c56e86b1a72bcb9c71750 (diff)
launcher: observe umask in MakeDirectories.
-- MOS_MIGRATED_REVID=94905648
Diffstat (limited to 'src/main/cpp/blaze_util.cc')
-rw-r--r--src/main/cpp/blaze_util.cc15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index b2784d715d..4917462f3a 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -79,11 +79,12 @@ string MakeAbsolute(const string &path) {
return cwdbuf + separator + path;
}
-// Runs "stat" on `path`. Returns -1 and sets errno if stat fails or `path`
-// isn't a directory. If check_perms is true, this will also make sure that
-// `path` is owned by the current user and has `mode` permissions (attempting to
-// run chmod if not). If `path` is a symlink, this will check ownership of the
-// link, not the underlying directory.
+// Runs "stat" on `path`. Returns -1 and sets errno if stat fails or
+// `path` isn't a directory. If check_perms is true, this will also
+// make sure that `path` is owned by the current user and has `mode`
+// permissions (observing the umask). It attempts to run chmod to
+// correct the mode if necessary. If `path` is a symlink, this will
+// check ownership of the link, not the underlying directory.
static int GetDirectoryStat(const string& path, mode_t mode, bool check_perms) {
struct stat filestat = {};
if (stat(path.c_str(), &filestat) == -1) {
@@ -107,6 +108,10 @@ static int GetDirectoryStat(const string& path, mode_t mode, bool check_perms) {
errno = EACCES;
return -1;
}
+
+ mode_t mask = umask(022);
+ umask(mask);
+ mode = (mode & ~mask);
if ((filestat.st_mode & 0777) != mode
&& chmod(path.c_str(), mode) == -1) {
// errno set by chmod.