+ if (do_mkdir(name,0777 & ~orig_umask) != 0) {
+ rsyserr(FERROR, errno, "mkdir %s failed", full_fname(name));
+ exit_cleanup(RERR_FILEIO);
+ }
+ if (verbose > 0)
+ rprintf(FINFO, "created directory %s\n", safe_fname(name));
+
+ if (dry_run) {
+ dry_run++;
+ return NULL;
+ }
+
+ if (!push_dir(name)) {
+ rsyserr(FERROR, errno, "push_dir#2 %s failed",
+ full_fname(name));
+ exit_cleanup(RERR_FILESELECT);
+ }
+
+ return NULL;
+}
+
+
+static void do_server_sender(int f_in, int f_out, int argc,char *argv[])
+{
+ int i;
+ struct file_list *flist;
+ char *dir = argv[0];
+
+ if (verbose > 2) {
+ rprintf(FINFO, "server_sender starting pid=%ld\n",
+ (long)getpid());
+ }
+
+ if (am_daemon && lp_write_only(module_id)) {
+ rprintf(FERROR, "ERROR: module is write only\n");
+ exit_cleanup(RERR_SYNTAX);
+ return;
+ }
+ if (am_daemon && lp_read_only(module_id) && remove_sent_files) {
+ rprintf(FERROR,
+ "ERROR: --remove-sent-files cannot be used with a read-only module\n");
+ exit_cleanup(RERR_SYNTAX);
+ return;
+ }
+
+ if (!relative_paths && !push_dir(dir)) {
+ rsyserr(FERROR, errno, "push_dir#3 %s failed",
+ full_fname(dir));
+ exit_cleanup(RERR_FILESELECT);
+ }
+ argc--;
+ argv++;
+
+ if (strcmp(dir,".")) {
+ int l = strlen(dir);
+ if (strcmp(dir,"/") == 0)
+ l = 0;
+ for (i = 0; i < argc; i++)
+ argv[i] += l+1;
+ }
+
+ if (argc == 0 && (recurse || list_only)) {
+ argc = 1;
+ argv--;
+ argv[0] = ".";
+ }
+
+ flist = send_file_list(f_out,argc,argv);
+ if (!flist || flist->count == 0) {
+ exit_cleanup(0);
+ }
+
+ io_start_buffering_in();
+ io_start_buffering_out();
+
+ send_files(flist,f_out,f_in);
+ io_flush(FULL_FLUSH);
+ report(f_out);
+ if (protocol_version >= 24) {
+ /* final goodbye message */
+ read_int(f_in);
+ }
+ io_flush(FULL_FLUSH);
+ exit_cleanup(0);
+}
+
+
+static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
+{
+ int pid;
+ int status = 0;
+ int error_pipe[2], name_pipe[2];
+ BOOL need_name_pipe = (basis_dir[0] || partial_dir || fuzzy_basis
+ || (inplace && make_backups)) && !dry_run;
+
+ /* The receiving side mustn't obey this, or an existing symlink that
+ * points to an identical file won't be replaced by the referent. */
+ copy_links = 0;
+
+ if (preserve_hard_links)
+ init_hard_links(flist);
+
+ if (fd_pair(error_pipe) < 0
+ || (need_name_pipe && fd_pair(name_pipe) < 0)) {
+ rsyserr(FERROR, errno, "pipe failed in do_recv");
+ exit_cleanup(RERR_IPC);
+ }
+
+ io_flush(NORMAL_FLUSH);
+
+ if ((pid = do_fork()) == -1) {
+ rsyserr(FERROR, errno, "fork failed in do_recv");
+ exit_cleanup(RERR_IPC);
+ }
+
+ if (pid == 0) {
+ close(error_pipe[0]);
+ if (need_name_pipe) {
+ close(name_pipe[1]);
+ set_blocking(name_pipe[0]);
+ } else
+ name_pipe[0] = -1;
+ if (f_in != f_out)
+ close(f_out);
+
+ /* we can't let two processes write to the socket at one time */
+ close_multiplexing_out();
+
+ /* set place to send errors */
+ set_msg_fd_out(error_pipe[1]);
+
+ recv_files(f_in, flist, local_name, name_pipe[0]);
+ io_flush(FULL_FLUSH);
+ report(f_in);
+
+ send_msg(MSG_DONE, "", 0);
+ io_flush(FULL_FLUSH);
+ /* finally we go to sleep until our parent kills us
+ * with a USR2 signal. We sleep for a short time as on
+ * some OSes a signal won't interrupt a sleep! */
+ while (1)
+ msleep(20);
+ }
+
+ am_generator = 1;
+ close_multiplexing_in();
+ if (write_batch)
+ stop_write_batch();
+
+ close(error_pipe[1]);
+ if (need_name_pipe) {
+ close(name_pipe[0]);
+ set_nonblocking(name_pipe[1]);
+ } else
+ name_pipe[1] = -1;
+ if (f_in != f_out)
+ close(f_in);
+
+ io_start_buffering_out();
+
+ set_msg_fd_in(error_pipe[0]);
+
+ generate_files(f_out, flist, local_name, name_pipe[1]);
+
+ report(-1);
+ io_flush(FULL_FLUSH);
+ if (protocol_version >= 24) {
+ /* send a final goodbye message */
+ write_int(f_out, -1);
+ }
+ io_flush(FULL_FLUSH);
+
+ set_msg_fd_in(-1);
+ kill(pid, SIGUSR2);
+ wait_process(pid, &status);
+ return status;
+}
+
+
+static void do_server_recv(int f_in, int f_out, int argc,char *argv[])
+{
+ int status;
+ struct file_list *flist;
+ char *local_name = NULL;
+ char *dir = NULL;
+ int save_verbose = verbose;
+
+ if (filesfrom_fd >= 0) {
+ /* We can't mix messages with files-from data on the socket,
+ * so temporarily turn off verbose messages. */
+ verbose = 0;
+ }
+
+ if (verbose > 2) {
+ rprintf(FINFO, "server_recv(%d) starting pid=%ld\n",
+ argc, (long)getpid());
+ }
+
+ if (am_daemon && lp_read_only(module_id)) {
+ rprintf(FERROR,"ERROR: module is read only\n");
+ exit_cleanup(RERR_SYNTAX);
+ return;
+ }
+
+
+ if (argc > 0) {
+ dir = argv[0];
+ argc--;
+ argv++;
+ if (!am_daemon && !push_dir(dir)) {
+ rsyserr(FERROR, errno, "push_dir#4 %s failed",
+ full_fname(dir));
+ exit_cleanup(RERR_FILESELECT);
+ }
+ }
+
+ io_start_buffering_in();
+ recv_filter_list(f_in);
+
+ if (filesfrom_fd >= 0) {
+ /* We need to send the files-from names to the sender at the
+ * same time that we receive the file-list from them, so we
+ * need the IO routines to automatically write out the names
+ * onto our f_out socket as we read the file-list. This
+ * avoids both deadlock and extra delays/buffers. */
+ io_set_filesfrom_fds(filesfrom_fd, f_out);
+ filesfrom_fd = -1;
+ }
+
+ flist = recv_file_list(f_in);
+ verbose = save_verbose;
+ if (!flist) {
+ rprintf(FERROR,"server_recv: recv_file_list error\n");
+ exit_cleanup(RERR_FILESELECT);
+ }
+
+ if (argc > 0) {
+ if (strcmp(dir,".")) {
+ argv[0] += strlen(dir);
+ if (argv[0][0] == '/')
+ argv[0]++;
+ }
+ local_name = get_local_name(flist,argv[0]);
+ }
+
+ status = do_recv(f_in,f_out,flist,local_name);
+ exit_cleanup(status);
+}
+
+
+int child_main(int argc, char *argv[])