Add new --outbuf=N|L|B option.
authorWayne Davison <wayned@samba.org>
Sat, 28 Jan 2012 18:36:43 +0000 (10:36 -0800)
committerWayne Davison <wayned@samba.org>
Sat, 28 Jan 2012 18:41:58 +0000 (10:41 -0800)
configure.ac
options.c
rsync.yo

index 9e6b5552de84b4c3ab953a437ca63015ee8754db..a73fce69a512681bbea43ca662217267b34f29a6 100644 (file)
@@ -601,7 +601,7 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd strdup chown chmod lchmod mknod mkfifo \
     setlocale setmode open64 lseek64 mkstemp64 mtrace va_copy __va_copy \
     seteuid strerror putenv iconv_open locale_charset nl_langinfo getxattr \
     extattr_get_link sigaction sigprocmask setattrlist getgrouplist \
-    initgroups utimensat posix_fallocate attropen)
+    initgroups utimensat posix_fallocate attropen setvbuf)
 
 dnl cygwin iconv.h defines iconv_open as libiconv_open
 if test x"$ac_cv_func_iconv_open" != x"yes"; then
index 9b701d36a7efa03beb2251ef34703c370c25943c..5b2bfc1d66c39f091c5c0ef868b59d9596788d81 100644 (file)
--- a/options.c
+++ b/options.c
@@ -303,6 +303,7 @@ static int refused_partial, refused_progress, refused_delete_before;
 static int refused_delete_during;
 static int refused_inplace, refused_no_iconv;
 static BOOL usermap_via_chown, groupmap_via_chown;
+static char *outbuf_mode;
 static char *bwlimit_arg, *max_size_arg, *min_size_arg;
 static char tmp_partialdir[] = ".~tmp~";
 
@@ -789,6 +790,9 @@ void usage(enum logcode F)
   rprintf(F,"     --password-file=FILE    read daemon-access password from FILE\n");
   rprintf(F,"     --list-only             list the files instead of copying them\n");
   rprintf(F,"     --bwlimit=RATE          limit socket I/O bandwidth\n");
+#ifdef HAVE_SETVBUF
+  rprintf(F,"     --outbuf=N|L|B          set output buffering to None, Line, or Block\n");
+#endif
   rprintf(F,"     --write-batch=FILE      write a batched update to FILE\n");
   rprintf(F,"     --only-write-batch=FILE like --write-batch but w/o updating destination\n");
   rprintf(F,"     --read-batch=FILE       read a batched update from FILE\n");
@@ -1025,6 +1029,9 @@ static struct poptOption long_options[] = {
   {"password-file",    0,  POPT_ARG_STRING, &password_file, 0, 0, 0 },
   {"blocking-io",      0,  POPT_ARG_VAL,    &blocking_io, 1, 0, 0 },
   {"no-blocking-io",   0,  POPT_ARG_VAL,    &blocking_io, 0, 0, 0 },
+#ifdef HAVE_SETVBUF
+  {"outbuf",           0,  POPT_ARG_STRING, &outbuf_mode, 0, 0, 0 },
+#endif
   {"remote-option",   'M', POPT_ARG_STRING, 0, 'M', 0, 0 },
   {"protocol",         0,  POPT_ARG_INT,    &protocol_version, 0, 0, 0 },
   {"checksum-seed",    0,  POPT_ARG_INT,    &checksum_seed, 0, 0, 0 },
@@ -1820,6 +1827,33 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                exit_cleanup(0);
        }
 
+#ifdef HAVE_SETVBUF
+       if (outbuf_mode && !am_server) {
+               int mode = *(uchar *)outbuf_mode;
+               if (islower(mode))
+                       mode = toupper(mode);
+               fflush(stdout); /* Just in case... */
+               switch (mode) {
+               case 'N': /* None */
+               case 'U': /* Unbuffered */
+                       mode = _IONBF;
+                       break;
+               case 'L': /* Line */
+                       mode = _IOLBF;
+                       break;
+               case 'B': /* Block */
+               case 'F': /* Full */
+                       mode = _IOFBF;
+                       break;
+               default:
+                       snprintf(err_buf, sizeof err_buf,
+                               "Invalid --outbuf setting -- specify N, L, or B.\n");
+                       return 0;
+               }
+               setvbuf(stdout, (char *)NULL, mode, 0);
+       }
+#endif
+
        set_output_verbosity(verbose, DEFAULT_PRIORITY);
 
        if (do_stats) {
index e18fd2c2551f175ab91d090e0975a87d9416fefd..f5bc2bafb3b73b13a0c4541db619e51161691da0 100644 (file)
--- a/rsync.yo
+++ b/rsync.yo
@@ -434,6 +434,7 @@ to the detailed description below for a complete description.  verb(
      --port=PORT             specify double-colon alternate port number
      --sockopts=OPTIONS      specify custom TCP options
      --blocking-io           use blocking I/O for the remote shell
+     --outbuf=N|L|B          set out buffering to None, Line, or Block
      --stats                 give some file-transfer stats
  -8, --8-bit-output          leave high-bit chars unescaped in output
  -h, --human-readable        output numbers in a human-readable format
@@ -2007,6 +2008,13 @@ rsync defaults to using
 blocking I/O, otherwise it defaults to using non-blocking I/O.  (Note that
 ssh prefers non-blocking I/O.)
 
+dit(bf(--outbuf=MODE)) This sets the output buffering mode.  The mode can be
+None (aka Unbuffered), Line, or Block (aka Full).  You may specify as little
+as a single letter for the mode, and use upper or lower case.
+
+The main use of this option is to change Full buffering to Line buffering
+when rsync's output is going to a file or pipe.
+
 dit(bf(-i, --itemize-changes)) Requests a simple itemized list of the
 changes that are being made to each file, including attribute changes.
 This is exactly the same as specifying bf(--out-format='%i %n%L').