The "pid file" was getting created mode 666, not applying the umask
[rsync.git] / clientserver.c
index 9e79538ec1f1746e919d414f2a9da2d33ecb777f..ace360b4de150023317e9c2c91fdc1324c869172 100644 (file)
@@ -417,6 +417,7 @@ static int start_daemon(int fd)
 int daemon_main(void)
 {
        extern char *config_file;
+       extern int orig_umask;
        char *pid_file;
 
        if (is_a_socket(STDIN_FILENO)) {
@@ -447,16 +448,19 @@ int daemon_main(void)
        rprintf(FINFO,"rsyncd version %s starting\n",VERSION);
 
        if (((pid_file = lp_pid_file()) != NULL) && (*pid_file != '\0')) {
-               FILE *f;
+               char pidbuf[16];
+               int fd;
                int pid = (int) getpid();
                cleanup_set_pid(pid);
-               if ((f = fopen(lp_pid_file(), "w")) == NULL) {
+               if ((fd = do_open(lp_pid_file(), O_WRONLY|O_CREAT|O_TRUNC,
+                                       0666 & ~orig_umask)) == -1) {
                    cleanup_set_pid(0);
                    fprintf(stderr,"failed to create pid file %s\n", pid_file);
                    exit_cleanup(RERR_FILEIO);
                }
-               fprintf(f, "%d\n", pid);
-               fclose(f);
+               slprintf(pidbuf, sizeof(pidbuf), "%d\n", pid);
+               write(fd, pidbuf, strlen(pidbuf));
+               close(fd);
        }
 
        start_accept_loop(rsync_port, start_daemon);