char line[MAXPATHLEN];
char *p, *user=NULL;
extern int remote_version;
- extern int am_client;
extern int am_sender;
if (*path == '/') {
if (!user) user = getenv("USER");
if (!user) user = getenv("LOGNAME");
- am_client = 1;
-
fd = open_socket_out(host, rsync_port);
if (fd == -1) {
exit_cleanup(RERR_SOCKETIO);
return -1;
}
- if (chdir("/")) {
+ if (!push_dir("/", 0)) {
rprintf(FERROR,"chdir %s failed\n", lp_path(i));
io_printf(fd,"@ERROR: chdir failed\n");
return -1;
}
}
- ret = parse_arguments(argc, argv);
+ ret = parse_arguments(argc, argv, 0);
if (request) {
if (*auth_user) {
int daemon_main(void)
{
extern char *config_file;
+ extern int orig_umask;
char *pid_file;
- /* this ensures that we don't call getcwd after the chroot,
- which doesn't work on platforms that use popen("pwd","r")
- for getcwd */
- push_dir("/", 0);
-
if (is_a_socket(STDIN_FILENO)) {
int i;
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);