+extern int verbose;
+extern int dry_run;
+extern int list_only;
+extern int am_root;
+extern int am_server;
+extern int am_sender;
+extern int am_generator;
+extern int am_daemon;
+extern int blocking_io;
+extern int remove_sent_files;
+extern int daemon_over_rsh;
+extern int need_messages_from_generator;
+extern int kluge_around_eof;
+extern int do_stats;
+extern int log_got_error;
+extern int module_id;
+extern int orig_umask;
+extern int copy_links;
+extern int keep_dirlinks;
+extern int preserve_hard_links;
+extern int protocol_version;
+extern int always_checksum;
+extern int recurse;
+extern int relative_paths;
+extern int rsync_port;
+extern int whole_file;
+extern int read_batch;
+extern int write_batch;
+extern int batch_fd;
+extern int batch_gen_fd;
+extern int filesfrom_fd;
+extern pid_t cleanup_child_pid;
+extern struct stats stats;
+extern char *filesfrom_host;
+extern char *rsync_path;
+extern char *shell_cmd;
+extern char *batch_name;
+extern char curr_dir[MAXPATHLEN];
+
+int local_server = 0;
+int pre_checksum = 0;
+struct file_list *the_file_list;
+
+/* There's probably never more than at most 2 outstanding child processes,
+ * but set it higher, just in case. */
+#define MAXCHILDPROCS 5
+
+struct pid_status {
+ pid_t pid;
+ int status;
+} pid_stat_table[MAXCHILDPROCS];
+
+static time_t starttime, endtime;
+static int64 total_read, total_written;
+
+static void show_malloc_stats(void);
+
+/* Works like waitpid(), but if we already harvested the child pid in our
+ * sigchld_handler(), we succeed instead of returning an error. */
+pid_t wait_process(pid_t pid, int *status_ptr, int flags)
+{
+ pid_t waited_pid = waitpid(pid, status_ptr, flags);
+
+ if (waited_pid == -1 && errno == ECHILD) {
+ /* Status of requested child no longer available: check to
+ * see if it was processed by sigchld_handler(). */
+ int cnt;
+ for (cnt = 0; cnt < MAXCHILDPROCS; cnt++) {
+ if (pid == pid_stat_table[cnt].pid) {
+ *status_ptr = pid_stat_table[cnt].status;
+ pid_stat_table[cnt].pid = 0;
+ return pid;
+ }
+ }
+ }