Patch for stderr logging

John H. Robinson, IV jhriv at ucsd.edu
Tue Apr 15 05:03:52 EST 2003


Rsync team, and interested parties:

i was attempting to get rsync to launch from tcpserver[0] (an inetd
replacement from djb) and log to stderr for logging via multilog[1]
(syslog replacement by djb) and i was unable to get it to log to stdout/
stderr at all.
    [0] http://cr.yp.to/ucspi-tcp/tcpserver.html 
    [1] http://cr.yp.to/daemontools/multilog.html 

i have attached a patch that allows ``log file=/dev/stderr'' to work.
additionally, since multilog can do its own timestamping, i have made
the timestamping and pid logging optional when using a ``log file=''
option. the rsyncd.conf.{yo,5} have been updated to reflect the changes.
i believe my yodl is a bit different than yours, because the changes to
the .5 are huge.

additionally, the close_all() definition in cleanup.c was changed to
prevent the close_all() definition in proto.h from being changed.

Summary of changes:
  cleanup.c:
    changed definition of close_all()
  clientserver.c:
    no longer redirect stderr to /dev/null
  loadparm.c:
    add "log timestamp" global boolean option
    add "log pid" global boolen option
  log.c:
    respect "log timestamp" and "log pid" options
  rsyncd.conf.yo
    document new options

PS: i am not subscribed to the list. MFT set appropriately.

