From eabc85ef5ecd7ed9892ee3d9562468dbb84cbef5 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Sun, 20 Jul 2008 20:08:08 -0700 Subject: [PATCH] Added a debug-helping option, --msgs2stderr, than should help all messages to be seen in a situation where rsync is dying (as long as stderr is a viable output method for the remote rsync). --- log.c | 7 +++++++ main.c | 3 ++- options.c | 2 ++ rsync.c | 7 +++++-- testsuite/hands.test | 10 ++++++---- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/log.c b/log.c index 8f8f049f..5d59419e 100644 --- a/log.c +++ b/log.c @@ -36,6 +36,7 @@ extern int allow_8bit_chars; extern int protocol_version; extern int always_checksum; extern int preserve_times; +extern int msgs2stderr; extern int uid_ndx; extern int gid_ndx; extern int stdout_format_has_i; @@ -257,6 +258,11 @@ void rwrite(enum logcode code, const char *buf, int len, int is_utf8) if (len < 0) exit_cleanup(RERR_MESSAGEIO); + if (msgs2stderr && code != FLOG) { + f = stderr; + goto output_msg; + } + if (am_server && msg_fd_out >= 0) { assert(!is_utf8); /* Pass the message to our sibling. */ @@ -323,6 +329,7 @@ void rwrite(enum logcode code, const char *buf, int len, int is_utf8) exit_cleanup(RERR_MESSAGEIO); } +output_msg: if (output_needs_newline) { fputc('\n', f); output_needs_newline = 0; diff --git a/main.c b/main.c index 939004ab..39eab69b 100644 --- a/main.c +++ b/main.c @@ -43,6 +43,7 @@ extern int output_needs_newline; extern int need_messages_from_generator; extern int kluge_around_eof; extern int got_xfer_error; +extern int msgs2stderr; extern int module_id; extern int copy_links; extern int copy_dirlinks; @@ -860,7 +861,7 @@ static void do_server_recv(int f_in, int f_out, int argc, char *argv[]) char *local_name = NULL; int negated_levels; - if (filesfrom_fd >= 0) { + if (filesfrom_fd >= 0 && !msgs2stderr) { /* We can't mix messages with files-from data on the socket, * so temporarily turn off info/debug messages. */ negate_output_levels(); diff --git a/options.c b/options.c index a93f4656..4a7516d9 100644 --- a/options.c +++ b/options.c @@ -83,6 +83,7 @@ int am_starting_up = 1; int relative_paths = -1; int implied_dirs = 1; int numeric_ids = 0; +int msgs2stderr = 0; int allow_8bit_chars = 0; int force_delete = 0; int io_timeout = 0; @@ -795,6 +796,7 @@ static struct poptOption long_options[] = { {"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 }, {"info", 0, POPT_ARG_STRING, 0, OPT_INFO, 0, 0 }, {"debug", 0, POPT_ARG_STRING, 0, OPT_DEBUG, 0, 0 }, + {"msgs2stderr", 0, POPT_ARG_NONE, &msgs2stderr, 0, 0, 0 }, {"quiet", 'q', POPT_ARG_NONE, 0, 'q', 0, 0 }, {"motd", 0, POPT_ARG_VAL, &output_motd, 1, 0, 0 }, {"no-motd", 0, POPT_ARG_VAL, &output_motd, 0, 0, 0 }, diff --git a/rsync.c b/rsync.c index 734a373d..0e635b03 100644 --- a/rsync.c +++ b/rsync.c @@ -45,6 +45,7 @@ extern int gid_ndx; extern int inc_recurse; extern int inplace; extern int flist_eof; +extern int msgs2stderr; extern int keep_dirlinks; extern int make_backups; extern struct file_list *cur_flist, *first_flist, *dir_flist; @@ -278,13 +279,15 @@ int read_ndx_and_attrs(int f_in, int *iflag_ptr, uchar *type_ptr, rprintf(FINFO, "[%s] receiving flist for dir %d\n", who_am_i(), ndx); } - negate_output_levels(); /* turn off all info/debug output */ + if (!msgs2stderr) + negate_output_levels(); /* turn off all info/debug output */ send_msg_int(MSG_FLIST, ndx); start_flist_forward(f_in); flist = recv_file_list(f_in); flist->parent_ndx = ndx; stop_flist_forward(); - negate_output_levels(); /* restore info/debug output */ + if (!msgs2stderr) + negate_output_levels(); /* restore info/debug output */ } iflags = protocol_version >= 29 ? read_shortint(f_in) diff --git a/testsuite/hands.test b/testsuite/hands.test index b60915d0..c12ab0a0 100644 --- a/testsuite/hands.test +++ b/testsuite/hands.test @@ -9,21 +9,23 @@ hands_setup +DEBUG_OPTS="--debug=all5,deltasum0 --msgs2stderr" + # Main script starts here runtest "basic operation" 'checkit "$RSYNC -av \"$fromdir/\" \"$todir\"" "$fromdir/" "$todir"' ln "$fromdir/filelist" "$fromdir/dir" -runtest "hard links" 'checkit "$RSYNC -avH --debug=all5 \"$fromdir/\" \"$todir\"" "$fromdir/" "$todir"' +runtest "hard links" 'checkit "$RSYNC -avH $DEBUG_OPTS \"$fromdir/\" \"$todir\"" "$fromdir/" "$todir"' rm "$todir/text" -runtest "one file" 'checkit "$RSYNC -avH --debug=hlink5 \"$fromdir/\" \"$todir\"" "$fromdir/" "$todir"' +runtest "one file" 'checkit "$RSYNC -avH $DEBUG_OPTS \"$fromdir/\" \"$todir\"" "$fromdir/" "$todir"' echo "extra line" >> "$todir/text" -runtest "extra data" 'checkit "$RSYNC -avH --debug=hlink5 --no-whole-file \"$fromdir/\" \"$todir\"" "$fromdir/" "$todir"' +runtest "extra data" 'checkit "$RSYNC -avH $DEBUG_OPTS --no-whole-file \"$fromdir/\" \"$todir\"" "$fromdir/" "$todir"' cp "$fromdir/text" "$todir/ThisShouldGo" -runtest " --delete" 'checkit "$RSYNC --delete -avH --debug=hlink5 \"$fromdir/\" \"$todir\"" "$fromdir/" "$todir"' +runtest " --delete" 'checkit "$RSYNC --delete -avH $DEBUG_OPTS \"$fromdir/\" \"$todir\"" "$fromdir/" "$todir"' cd "$tmpdir" rm -rf to from/*dir -- 2.34.1