Here's a better patch; rsync should now no longer dump core if called with
insufficient arguments. write_batch_argvs_file() is still ugly though, not
sure how to clean this up.

Index: batch.c
===================================================================
RCS file: /cvsroot/rsync/batch.c,v
retrieving revision 1.6
diff -u -r1.6 batch.c
--- batch.c     2 Dec 2001 22:47:30 -0000       1.6
+++ batch.c     6 Dec 2001 23:11:26 -0000
@@ -128,7 +128,7 @@
        }
 }
 
-void write_batch_argvs_file(int orig_argc, int argc, char **argv)
+void write_batch_argvs_file(int argc, char *argv[])
 {
        int fdb;
        int i;
@@ -149,13 +149,17 @@
        buff[0] = '\0';
        /* Write argvs info to batch file */
 
-       for (i = argc - orig_argc; i < argc; i++) {
-               /* FIXME: This apparently crashes if rsync is run with
-                * just "rsync -F".  I think directly manipulating
-                * argv[] is probably bogus -- what if -F is part of a
-                * run of several short options? */
-               if (!strcmp(argv[i], "-F")) {   /* safer to change it here than script 
*/
-                       strncat(buff, "-f ", 3);        /* chg to -f + ext to get 
ready for remote */
+       for (i = 0; i < argc; ++i) {
+               /*
+                * FIXME: I think directly manipulating argv[] is probably
+                * bogus -- what if -F is part of a run of several short
+                * options?
+                */
+               if (!strcmp(argv[i], "-F") ||
+                   !strcmp(argv[i], "--write-batch")) {
+                       /* safer to change it here than script */
+                       /* chg to -f + ext to get ready for remote */
+                       strncat(buff, "-f ", 3);
                        strncat(buff, batch_file_ext,
                                strlen(batch_file_ext));
                } else {
Index: main.c
===================================================================
RCS file: /cvsroot/rsync/main.c,v
retrieving revision 1.134
diff -u -r1.134 main.c
--- main.c      15 Aug 2001 07:50:07 -0000      1.134
+++ main.c      6 Dec 2001 23:11:27 -0000
@@ -765,8 +765,10 @@
        extern int write_batch;  /*  dw */
        extern char *batch_ext;   /*  dw */
        int orig_argc;  /* dw */
+       char **orig_argv;
 
        orig_argc = argc;   /* dw */
+       orig_argv = argv;
 
        signal(SIGUSR1, sigusr1_handler);
        signal(SIGUSR2, sigusr2_handler);
@@ -806,7 +808,7 @@
 
        if (write_batch) { /* dw */
            create_batch_file_ext();
-           write_batch_argvs_file(orig_argc, argc, argv);
+           write_batch_argvs_file(orig_argc, orig_argv);
        }
 
        if (read_batch) { /* dw */
Index: proto.h
===================================================================
RCS file: /cvsroot/rsync/proto.h,v
retrieving revision 1.133
diff -u -r1.133 proto.h
--- proto.h     26 Nov 2001 07:18:09 -0000      1.133
+++ proto.h     6 Dec 2001 23:11:27 -0000
@@ -9,7 +9,7 @@
 void write_batch_flist_file(char *buff, int bytes_to_write);
 void write_batch_flist_info(int flist_count, struct file_struct **fptr);
 void write_char_bufs(char *buf);
-void write_batch_argvs_file(int orig_argc, int argc, char **argv);
+void write_batch_argvs_file(int argc, char *argv[]);
 struct file_list *create_flist_from_batch();
 int read_batch_flist_file(char *buff, int len);
 unsigned char read_batch_flags();

-- 
Jos Backus                 _/  _/_/_/        Santa Clara, CA
                          _/  _/   _/
                         _/  _/_/_/             
                    _/  _/  _/    _/
[EMAIL PROTECTED]     _/_/   _/_/_/            use Std::Disclaimer;

Reply via email to