+ int pid;
+ int exit_code = 0;
+ int error_pipe[2];
+
+ /* 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 = copy_dirlinks = 0;
+
+ if (preserve_hard_links)
+ init_hard_links();
+
+ if (fd_pair(error_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 (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);
+ io_flush(FULL_FLUSH);
+ handle_stats(f_in);
+
+ send_msg(MSG_DONE, "", 0);
+ io_flush(FULL_FLUSH);
+
+ /* Handle any keep-alive packets from the post-processing work
+ * that the generator does. */
+ if (protocol_version >= 29) {
+ kluge_around_eof = -1;
+
+ /* This should only get stopped via a USR2 signal. */
+ while (read_int(f_in) == flist->count
+ && read_shortint(f_in) == ITEM_IS_NEW) {}
+
+ rprintf(FERROR, "Invalid packet at end of run [%s]\n",
+ who_am_i());
+ exit_cleanup(RERR_PROTOCOL);
+ }
+
+ /* 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 && !am_server)
+ stop_write_batch();