-- 
John H. Robinson, IV   University of California, San Diego
jhriv at ucsd.edu         Academic Computing Services               http  ((((
TEL: +1 858 534 4062   9500 Gilman Drive                     sbih.org ( )(:[
FAX: +1 858 534 7018   La Jolla CA  92093-0110           spiders.html  ((((
-------------- next part --------------
diff -Nuar rsync-2.5.6/cleanup.c rsync-2.5.6.new/cleanup.c
--- rsync-2.5.6/cleanup.c	Sun Jan 26 19:35:08 2003
+++ rsync-2.5.6.new/cleanup.c	Sun Apr 13 22:04:54 2003
@@ -26,7 +26,7 @@
  * shutdown() of socket connections.  This eliminates the abortive
  * TCP RST sent by a Winsock-based system when the close() occurs.
  **/
-void close_all()
+void close_all(void)
 {
 #ifdef SHUTDOWN_ALL_SOCKETS
 	int max_fd;
diff -Nuar rsync-2.5.6/clientserver.c rsync-2.5.6.new/clientserver.c
--- rsync-2.5.6/clientserver.c	Sun Jan 26 12:08:14 2003
+++ rsync-2.5.6.new/clientserver.c	Sat Apr 12 21:30:21 2003
@@ -576,7 +576,7 @@
 		/* we are running via inetd - close off stdout and
 		   stderr so that library functions (and getopt) don't
 		   try to use them. Redirect them to /dev/null */
-		for (i=1;i<3;i++) {
+		for (i=1;i<2;i++) {
 			close(i); 
 			open("/dev/null", O_RDWR);
 		}
diff -Nuar rsync-2.5.6/loadparm.c rsync-2.5.6.new/loadparm.c
--- rsync-2.5.6/loadparm.c	Sun Apr 13 00:06:02 2003
+++ rsync-2.5.6.new/loadparm.c	Sat Apr 12 23:52:58 2003
@@ -100,6 +100,8 @@
 {
 	char *motd_file;
 	char *log_file;
+	BOOL log_timestamp;
+	BOOL log_pid;
 	char *pid_file;
 	int syslog_facility;
 	char *socket_options;
@@ -267,6 +269,8 @@
   {"syslog facility",  P_ENUM,    P_GLOBAL, &Globals.syslog_facility, enum_facilities,0},
   {"socket options",   P_STRING,  P_GLOBAL, &Globals.socket_options,NULL,  0},
   {"log file",         P_STRING,  P_GLOBAL, &Globals.log_file,      NULL,  0},
+  {"log timestamp",    P_BOOL,    P_GLOBAL, &Globals.log_timestamp, NULL,  0},
+  {"log pid",          P_BOOL,    P_GLOBAL, &Globals.log_pid,       NULL,  0},
   {"pid file",         P_STRING,  P_GLOBAL, &Globals.pid_file,      NULL,  0},
 
   {"timeout",          P_INTEGER, P_LOCAL,  &sDefault.timeout,     NULL,  0},
@@ -305,6 +309,8 @@
 static void init_globals(void)
 {
 	memset(&Globals, 0, sizeof(Globals));
+	Globals.log_timestamp = True;
+	Globals.log_pid = True;
 #ifdef LOG_DAEMON
 	Globals.syslog_facility = LOG_DAEMON;
 #endif
@@ -344,6 +350,8 @@
 
 FN_GLOBAL_STRING(lp_motd_file, &Globals.motd_file)
 FN_GLOBAL_STRING(lp_log_file, &Globals.log_file)
+FN_GLOBAL_BOOL(lp_log_timestamp, &Globals.log_timestamp)
+FN_GLOBAL_BOOL(lp_log_pid, &Globals.log_pid)
 FN_GLOBAL_STRING(lp_pid_file, &Globals.pid_file)
 FN_GLOBAL_STRING(lp_socket_options, &Globals.socket_options)
 FN_GLOBAL_INTEGER(lp_syslog_facility, &Globals.syslog_facility)
diff -Nuar rsync-2.5.6/log.c rsync-2.5.6.new/log.c
--- rsync-2.5.6/log.c	Mon Dec 23 23:42:04 2002
+++ rsync-2.5.6.new/log.c	Sat Apr 12 23:57:54 2003
@@ -137,11 +137,17 @@
 	if (logfname) {
 		if (!logfile)
 			log_open();
-		fprintf(logfile,"%s [%d] %s", 
-			timestring(time(NULL)), (int)getpid(), buf);
+		if (lp_log_timestamp()) {
+			fprintf(logfile,"%s ", timestring(time(NULL)));
+		}
+		if (lp_log_pid()) {
+			fprintf(logfile,"[%d] ", (int)getpid());
+		}
+		fprintf(logfile,"%s", buf);
 		fflush(logfile);
 	} else {
 		syslog(priority, "%s", buf);
+		/*fprintf (stderr, "%s", buf);*/
 	}
 }
 
diff -Nuar rsync-2.5.6/proto.h rsync-2.5.6.new/proto.h
--- rsync-2.5.6/proto.h	Sun Jan 26 19:35:09 2003
+++ rsync-2.5.6.new/proto.h	Sun Apr 13 22:04:56 2003
@@ -119,6 +119,8 @@
 void io_multiplexing_close(void);
 char *lp_motd_file(void);
 char *lp_log_file(void);
+BOOL lp_log_timestamp(void);
+BOOL lp_log_pid(void);
 char *lp_pid_file(void);
 char *lp_socket_options(void);
 int lp_syslog_facility(void);
diff -Nuar rsync-2.5.6/rsyncd.conf.5 rsync-2.5.6.new/rsyncd.conf.5
--- rsync-2.5.6/rsyncd.conf.5	Sun Jan 26 19:07:18 2003
+++ rsync-2.5.6.new/rsyncd.conf.5	Sun Apr 13 22:00:59 2003
@@ -17,7 +17,7 @@
 .PP 
 The file consists of modules and parameters\&. A module begins with the 
 name of the module in square brackets and continues until the next
-module begins\&. Modules contain parameters of the form \'name = value\'\&.
+module begins\&. Modules contain parameters of the form \&'name = value\&'\&.
 .PP 
 The file is line-based - that is, each newline-terminated line represents
 either a comment, a module name or a parameter\&.
@@ -94,9 +94,20 @@
 .IP "\fBlog file\fP" 
 The "log file" option tells the rsync daemon to log
 messages to that file rather than using syslog\&. This is particularly
-useful on systems (such as AIX) where syslog() doesn\'t work for
+useful on systems (such as AIX) where syslog() doesn\&'t work for
 chrooted programs\&.
 .IP 
+.IP "\fBlog timestamp\fP" 
+The "log timestamp" option tells the rsync
+daemon to log the timestamp to the log file whenever any message is
+written\&. Defaults to True\&. This is useful only when the "log file"
+option is used\&.
+.IP 
+.IP "\fBlog pid\fP" 
+The "log pid" option tells the rsync daemon to log
+the pid to the log file whenever any message is written\&. Defaults to
+true\&. This is useful only when the "log file" option is used\&.
+.IP 
 .IP "\fBpid file\fP" 
 The "pid file" option tells the rsync daemon to write
 its process id to that file\&.
@@ -196,7 +207,7 @@
 that the exclude list is not passed to the client and thus only applies on
 the server: that is, it excludes files received by a client when receiving
 from a server and files deleted on a server when sending to a server, but
-it doesn\'t exclude files sent from a client when sending to a server or
+it doesn\&'t exclude files sent from a client when sending to a server or
 files deleted on a client when receiving from a server\&.  
 Only one "exclude" option may be specified, but
 you can use "-" and "+" before patterns to specify exclude/include\&.
@@ -256,7 +267,7 @@
 with a hash (#) is considered a comment and is skipped\&. The passwords
 can contain any characters but be warned that many operating systems
 limit the length of passwords that can be typed at the client end, so
-you may find that passwords longer than 8 characters don\'t work\&. 
+you may find that passwords longer than 8 characters don\&'t work\&. 
 .IP 
 There is no default for the "secrets file" option, you must choose a name
 (such as \f(CW/etc/rsyncd\&.secrets\fP)\&.  The file must normally not be readable
@@ -280,7 +291,7 @@
 .IP 
 .IP o 
 a dotted decimal IPv4 address of the form a\&.b\&.c\&.d, or an IPv6 address
-of the form a:b:c::d:e:f\&. In this case the incoming machine\'s IP address
+of the form a:b:c::d:e:f\&. In this case the incoming machine\&'s IP address
 must match exactly\&.
 .IP 
 .IP o 
@@ -347,7 +358,7 @@
 This tells the rsync server to completely
 ignore files that are not readable by the user\&. This is useful for
 public archives that may have some non-readable files among the
-directories, and the sysadmin doesn\'t want those files to be seen at all\&.
+directories, and the sysadmin doesn\&'t want those files to be seen at all\&.
 .IP 
 .IP "\fBtransfer logging\fP" 
 The "transfer logging" option enables per-file 
@@ -390,7 +401,8 @@
 received for this file
 .IP 
 The default log format is "%o %h [%a] %m (%u) %f %l", and a "%t [%p] "
-is always added to the beginning when using the "log file" option\&.
+is by default added to the beginning when using the "log file" option\&.
+See the "log timestamp" and "log pid" options\&.
 .IP 
 A perl script called rsyncstats to summarize this format is included
 in the rsync source code distribution\&.
@@ -398,7 +410,7 @@
 .IP "\fBtimeout\fP" 
 The "timeout" option allows you to override the
 clients choice for IO timeout for this module\&. Using this option you
-can ensure that rsync won\'t wait on a dead client forever\&. The timeout
+can ensure that rsync won\&'t wait on a dead client forever\&. The timeout
 is specified in seconds\&. A value of zero means no timeout and is the
 default\&. A good choice for anonymous rsync servers may be 600 (giving
 a 10 minute timeout)\&.
@@ -417,7 +429,7 @@
 The "dont compress" option allows you to select
 filenames based on wildcard patterns that should not be compressed
 during transfer\&. Compression is expensive in terms of CPU usage so it
-is usually good to not try to compress files that won\'t compress well,
+is usually good to not try to compress files that won\&'t compress well,
 such as already compressed files\&. 
 .IP 
 The "dont compress" option takes a space separated list of
diff -Nuar rsync-2.5.6/rsyncd.conf.yo rsync-2.5.6.new/rsyncd.conf.yo
--- rsync-2.5.6/rsyncd.conf.yo	Sun Jan 26 19:07:18 2003
+++ rsync-2.5.6.new/rsyncd.conf.yo	Sun Apr 13 22:00:57 2003
@@ -92,6 +92,15 @@
 useful on systems (such as AIX) where syslog() doesn't work for
 chrooted programs.
 
+dit(bf(log timestamp)) The "log timestamp" option tells the rsync
+daemon to log the timestamp to the log file whenever any message is
+written. Defaults to True. This is useful only when the "log file"
+option is used.
+
+dit(bf(log pid)) The "log pid" option tells the rsync daemon to log
+the pid to the log file whenever any message is written. Defaults to
+true. This is useful only when the "log file" option is used.
+
 dit(bf(pid file)) The "pid file" option tells the rsync daemon to write
 its process id to that file.
 
@@ -344,7 +353,8 @@
 )
 
 The default log format is "%o %h [%a] %m (%u) %f %l", and a "%t [%p] "
-is always added to the beginning when using the "log file" option.
+is by default added to the beginning when using the "log file" option.
+See the "log timestamp" and "log pid" options.
 
 A perl script called rsyncstats to summarize this format is included
 in the rsync source code distribution.


More information about the rsync mailing list