+ if (do_mkdir(name,0777 & ~orig_umask) != 0) {
+ rprintf(FERROR, "mkdir %s failed: %s\n",
+ full_fname(name), strerror(errno));
+ exit_cleanup(RERR_FILEIO);
+ } else {
+ if (verbose > 0)
+ rprintf(FINFO,"created directory %s\n",name);
+ }
+
+ if (!push_dir(name)) {
+ rprintf(FERROR, "push_dir %s failed: %s (2)\n",
+ full_fname(name), strerror(errno));
+ 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 (!relative_paths && !push_dir(dir)) {
+ rprintf(FERROR, "push_dir %s failed: %s (3)\n",
+ full_fname(dir), strerror(errno));
+ 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) {
+ 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(f_in);
+ io_start_buffering_out(f_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];
+
+ if (preserve_hard_links)
+ init_hard_links(flist);
+
+ if (!delete_after) {
+ /* I moved this here from recv_files() to prevent a race condition */
+ if (recurse && delete_mode && !local_name && flist->count>0) {
+ delete_files(flist);
+ }
+ }
+
+ if (fd_pair(error_pipe) < 0) {
+ rprintf(FERROR,"error pipe failed in do_recv\n");
+ exit_cleanup(RERR_SOCKETIO);
+ }
+
+ io_flush(NORMAL_FLUSH);
+
+ if ((pid=do_fork()) == 0) {
+ close(error_pipe[0]);
+ if (f_in != f_out) close(f_out);
+
+ /* we can't let two processes write to the socket at one time */
+ io_multiplexing_close();
+
+ /* set place to send errors */
+ set_msg_fd_out(error_pipe[1]);
+
+ recv_files(f_in,flist,local_name);
+ 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(error_pipe[1]);
+ if (f_in != f_out) close(f_in);
+
+ io_start_buffering_out(f_out);
+
+ set_msg_fd_in(error_pipe[0]);
+
+ generate_files(f_out, flist, local_name);
+
+ get_redo_num(); /* Read final MSG_DONE and any prior messages. */
+ 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;
+
+ if (verbose > 2) {
+ rprintf(FINFO, "server_recv(%d) starting pid=%ld\n",
+ argc, (long)getpid());
+ }
+
+ if (am_daemon && lp_read_only(module_id) && !am_sender) {
+ 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)) {
+ rprintf(FERROR, "push_dir %s failed: %s (4)\n",
+ full_fname(dir), strerror(errno));
+ exit_cleanup(RERR_FILESELECT);
+ }
+ }
+
+ io_start_buffering_in(f_in);
+ if (delete_mode && !delete_excluded)
+ recv_exclude_list(f_in);
+
+ if (filesfrom_fd >= 0) {
+ /* We're receiving the file info from the sender, so we need
+ * the IO routines to automatically write out the names onto
+ * our f_out socket as we read the list info from the sender.
+ * This avoids both deadlock and extra delays/buffers. */
+ io_set_filesfrom_fds(filesfrom_fd, f_out);
+ filesfrom_fd = -1;
+ }
+
+ if (read_batch)
+ flist = batch_flist;
+ else
+ flist = recv_file_list(f_in);
+ 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[])