From: Matt McCutchen Date: Mon, 1 Feb 2010 18:29:39 +0000 (-0500) Subject: Don't set the umask to 0 any more: it's ugly and pointless. X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/commitdiff_plain/9a54a640f74dcaeb03ef99799a5320b3eb77f7ec Don't set the umask to 0 any more: it's ugly and pointless. --- diff --git a/clientserver.c b/clientserver.c index a7996c7f..878254f3 100644 --- a/clientserver.c +++ b/clientserver.c @@ -48,7 +48,6 @@ extern int write_batch; extern int default_af_hint; extern int logfile_format_has_i; extern int logfile_format_has_o_or_i; -extern mode_t orig_umask; extern char *bind_address; extern char *config_file; extern char *logfile_format; @@ -676,7 +675,6 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char if (*lp_prexfer_exec(i) || *lp_postxfer_exec(i)) { int status; - umask(orig_umask); /* For post-xfer exec, fork a new process to run the rsync * daemon while this process waits for the exit status and * runs the indicated command at that point. */ @@ -745,7 +743,6 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char set_blocking(fds[1]); pre_exec_fd = fds[1]; } - umask(0); } #endif @@ -1076,7 +1073,7 @@ static void create_pid_file(void) return; cleanup_set_pid(pid); - if ((fd = do_open(pid_file, O_WRONLY|O_CREAT|O_EXCL, 0666 & ~orig_umask)) == -1) { + if ((fd = do_open(pid_file, O_WRONLY|O_CREAT|O_EXCL, 0666)) == -1) { failure: cleanup_set_pid(0); fprintf(stderr, "failed to create pid file %s: %s\n", pid_file, strerror(errno)); diff --git a/main.c b/main.c index 4f3729e8..66412916 100644 --- a/main.c +++ b/main.c @@ -1521,9 +1521,10 @@ int main(int argc,char *argv[]) exit_cleanup(RERR_SYNTAX); } - /* we set a 0 umask so that correct file permissions can be - * carried across */ - orig_umask = umask(0); + /* Get the umask for use in permission calculations. We no longer set + * it to zero; that is ugly and pointless now that all the callers that + * relied on it have been reeducated to work with default ACLs. */ + umask(orig_umask = umask(0)); #if defined CONFIG_LOCALE && defined HAVE_SETLOCALE setlocale(LC_CTYPE, ""); diff --git a/pipe.c b/pipe.c index a33117c4..236cc616 100644 --- a/pipe.c +++ b/pipe.c @@ -27,7 +27,6 @@ extern int am_server; extern int blocking_io; extern int filesfrom_fd; extern int munge_symlinks; -extern mode_t orig_umask; extern char *logfile_name; extern int remote_option_cnt; extern const char **remote_options; @@ -78,7 +77,6 @@ pid_t piped_child(char **command, int *f_in, int *f_out) close(to_child_pipe[0]); if (from_child_pipe[1] != STDOUT_FILENO) close(from_child_pipe[1]); - umask(orig_umask); set_blocking(STDIN_FILENO); if (blocking_io > 0) set_blocking(STDOUT_FILENO); diff --git a/t_stub.c b/t_stub.c index e176b8b2..44593080 100644 --- a/t_stub.c +++ b/t_stub.c @@ -26,7 +26,6 @@ int module_id = -1; int relative_paths = 0; int module_dirlen = 0; int preserve_xattrs = 0; -mode_t orig_umask = 002; char number_separator = ','; char *partial_dir; char *module_dir; diff --git a/util.c b/util.c index c0580508..2c4c571e 100644 --- a/util.c +++ b/util.c @@ -32,7 +32,6 @@ extern int relative_paths; extern int preserve_xattrs; extern char *module_dir; extern unsigned int module_dirlen; -extern mode_t orig_umask; extern char *partial_dir; extern filter_rule_list daemon_filter_list; @@ -178,18 +177,11 @@ int set_modtime(const char *fname, time_t modtime, uint32 mod_nsec, mode_t mode) } } -/* This creates a new directory with default permissions. Since there - * might be some directory-default permissions affecting this, we can't - * force the permissions directly using the original umask and mkdir(). */ +/* This creates a new directory with default permissions. Now that we + * leave the original umask set, we can just mkdir with mode 777. */ int mkdir_defmode(char *fname) { - int ret; - - umask(orig_umask); - ret = do_mkdir(fname, ACCESSPERMS); - umask(0); - - return ret; + return do_mkdir(fname, ACCESSPERMS); } /* Create any necessary directories in fname. Any missing directories are @@ -216,8 +208,6 @@ int make_path(char *fname, int flags) } else end = fname + strlen(fname); - umask(orig_umask); /* NOTE: don't return before setting this back to 0! */ - /* Try to find an existing dir, starting from the deepest dir. */ for (p = end; ; ) { if (do_mkdir(fname, ACCESSPERMS) == 0) { @@ -258,8 +248,6 @@ int make_path(char *fname, int flags) ret++; } - umask(0); - if (flags & MKP_DROP_NAME) *end = '/';