Matt McCutchen's Web Site
/
rsync
/
rsync.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Mention the latest fixes.
[rsync/rsync.git]
/
log.c
diff --git
a/log.c
b/log.c
index
4abc3d5
..
139f002
100644
(file)
--- a/
log.c
+++ b/
log.c
@@
-39,18
+39,19
@@
extern int protocol_version;
extern int preserve_times;
extern int log_format_has_i;
extern int log_format_has_o_or_i;
extern int preserve_times;
extern int log_format_has_i;
extern int log_format_has_o_or_i;
-extern int
daemon_log
_format_has_o_or_i;
+extern int
logfile
_format_has_o_or_i;
extern mode_t orig_umask;
extern char *auth_user;
extern char *log_format;
extern mode_t orig_umask;
extern char *auth_user;
extern char *log_format;
+extern char *logfile_format;
+extern char *logfile_name;
#if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H
extern iconv_t ic_chck;
#endif
static int log_initialised;
static int logfile_was_closed;
#if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H
extern iconv_t ic_chck;
#endif
static int log_initialised;
static int logfile_was_closed;
-static char *logfname;
-static FILE *logfile;
+static FILE *logfile_fp;
struct stats stats;
int log_got_error = 0;
struct stats stats;
int log_got_error = 0;
@@
-104,10
+105,10
@@
static void logit(int priority, char *buf)
{
if (logfile_was_closed)
logfile_reopen();
{
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);
timestring(time(NULL)), (int)getpid(), buf);
- fflush(logfile);
+ fflush(logfile
_fp
);
} else {
syslog(priority, "%s", buf);
}
} else {
syslog(priority, "%s", buf);
}
@@
-140,14
+141,14
@@
static void syslog_init()
static void logfile_open(void)
{
mode_t old_umask = umask(022 | orig_umask);
static void logfile_open(void)
{
mode_t old_umask = umask(022 | orig_umask);
- logfile
= fopen(logf
name, "a");
+ logfile
_fp = fopen(logfile_
name, "a");
umask(old_umask);
umask(old_umask);
- if (!logfile) {
+ if (!logfile
_fp
) {
int fopen_errno = errno;
/* Rsync falls back to using syslog on failure. */
syslog_init();
rsyserr(FERROR, fopen_errno,
int fopen_errno = errno;
/* Rsync falls back to using syslog on failure. */
syslog_init();
rsyserr(FERROR, fopen_errno,
- "failed to open log-file %s", logfname);
+ "failed to open log-file %s", logf
ile_
name);
rprintf(FINFO, "Ignoring \"log file\" setting.\n");
}
}
rprintf(FINFO, "Ignoring \"log file\" setting.\n");
}
}
@@
-163,9
+164,11
@@
void log_init(void)
* before the chroot. */
timestring(time(NULL));
* before the chroot. */
timestring(time(NULL));
- /* 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)
+ logfile_name = lp_log_file();
+ if (logfile_name && *logfile_name)
logfile_open();
else
syslog_init();
logfile_open();
else
syslog_init();
@@
-173,10
+176,10
@@
void log_init(void)
void logfile_close(void)
{
void logfile_close(void)
{
- if (logfile) {
+ if (logfile
_fp
) {
logfile_was_closed = 1;
logfile_was_closed = 1;
- fclose(logfile);
- logfile = NULL;
+ fclose(logfile
_fp
);
+ logfile
_fp
= NULL;
}
}
}
}
@@
-221,9
+224,6
@@
void rwrite(enum logcode code, char *buf, int len)
if (len < 0)
exit_cleanup(RERR_MESSAGEIO);
if (len < 0)
exit_cleanup(RERR_MESSAGEIO);
- if (quiet && code == FINFO)
- return;
-
if (am_server && msg_fd_out >= 0) {
/* Pass the message to our sibling. */
send_msg((enum msgcode)code, buf, len);
if (am_server && msg_fd_out >= 0) {
/* Pass the message to our sibling. */
send_msg((enum msgcode)code, buf, len);
@@
-235,9
+235,9
@@
void rwrite(enum logcode code, char *buf, int len)
if (code == FCLIENT)
code = FINFO;
if (code == FCLIENT)
code = FINFO;
- else if (am_daemon) {
+ else if (am_daemon
|| logfile_name
) {
static int in_block;
static int in_block;
- char msg[2048];
+ char msg[2048]
, *s
;
int priority = code == FERROR ? LOG_WARNING : LOG_INFO;
if (in_block)
int priority = code == FERROR ? LOG_WARNING : LOG_INFO;
if (in_block)
@@
-246,17
+246,21
@@
void rwrite(enum logcode code, char *buf, int len)
if (!log_initialised)
log_init();
strlcpy(msg, buf, MIN((int)sizeof msg, len + 1));
if (!log_initialised)
log_init();
strlcpy(msg, buf, MIN((int)sizeof msg, len + 1));
- logit(priority, msg);
+ for (s = msg; *s == '\n' && s[1]; s++) {}
+ logit(priority, s);
in_block = 0;
in_block = 0;
- if (code == FLOG ||
!am_server
)
+ if (code == FLOG ||
(am_daemon && !am_server)
)
return;
} else if (code == FLOG)
return;
return;
} else if (code == FLOG)
return;
+ if (quiet && code != FERROR)
+ return;
+
if (am_server) {
/* Pass the message to the non-server side. */
if (am_server) {
/* Pass the message to the non-server side. */
- if (send_msg(code, buf, len))
+ if (send_msg(
(enum msgcode)
code, buf, len))
return;
if (am_daemon) {
/* TODO: can we send the error to the user somehow? */
return;
if (am_daemon) {
/* TODO: can we send the error to the user somehow? */
@@
-395,26
+399,14
@@
void rflush(enum logcode code)
{
FILE *f = NULL;
{
FILE *f = NULL;
- if (am_daemon) {
- return;
- }
-
- if (code == FLOG) {
+ if (am_daemon || code == FLOG)
return;
return;
- }
- if (code == FERROR
) {
+ if (code == FERROR
|| am_server)
f = stderr;
f = stderr;
- }
-
- if (code == FINFO) {
- if (am_server)
- f = stderr;
- else
- f = stdout;
- }
+ else
+ f = stdout;
- if (!f) exit_cleanup(RERR_MESSAGEIO);
fflush(f);
}
fflush(f);
}
@@
-687,12
+679,12
@@
void log_item(struct file_struct *file, struct stats *initial_stats,
{
char *s_or_r = am_sender ? "send" : "recv";
{
char *s_or_r = am_sender ? "send" : "recv";
- if (lp_transfer_logging(module_id)) {
- log_formatted(FLOG, lp_log_format(module_id), s_or_r,
- file, initial_stats, iflags, hlink);
- } else if (log_format && !am_server) {
+ if (log_format && !am_server) {
log_formatted(FNAME, log_format, s_or_r,
file, initial_stats, iflags, hlink);
log_formatted(FNAME, log_format, s_or_r,
file, initial_stats, iflags, hlink);
+ } else if (logfile_format) {
+ log_formatted(FLOG, logfile_format, s_or_r,
+ file, initial_stats, iflags, hlink);
}
}
}
}
@@
-704,7
+696,7
@@
void maybe_log_item(struct file_struct *file, int iflags, int itemizing,
|| log_format_has_i > 1 || (verbose > 1 && log_format_has_i));
int local_change = iflags & ITEM_LOCAL_CHANGE && significant_flags;
if (am_server) {
|| log_format_has_i > 1 || (verbose > 1 && log_format_has_i));
int local_change = iflags & ITEM_LOCAL_CHANGE && significant_flags;
if (am_server) {
- if (
am_daemon
&& !dry_run && see_item)
+ if (
logfile_name
&& !dry_run && see_item)
log_item(file, &stats, iflags, buf);
} else if (see_item || local_change || *buf
|| (S_ISDIR(file->mode) && significant_flags))
log_item(file, &stats, iflags, buf);
} else if (see_item || local_change || *buf
|| (S_ISDIR(file->mode) && significant_flags))
@@
-732,10
+724,10
@@
void log_delete(char *fname, int mode)
ITEM_DELETED, NULL);
}
ITEM_DELETED, NULL);
}
- if (!
am_daemon || dry_run || !lp_transfer_logging(module_id)
)
+ if (!
logfile_name || dry_run || !logfile_format
)
return;
return;
- fmt =
daemon_log_format_has_o_or_i ? lp_log_format(module_id)
: "deleting %n";
+ fmt =
logfile_format_has_o_or_i ? logfile_format
: "deleting %n";
log_formatted(FLOG, fmt, "del.", &file, &stats, ITEM_DELETED, NULL);
}
log_formatted(FLOG, fmt, "del.", &file, &stats, ITEM_DELETED, NULL);
}