X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/blobdiff_plain/a56690e21f75e41f17ea693842d82f37e3d64f4a..ac81cbf8e67d98bd0045ddba2902bdc6f6accebf:/log-file.diff diff --git a/log-file.diff b/log-file.diff index 5e33379..7bfc8bc 100644 --- a/log-file.diff +++ b/log-file.diff @@ -1,9 +1,9 @@ -This patch allows a non-daemon server and a client rsync to log what they +This patch allows a non-daemon server and/or a client rsync to log what they are doing, similar to how a daemon logs its actions. --- old/cleanup.c +++ new/cleanup.c -@@ -21,6 +21,7 @@ +@@ -21,10 +21,12 @@ #include "rsync.h" @@ -11,24 +11,28 @@ are doing, similar to how a daemon logs its actions. extern int io_error; extern int keep_partial; extern int log_got_error; -@@ -149,7 +150,7 @@ void _exit_cleanup(int code, const char + extern char *partial_dir; ++extern char *logfile_name; + + #ifdef HAVE_SIGACTION + static struct sigaction sigact; +@@ -149,7 +151,7 @@ void _exit_cleanup(int code, const char code = RERR_PARTIAL; } - if (code) -+ if (code || am_server) ++ if (code || am_daemon || (am_server && logfile_name)) log_exit(code, file, line); if (verbose > 2) { --- old/clientserver.c +++ new/clientserver.c -@@ -44,11 +44,15 @@ extern int protocol_version; +@@ -44,10 +44,14 @@ extern int protocol_version; extern int io_timeout; extern int no_detach; extern int default_af_hint; +extern int logfile_format_has_i; +extern int logfile_format_has_o_or_i; - extern int log_initialised; extern mode_t orig_umask; extern char *bind_address; extern char *sockopts; @@ -38,7 +42,7 @@ are doing, similar to how a daemon logs its actions. extern char *files_from; extern char *tmpdir; extern struct chmod_mode_struct *chmod_modes; -@@ -56,8 +60,6 @@ extern struct filter_list_struct server_ +@@ -55,8 +59,6 @@ extern struct filter_list_struct server_ char *auth_user; int read_only = 0; @@ -47,7 +51,7 @@ are doing, similar to how a daemon logs its actions. int module_id = -1; struct chmod_mode_struct *daemon_chmod_modes; -@@ -330,11 +332,12 @@ static int rsync_module(int f_in, int f_ +@@ -329,11 +331,12 @@ static int rsync_module(int f_in, int f_ read_only = 1; if (lp_transfer_logging(i)) { @@ -65,34 +69,6 @@ are doing, similar to how a daemon logs its actions. } am_root = (MY_UID() == 0); -@@ -395,6 +398,7 @@ static int rsync_module(int f_in, int f_ - parse_rule(&server_filter_list, p, MATCHFLG_WORD_SPLIT, - XFLG_ABS_IF_SLASH | XFLG_OLD_PREFIXES); - -+ logfile_name = lp_log_file(); - log_init(); - - #ifdef HAVE_PUTENV -@@ -742,8 +746,10 @@ int start_daemon(int f_in, int f_out) - if (!lp_load(config_file, 0)) - exit_cleanup(RERR_SYNTAX); - -- if (!log_initialised) -+ if (!log_initialised) { -+ logfile_name = lp_log_file(); - log_init(); -+ } - - if (!am_server) { - set_socket_options(f_in, "SO_KEEPALIVE"); -@@ -842,6 +848,7 @@ int daemon_main(void) - if (bind_address == NULL && *lp_bind_address()) - bind_address = lp_bind_address(); - -+ logfile_name = lp_log_file(); - log_init(); - - rprintf(FLOG, "rsyncd version %s starting, listening on port %d\n", --- old/flist.c +++ new/flist.c @@ -95,15 +95,15 @@ static int show_filelist_p(void) @@ -150,7 +126,7 @@ are doing, similar to how a daemon logs its actions. extern int am_root; extern int am_server; extern int am_daemon; -@@ -663,7 +663,7 @@ static int try_dests_reg(struct file_str +@@ -661,7 +661,7 @@ static int try_dests_reg(struct file_str } else if (itemizing) itemize(file, ndx, 0, stp, 0, 0, NULL); if (verbose > 1 && maybe_ATTRS_REPORT) { @@ -159,7 +135,7 @@ are doing, similar to how a daemon logs its actions. ? FCLIENT : FINFO; rprintf(code, "%s is uptodate\n", fname); } -@@ -686,7 +686,7 @@ static int try_dests_reg(struct file_str +@@ -684,7 +684,7 @@ static int try_dests_reg(struct file_str if (maybe_ATTRS_REPORT && ((!itemizing && verbose && match_level == 2) || (verbose > 1 && match_level == 3))) { @@ -168,7 +144,7 @@ are doing, similar to how a daemon logs its actions. ? FCLIENT : FINFO; rprintf(code, "%s%s\n", fname, match_level == 3 ? " is uptodate" : ""); -@@ -742,7 +742,7 @@ static int try_dests_non(struct file_str +@@ -746,7 +746,7 @@ static int try_dests_non(struct file_str itemize(file, ndx, 0, &st, changes, 0, lp); } if (verbose > 1 && maybe_ATTRS_REPORT) { @@ -177,7 +153,7 @@ are doing, similar to how a daemon logs its actions. ? FCLIENT : FINFO; rprintf(code, "%s is uptodate\n", fname); } -@@ -1304,9 +1304,9 @@ void generate_files(int f_out, struct fi +@@ -1309,9 +1309,9 @@ void generate_files(int f_out, struct fi if (protocol_version >= 29) { itemizing = 1; maybe_ATTRS_REPORT = log_format_has_i ? 0 : ATTRS_REPORT; @@ -191,7 +167,7 @@ are doing, similar to how a daemon logs its actions. } else if (!am_server) { --- old/log.c +++ new/log.c -@@ -44,16 +44,17 @@ extern int protocol_version; +@@ -44,18 +44,19 @@ extern int protocol_version; extern int preserve_times; extern int log_format_has_i; extern int log_format_has_o_or_i; @@ -206,19 +182,37 @@ are doing, similar to how a daemon logs its actions. extern iconv_t ic_chck; #endif + static int log_initialised; static int logfile_was_closed; -static char *logfname; - static FILE *logfile; +-static FILE *logfile; ++static FILE *logfile_fp; struct stats stats; + int log_got_error = 0; +@@ -109,10 +110,10 @@ static void logit(int priority, char *bu + { + if (logfile_was_closed) + logfile_reopen(); +- if (logfile) { +- fprintf(logfile,"%s [%d] %s", ++ if (logfile_fp) { ++ fprintf(logfile_fp, "%s [%d] %s", + timestring(time(NULL)), (int)getpid(), buf); +- fflush(logfile); ++ fflush(logfile_fp); + } else { + syslog(priority, "%s", buf); + } @@ -145,14 +146,14 @@ static void syslog_init() static void logfile_open(void) { mode_t old_umask = umask(022 | orig_umask); - logfile = fopen(logfname, "a"); -+ logfile = fopen(logfile_name, "a"); ++ logfile_fp = fopen(logfile_name, "a"); umask(old_umask); - if (!logfile) { +- if (!logfile) { ++ if (!logfile_fp) { int fopen_errno = errno; /* Rsync falls back to using syslog on failure. */ syslog_init(); @@ -228,30 +222,48 @@ are doing, similar to how a daemon logs its actions. rprintf(FINFO, "Ignoring \"log file\" setting.\n"); } } -@@ -171,9 +172,7 @@ void log_init(void) +@@ -171,9 +172,11 @@ void log_init(void) t = time(NULL); localtime(&t); - /* optionally use a log file instead of syslog */ - logfname = lp_log_file(); - if (logfname && *logfname) ++ /* Optionally use a log file instead of syslog. (Non-daemon ++ * rsyncs will have already set logfile_name, as needed.) */ ++ if (am_daemon) ++ logfile_name = lp_log_file(); + if (logfile_name && *logfile_name) logfile_open(); else syslog_init(); -@@ -243,9 +242,9 @@ void rwrite(enum logcode code, char *buf +@@ -181,10 +184,10 @@ void log_init(void) + + void logfile_close(void) + { +- if (logfile) { ++ if (logfile_fp) { + logfile_was_closed = 1; +- fclose(logfile); +- logfile = NULL; ++ fclose(logfile_fp); ++ logfile_fp = NULL; + } + } + +@@ -243,9 +246,9 @@ void rwrite(enum logcode code, char *buf if (code == FCLIENT) code = FINFO; - else if (am_daemon) { -+ else if (logfile_name) { /* always non-NULL in the daemon */ ++ else if (am_daemon || logfile_name) { static int in_block; - char msg[2048]; + char msg[2048], *s; int priority = code == FERROR ? LOG_WARNING : LOG_INFO; if (in_block) -@@ -254,10 +253,11 @@ void rwrite(enum logcode code, char *buf +@@ -254,10 +257,11 @@ void rwrite(enum logcode code, char *buf if (!log_initialised) log_init(); strlcpy(msg, buf, MIN((int)sizeof msg, len + 1)); @@ -265,7 +277,7 @@ are doing, similar to how a daemon logs its actions. return; } else if (code == FLOG) return; -@@ -403,26 +403,14 @@ void rflush(enum logcode code) +@@ -403,26 +407,14 @@ void rflush(enum logcode code) { FILE *f = NULL; @@ -296,7 +308,7 @@ are doing, similar to how a daemon logs its actions. fflush(f); } -@@ -695,12 +683,12 @@ void log_item(struct file_struct *file, +@@ -695,12 +687,12 @@ void log_item(struct file_struct *file, { char *s_or_r = am_sender ? "send" : "recv"; @@ -313,7 +325,7 @@ are doing, similar to how a daemon logs its actions. } } -@@ -712,7 +700,7 @@ void maybe_log_item(struct file_struct * +@@ -712,7 +704,7 @@ void maybe_log_item(struct file_struct * || log_format_has_i > 1 || (verbose > 1 && log_format_has_i)); int local_change = iflags & ITEM_LOCAL_CHANGE && significant_flags; if (am_server) { @@ -322,7 +334,7 @@ are doing, similar to how a daemon logs its actions. log_item(file, &stats, iflags, buf); } else if (see_item || local_change || *buf || (S_ISDIR(file->mode) && significant_flags)) -@@ -740,10 +728,10 @@ void log_delete(char *fname, int mode) +@@ -740,10 +732,10 @@ void log_delete(char *fname, int mode) ITEM_DELETED, NULL); }