X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/b35d0d8e9ae9c5407c9f781b545f8a66b9caa9d0..58cadc8608fbb2cbc7b74578cd92de4337a4b887:/log.c diff --git a/log.c b/log.c index e79bc220..d440a16f 100644 --- a/log.c +++ b/log.c @@ -27,6 +27,7 @@ */ #include "rsync.h" +static int log_initialised; static char *logfname; static FILE *logfile; static int log_error_fd = -1; @@ -51,7 +52,7 @@ struct { { RERR_SIGNAL , "received SIGUSR1 or SIGINT" }, { RERR_WAITCHILD , "some error returned by waitpid()" }, { RERR_MALLOC , "error allocating core memory buffers" }, - { RERR_PARTIAL , "partial transfer" }, + { RERR_PARTIAL , "some files could not be transferred" }, { RERR_TIMEOUT , "timeout in data send/receive" }, { RERR_CMD_FAILED , "remote shell failed" }, { RERR_CMD_KILLED , "remote shell killed" }, @@ -89,10 +90,10 @@ static struct err_list *err_list_tail; static void err_list_add(int code, char *buf, int len) { struct err_list *el; - el = (struct err_list *)malloc(sizeof(*el)); + el = new(struct err_list); if (!el) exit_cleanup(RERR_MALLOC); el->next = NULL; - el->buf = malloc(len+4); + el->buf = new_array(char, len+4); if (!el->buf) exit_cleanup(RERR_MALLOC); memcpy(el->buf+4, buf, len); SIVAL(el->buf, 0, ((code+MPLEX_BASE)<<24) | len); @@ -146,12 +147,11 @@ static void logit(int priority, char *buf) void log_init(void) { - static int initialised; int options = LOG_PID; time_t t; - if (initialised) return; - initialised = 1; + if (log_initialised) return; + log_initialised = 1; /* this looks pointless, but it is needed in order for the C library on some systems to fetch the timezone info @@ -184,7 +184,7 @@ void log_init(void) #endif } -void log_open() +void log_open(void) { if (logfname && !logfile) { extern int orig_umask; @@ -194,7 +194,7 @@ void log_open() } } -void log_close() +void log_close(void) { if (logfile) { fclose(logfile); @@ -238,16 +238,22 @@ void rwrite(enum logcode code, char *buf, int len) return; } - /* If that fails, try to pass it to the other end. - * - * io_multiplex_write can fail if we do not have a multiplexed - * connection at the moment, in which case we fall through and - * log locally instead. */ + /* next, if we are a server and multiplexing is enabled, + * pass it to the other side. */ if (am_server && io_multiplex_write(code, buf, len)) { return; } - if (am_daemon) { + /* otherwise, if in daemon mode and either we are not a server + * (that is, we are not running --daemon over a remote shell) or + * the log has already been initialised, log the message on this + * side because we don't want the client to see most errors for + * security reasons. We do want early messages when running daemon + * mode over a remote shell to go to the remote side; those will + * fall through to the next case. + * Note that this is only for the time before multiplexing is enabled. + */ + if (am_daemon && (!am_server || log_initialised)) { static int depth; int priority = LOG_INFO; if (code == FERROR) priority = LOG_WARNING; @@ -566,17 +572,3 @@ void log_exit(int code, const char *file, int line) name, code, file, line); } } - -/* - * Log the incoming transfer of a file for interactive use, - * this will be called at the end where the client was run. - * Called when a file starts to be transferred. - */ -void log_transfer(struct file_struct *file, const char *fname) -{ - extern int verbose; - - if (!verbose) return; - - rprintf(FINFO, "%s\n", fname); -}