Differentiating debug messages from both sides

Wayne Davison wayned at samba.org
Tue Jan 27 08:31:05 GMT 2004


Some of the debug messages that rsync outputs (when verbose >= 2) can
occur on both sides of the connection.  This makes it hard to know which
program is saying what.  Some debug messages deal with this by
outputting a "[PID]" string at the start of the message.  Unfortunately,
the startup message that tells us which pid is which is only output when
verbose >= 3, so there's a bit of a problem if we use this idiom for
messages such as "expanding file_list ..." and "excluding file ..."
(which get output at verbose >= 2 and can occur on both sides).

I'd like to propose a change that prefixes dual-sided messages with [s],
[r], or [g] for the sender, receiver, and generator, respectively.  This
makes them easier to read, and it works at any verbose level.  Here's a
patch.  Let me know what you think.

..wayne..
-------------- next part --------------
--- exclude.c	20 Jan 2004 04:53:59 -0000	1.58
+++ exclude.c	27 Jan 2004 07:36:35 -0000
@@ -27,6 +27,7 @@
 #include "rsync.h"
 
 extern int verbose;
+extern char *who_am_i;
 
 struct exclude_struct **exclude_list;
 struct exclude_struct **local_exclude_list;
@@ -102,7 +103,7 @@ void free_exclude_list(struct exclude_st
 	struct exclude_struct **list = *listp;
 
 	if (verbose > 2)
-		rprintf(FINFO,"clearing exclude list\n");
+		rprintf(FINFO, "[%c] clearing exclude list\n", *who_am_i);
 
 	if (!list)
 		return;
@@ -203,12 +204,14 @@ static void report_exclude_result(char c
 	 * then it is stripped out by make_exclude.  So as a special
 	 * case we add it back in here. */
 
-	if (verbose >= 2)
-		rprintf(FINFO, "%s %s %s because of pattern %s%s\n",
+	if (verbose >= 2) {
+		rprintf(FINFO, "[%c] %s %s %s because of pattern %s%s\n",
+			*who_am_i,
 			ent->include ? "including" : "excluding",
 			name_is_dir ? "directory" : "file",
 			name, ent->pattern,
 			ent->directory ? "/" : "");
+	}
 }
 
 
@@ -250,7 +253,8 @@ void add_exclude(struct exclude_struct *
 		out_of_memory("add_exclude");
 
 	if (verbose > 2) {
-		rprintf(FINFO,"add_exclude(%s,%s)\n",pattern,
+		rprintf(FINFO, "[%c] add_exclude(%s,%s)\n",
+			*who_am_i, pattern,
 			include ? "include" : "exclude");
 	}
 
--- flist.c	27 Jan 2004 01:47:41 -0000	1.174
+++ flist.c	27 Jan 2004 07:36:30 -0000
@@ -46,6 +46,7 @@ extern int recurse;
 extern char curr_dir[MAXPATHLEN];
 extern char *files_from;
 extern int filesfrom_fd;
+extern char *who_am_i;
 
 extern int one_file_system;
 extern int make_backups;
@@ -342,7 +343,8 @@ static void flist_expand(struct file_lis
 		}
 
 		if (verbose >= 2) {
-			rprintf(FINFO, "expand file_list to %.0f bytes, did%s move\n",
+			rprintf(FINFO, "[%c] expand file_list to %.0f bytes, did%s move\n",
+				*who_am_i,
 				(double)sizeof(flist->files[0])
 				* flist->malloced,
 				(new_ptr == flist->files) ? " not" : "");
@@ -781,8 +783,10 @@ struct file_struct *make_file(char *fnam
 
       skip_excludes:
 
-	if (verbose > 2)
-		rprintf(FINFO, "make_file(%s,*,%d)\n", fname, exclude_level);
+	if (verbose > 2) {
+		rprintf(FINFO, "[%c] make_file(%s,*,%d)\n",
+			*who_am_i, fname, exclude_level);
+	}
 
 	file = new(struct file_struct);
 	if (!file)
@@ -1416,8 +1420,8 @@ static void clean_flist(struct file_list
 		return;
 
 	for (i = 0; i < flist->count; i++) {
-		rprintf(FINFO, "[%ld] i=%d %s %s mode=0%o len=%.0f\n",
-			(long) getpid(), i,
+		rprintf(FINFO, "[%c] i=%d %s %s mode=0%o len=%.0f\n",
+			*who_am_i, i,
 			NS(flist->files[i]->dirname),
 			NS(flist->files[i]->basename),
 			(int) flist->files[i]->mode,
--- main.c	27 Jan 2004 08:05:10 -0000	1.185
+++ main.c	27 Jan 2004 07:59:07 -0000
@@ -56,6 +56,8 @@ extern char *remote_filesfrom_file;
 extern char *rsync_path;
 extern char *shell_cmd;
 extern struct file_list *batch_flist;
+extern char *who_am_i;
+
 
 /* there's probably never more than at most 2 outstanding child processes,
  * but set it higher just in case.
@@ -198,7 +200,7 @@ static void show_malloc_stats(void)
 		getpid(),
 		am_server ? "server " : "",
 		am_daemon ? "daemon " : "",
-		am_sender ? "sender" : "receiver");
+		who_am_i);
 	rprintf(FINFO, "  arena:     %10d   (bytes from sbrk)\n", mi.arena);
 	rprintf(FINFO, "  ordblks:   %10d   (chunks not in use)\n", mi.ordblks);
 	rprintf(FINFO, "  smblks:    %10d\n", mi.smblks);
@@ -455,6 +457,8 @@ static int do_recv(int f_in,int f_out,st
 			msleep(20);
 	}
 
+	who_am_i = "generator";
+
 	close(error_pipe[1]);
 	if (f_in != f_out) close(f_in);
 
@@ -754,6 +758,7 @@ static int start_client(int argc, char *
 			argc--;
 			argv++;
 		} else {
+			who_am_i = "sender";
 			am_sender = 1;
 
 			/* rsync:// destination uses rsync server over direct socket */
@@ -817,6 +822,7 @@ static int start_client(int argc, char *
 			argc--;
 		}
 	} else {
+		who_am_i = "sender";
 		am_sender = 1;
 		local_server = 1;
 		shell_path = argv[argc-1];
--- options.c	23 Jan 2004 09:32:50 -0000	1.127
+++ options.c	27 Jan 2004 08:00:54 -0000
@@ -66,6 +66,7 @@ int read_only = 0;
 int module_id = -1;
 int am_server = 0;
 int am_sender = 0;
+char *who_am_i = "receiver";
 char *files_from = NULL;
 int filesfrom_fd = -1;
 char *remote_filesfrom_file = NULL;
@@ -554,6 +555,7 @@ int parse_arguments(int *argc, const cha
 				usage(FERROR);
 				exit_cleanup(RERR_SYNTAX);
 			}
+			who_am_i = "sender";
 			am_sender = 1;
 			break;
 


More information about the rsync mailing list