Added solaris IPv6 checking to configure. Fixes #6438.
[rsync/rsync.git] / main.c
diff --git a/main.c b/main.c
index 2a44cf8..8c2307a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -4,7 +4,7 @@
  * Copyright (C) 1996-2001 Andrew Tridgell <tridge@samba.org>
  * Copyright (C) 1996 Paul Mackerras
  * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2008 Wayne Davison
+ * Copyright (C) 2003-2009 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -77,10 +77,12 @@ extern char *rsync_path;
 extern char *shell_cmd;
 extern char *batch_name;
 extern char *password_file;
+extern char *backup_dir;
 extern char curr_dir[MAXPATHLEN];
+extern char backup_dir_buf[MAXPATHLEN];
 extern char *basis_dir[MAX_BASIS_DIRS+1];
 extern struct file_list *first_flist;
-extern struct filter_list_struct daemon_filter_list;
+extern filter_rule_list daemon_filter_list;
 
 uid_t our_uid;
 int am_generator = 0;
@@ -173,8 +175,10 @@ static void wait_process_with_flush(pid_t pid, int *exit_code_ptr)
 
 void write_del_stats(int f)
 {
-       if (!INFO_GTE(STATS, 2) || protocol_version < 31)
-               return;
+       if (read_batch)
+               write_int(f, NDX_DEL_STATS);
+       else
+               send_msg(MSG_DEL_STATS, "", 0, 0);
        write_varint(f, stats.deleted_files - stats.deleted_dirs
                      - stats.deleted_symlinks - stats.deleted_devices
                      - stats.deleted_specials);
@@ -186,8 +190,6 @@ void write_del_stats(int f)
 
 void read_del_stats(int f)
 {
-       if (!INFO_GTE(STATS, 2) || protocol_version < 31)
-               return;
        stats.deleted_files = read_varint(f);
        stats.deleted_files += stats.deleted_dirs = read_varint(f);
        stats.deleted_files += stats.deleted_symlinks = read_varint(f);
@@ -234,7 +236,6 @@ static void handle_stats(int f)
                                write_varlong30(f, stats.flist_buildtime, 3);
                                write_varlong30(f, stats.flist_xfertime, 3);
                        }
-                       write_del_stats(f);
                }
                return;
        }
@@ -253,8 +254,6 @@ static void handle_stats(int f)
                        stats.flist_buildtime = read_varlong30(f, 3);
                        stats.flist_xfertime = read_varlong30(f, 3);
                }
-               if (!read_batch)
-                       read_del_stats(f);
        } else if (write_batch) {
                /* The --read-batch process is going to be a client
                 * receiver, so we need to give it the stats. */
@@ -265,8 +264,6 @@ static void handle_stats(int f)
                        write_varlong30(batch_fd, stats.flist_buildtime, 3);
                        write_varlong30(batch_fd, stats.flist_xfertime, 3);
                }
-               /* We don't write the del stats into the batch file -- they
-                * come from the generator when reading the batch. */
        }
 }
 
@@ -528,7 +525,7 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
 #ifdef ICONV_CONST
                setup_iconv();
 #endif
-               if (protect_args)
+               if (protect_args && !daemon_over_rsh)
                        send_protected_args(*f_out_p, args);
        }
 
@@ -716,7 +713,7 @@ static void check_alt_basis_dirs(void)
 }
 
 /* This is only called by the sender. */
-static void read_final_goodbye(int f_in)
+static void read_final_goodbye(int f_in, int f_out)
 {
        int i, iflags, xlen;
        uchar fnamecmp_type;
@@ -725,8 +722,19 @@ static void read_final_goodbye(int f_in)
        if (protocol_version < 29)
                i = read_int(f_in);
        else {
-               i = read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type,
-                                      xname, &xlen);
+               i = read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type, xname, &xlen);
+               if (protocol_version >= 31 && i == NDX_DONE) {
+                       if (am_sender)
+                               write_ndx(f_out, NDX_DONE);
+                       else {
+                               if (batch_gen_fd >= 0) {
+                                       while (read_int(batch_gen_fd) != NDX_DEL_STATS) {}
+                                       read_del_stats(batch_gen_fd);
+                               }
+                               send_msg(MSG_DONE, "", 0, 0);
+                       }
+                       i = read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type, xname, &xlen);
+               }
        }
 
        if (i != NDX_DONE) {
@@ -785,7 +793,7 @@ static void do_server_sender(int f_in, int f_out, int argc, char *argv[])
        io_flush(FULL_FLUSH);
        handle_stats(f_out);
        if (protocol_version >= 24)
-               read_final_goodbye(f_in);
+               read_final_goodbye(f_in, f_out);
        io_flush(FULL_FLUSH);
        exit_cleanup(0);
 }
@@ -811,6 +819,16 @@ static int do_recv(int f_in, int f_out, char *local_name)
                exit_cleanup(RERR_IPC);
        }
 
+       if (backup_dir) {
+               int ret = make_path(backup_dir_buf, MKP_DROP_NAME); /* drops trailing slash */
+               if (ret < 0)
+                       exit_cleanup(RERR_SYNTAX);
+               if (ret)
+                       rprintf(FINFO, "Created backup_dir %s\n", backup_dir_buf);
+               else if (INFO_GTE(BACKUP, 1))
+                       rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf);
+       }
+
        io_flush(NORMAL_FLUSH);
 
        if ((pid = do_fork()) == -1) {
@@ -846,15 +864,10 @@ static int do_recv(int f_in, int f_out, char *local_name)
                /* Handle any keep-alive packets from the post-processing work
                 * that the generator does. */
                if (protocol_version >= 29) {
-                       int iflags, xlen;
-                       uchar fnamecmp_type;
-                       char xname[MAXPATHLEN];
-
                        kluge_around_eof = -1;
 
                        /* This should only get stopped via a USR2 signal. */
-                       read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type,
-                                          xname, &xlen);
+                       read_final_goodbye(f_in, f_out);
 
                        rprintf(FERROR, "Invalid packet at end of run [%s]\n",
                                who_am_i());
@@ -987,7 +1000,7 @@ static void do_server_recv(int f_in, int f_out, int argc, char *argv[])
 
        if (daemon_filter_list.head) {
                char **dir_p;
-               struct filter_list_struct *elp = &daemon_filter_list;
+               filter_rule_list *elp = &daemon_filter_list;
 
                for (dir_p = basis_dir; *dir_p; dir_p++) {
                        char *dir = *dir_p;
@@ -1090,7 +1103,6 @@ int client_run(int f_in, int f_out, pid_t pid, int argc, char *argv[])
                if (write_batch && !am_server)
                        start_write_batch(f_out);
                flist = send_file_list(f_out, argc, argv);
-               set_msg_fd_in(-1);
                if (DEBUG_GTE(FLIST, 3))
                        rprintf(FINFO,"file list sent\n");
 
@@ -1102,7 +1114,7 @@ int client_run(int f_in, int f_out, pid_t pid, int argc, char *argv[])
                io_flush(FULL_FLUSH);
                handle_stats(-1);
                if (protocol_version >= 24)
-                       read_final_goodbye(f_in);
+                       read_final_goodbye(f_in, f_out);
                if (pid != -1) {
                        if (DEBUG_GTE(EXIT, 2))
                                rprintf(FINFO,"client_run waiting on %d\n", (int) pid);