From 75dd382407a36b3ebab36bb1027eb43a07498bec Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 27 Sep 2003 13:34:50 +0200 Subject: [PATCH] added CCACHE_UMASK fixed a typo --- ccache.1 | 13 ++++++++++--- ccache.c | 15 +++++++++++++++ ccache.yo | 12 +++++++++--- execute.c | 4 ++-- util.c | 2 +- web/ccache-man.html | 11 ++++++++--- 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/ccache.1 b/ccache.1 index 962f98e08..8ffb5cc29 100644 --- a/ccache.1 +++ b/ccache.1 @@ -133,7 +133,7 @@ compiler as a command line option\&. .PP .SH "ENVIRONMENT VARIABLES" .PP -ccache used a number of environment variables to control operation\&. In +ccache uses a number of environment variables to control operation\&. In most cases you won\&'t need any of these as the defaults will be fine\&. .PP .IP @@ -201,6 +201,13 @@ This forces ccache to not use any cached results, even if it finds them\&. New results are still cached, but existing cache entries are ignored\&. .IP +.IP "\fBCCACHE_UMASK\fP" +This sets the umask for ccache and all child +processes (such as the compiler)\&. This is mostly useful when you wish +to share your cache with other users\&. Note that this also affects the +file permissions set on the object files created from your +compilations\&. +.IP .IP "\fBCCACHE_HASHDIR\fP" This tells ccache to hash the current working directory when calculating the hash that is used to distinguish two @@ -300,8 +307,8 @@ Use the same \fBCCACHE_DIR\fP environment variable setting Make sure that all users have write permission in the entire cache directory (and that you trust all users of the shared cache)\&. .IP o -Tell your users to set a umask that allows group writes -(eg\&. umask 002) +Make sure everyone sets the CCACHE_UMASK environment variable +to 002, this ensures that cached files are accessible to everyone\&. .IP o Make sure that the setgid bit is set on all directories in the cache\&. This tells the filesystem to inherit group ownership for new diff --git a/ccache.c b/ccache.c index 03e205e81..9ead0566f 100644 --- a/ccache.c +++ b/ccache.c @@ -961,6 +961,8 @@ static void setup_uncached_err(void) int main(int argc, char *argv[]) { + char *p; + cache_dir = getenv("CCACHE_DIR"); if (!cache_dir) { x_asprintf(&cache_dir, "%s/.ccache", getenv("HOME")); @@ -969,6 +971,19 @@ int main(int argc, char *argv[]) cache_logfile = getenv("CCACHE_LOGFILE"); setup_uncached_err(); + + + /* the user might have set CCACHE_UMASK */ + p = getenv("CCACHE_UMASK"); + if (p) { + mode_t mask; + errno = 0; + mask = strtol(p, NULL, 8); + if (errno == 0) { + umask(mask); + } + } + /* check if we are being invoked as "ccache" */ if (strlen(argv[0]) >= strlen(MYNAME) && diff --git a/ccache.yo b/ccache.yo index 72e3e6fe8..f33b3efaa 100644 --- a/ccache.yo +++ b/ccache.yo @@ -115,7 +115,7 @@ compiler as a command line option. manpagesection(ENVIRONMENT VARIABLES) -ccache used a number of environment variables to control operation. In +ccache uses a number of environment variables to control operation. In most cases you won't need any of these as the defaults will be fine. startdit() @@ -173,6 +173,12 @@ dit(bf(CCACHE_RECACHE)) This forces ccache to not use any cached results, even if it finds them. New results are still cached, but existing cache entries are ignored. +dit(bf(CCACHE_UMASK)) This sets the umask for ccache and all child +processes (such as the compiler). This is mostly useful when you wish +to share your cache with other users. Note that this also affects the +file permissions set on the object files created from your +compilations. + dit(bf(CCACHE_HASHDIR)) This tells ccache to hash the current working directory when calculating the hash that is used to distinguish two compiles. This prevents a problem with the storage of the current @@ -266,8 +272,8 @@ itemize( it() Use the same bf(CCACHE_DIR) environment variable setting it() Make sure that all users have write permission in the entire cache directory (and that you trust all users of the shared cache). - it() Tell your users to set a umask that allows group writes - (eg. umask 002) + it() Make sure everyone sets the CCACHE_UMASK environment variable + to 002, this ensures that cached files are accessible to everyone. it() Make sure that the setgid bit is set on all directories in the cache. This tells the filesystem to inherit group ownership for new directories. The command "chmod g+s `find $CCACHE_DIR -type d`" might diff --git a/execute.c b/execute.c index f55fbdda5..56146a001 100644 --- a/execute.c +++ b/execute.c @@ -37,7 +37,7 @@ int execute(char **argv, int fd; unlink(path_stdout); - fd = open(path_stdout, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644); + fd = open(path_stdout, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0666); if (fd == -1) { exit(STATUS_NOCACHE); } @@ -45,7 +45,7 @@ int execute(char **argv, close(fd); unlink(path_stderr); - fd = open(path_stderr, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644); + fd = open(path_stderr, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0666); if (fd == -1) { exit(STATUS_NOCACHE); } diff --git a/util.c b/util.c index 6bab50d91..27ddea56a 100644 --- a/util.c +++ b/util.c @@ -423,7 +423,7 @@ int create_empty_file(const char *fname) { int fd; - fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644); + fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0666); if (fd == -1) { return -1; } diff --git a/web/ccache-man.html b/web/ccache-man.html index f739ddbd2..9d0cd09b3 100644 --- a/web/ccache-man.html +++ b/web/ccache-man.html @@ -116,7 +116,7 @@ treated as an input file name and instead be passed along to the compiler as a command line option.

ENVIRONMENT VARIABLES

-

ccache used a number of environment variables to control operation. In +

ccache uses a number of environment variables to control operation. In most cases you won't need any of these as the defaults will be fine.

CCACHE_DIR
the CCACHE_DIR environment variable specifies @@ -161,6 +161,11 @@ file copy. Using hard links is faster, but can confuse programs like

CCACHE_RECACHE
This forces ccache to not use any cached results, even if it finds them. New results are still cached, but existing cache entries are ignored. +

CCACHE_UMASK
This sets the umask for ccache and all child +processes (such as the compiler). This is mostly useful when you wish +to share your cache with other users. Note that this also affects the +file permissions set on the object files created from your +compilations.

CCACHE_HASHDIR
This tells ccache to hash the current working directory when calculating the hash that is used to distinguish two compiles. This prevents a problem with the storage of the current @@ -241,8 +246,8 @@ following conditions need to be met:
  • Use the same CCACHE_DIR environment variable setting
  • Make sure that all users have write permission in the entire cache directory (and that you trust all users of the shared cache). -
  • Tell your users to set a umask that allows group writes - (eg. umask 002) +
  • Make sure everyone sets the CCACHE_UMASK environment variable + to 002, this ensures that cached files are accessible to everyone.
  • Make sure that the setgid bit is set on all directories in the cache. This tells the filesystem to inherit group ownership for new directories. The command "chmod g+s `find $CCACHE_DIR -type d`" might -- 2.47.2