if (fd == -1) return 0;
if (do_stat(fname, &st) == -1) {
- rprintf(FERROR,"stat(%s) : %s\n", fname, strerror(errno));
+ rsyserr(FERROR, errno, "stat(%s)", fname);
ok = 0;
} else if (lp_strict_modes(module)) {
if ((st.st_mode & 06) != 0) {
}
if (do_stat(filename, &st) == -1) {
- rprintf(FERROR,"stat(%s) : %s\n", filename, strerror(errno));
+ rsyserr(FERROR, errno, "stat(%s)", filename);
ok = 0;
} else if ((st.st_mode & 06) != 0) {
rprintf(FERROR,"password file must not be other-accessible\n");
if (do_rename(fname,fnamebak) != 0) {
/* cygwin (at least version b19) reports EINVAL */
if (errno != ENOENT && errno != EINVAL) {
- rprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
+ rsyserr(FERROR, errno, "rename %s to backup %s", fname, fnamebak);
return 0;
}
} else if (verbose > 1) {
-/*
- Copyright (C) Andrew Tridgell 1998
+/* -*- c-file-style: "linux"; -*-
+
+ Copyright (C) 1998-2000 by Andrew Tridgell
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
if (use_chroot) {
if (chroot(lp_path(i))) {
- rprintf(FERROR,"chroot %s failed\n", lp_path(i));
+ rsyserr(FERROR, errno, "chroot %s failed", lp_path(i));
io_printf(fd,"@ERROR: chroot failed\n");
return -1;
}
if (!push_dir("/", 0)) {
- rprintf(FERROR,"chdir %s failed\n", lp_path(i));
+ rsyserr(FERROR, errno, "chdir %s failed\n", lp_path(i));
io_printf(fd,"@ERROR: chdir failed\n");
return -1;
}
} else {
if (!push_dir(lp_path(i), 0)) {
- rprintf(FERROR,"chdir %s failed\n", lp_path(i));
+ rsyserr(FERROR, errno, "chdir %s failed\n", lp_path(i));
io_printf(fd,"@ERROR: chdir failed\n");
return -1;
}
if (am_root) {
if (setgid(gid)) {
- rprintf(FERROR,"setgid %d failed\n", gid);
+ rsyserr(FERROR, errno, "setgid %d failed", gid);
io_printf(fd,"@ERROR: setgid failed\n");
return -1;
}
if (setuid(uid)) {
- rprintf(FERROR,"setuid %d failed\n", uid);
+ rsyserr(FERROR, errno, "setuid %d failed", uid);
io_printf(fd,"@ERROR: setuid failed\n");
return -1;
}
if ((fd = do_open(lp_pid_file(), O_WRONLY|O_CREAT|O_TRUNC,
0666 & ~orig_umask)) == -1) {
cleanup_set_pid(0);
- rprintf(FLOG,"failed to create pid file %s\n", pid_file);
+ rsyserr(FLOG, errno, "failed to create pid file %s", pid_file);
exit_cleanup(RERR_FILEIO);
}
slprintf(pidbuf, sizeof(pidbuf), "%d\n", pid);
char line[MAXPATHLEN];
if (!f) {
if (fatal) {
- rprintf(FERROR,"%s : %s\n",fname,strerror(errno));
+ rsyserr(FERROR, errno,
+ "failed to open %s file %s",
+ include ? "include" : "exclude",
+ fname);
exit_cleanup(RERR_FILEIO);
}
return list;
-/*
- Copyright (C) Andrew Tridgell 1998
+/* -*- c-file-style: "linux"; -*-
+
+ Copyright (C) 1998-2000 by Andrew Tridgell
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
}
-/* this is the rsync debugging function. Call it with FINFO, FERROR or FLOG */
- void rprintf(enum logcode code, const char *format, ...)
+/* This is the rsync debugging function. Call it with FINFO, FERROR or
+ * FLOG. */
+void rprintf(enum logcode code, const char *format, ...)
{
va_list ap;
char buf[1024];
rwrite(code, buf, len);
}
+
+/* This is like rprintf, but it also tries to print some
+ * representation of the error code. Normally errcode = errno.
+ *
+ * Unlike rprintf, this always adds a newline and there should not be
+ * one in the format string.
+ *
+ * Note that since strerror might involve dynamically loading a
+ * message catalog we need to call it once before chroot-ing. */
+void rsyserr(enum logcode code, int errcode, const char *format, ...)
+{
+ va_list ap;
+ char buf[1024];
+ int len, sys_len;
+ char *sysmsg;
+
+ va_start(ap, format);
+ len = vslprintf(buf, sizeof(buf), format, ap);
+ va_end(ap);
+
+ if (len > sizeof(buf)-1) exit_cleanup(RERR_MESSAGEIO);
+
+ sysmsg = strerror(errcode);
+ sys_len = strlen(sysmsg);
+ if (len + 3 + sys_len > sizeof(buf) - 1)
+ exit_cleanup(RERR_MESSAGEIO);
+
+ strcpy(buf + len, ": ");
+ len += 2;
+ strcpy(buf + len, sysmsg);
+ len += sys_len;
+ strcpy(buf + len, "\n");
+ len++;
+
+ rwrite(code, buf, len);
+}
+
+
+
void rflush(enum logcode code)
{
FILE *f = NULL;
/*
- Copyright (C) Andrew Tridgell 1996
+ Copyright (C) by Andrew Tridgell 1996, 2000
Copyright (C) Paul Mackerras 1996
This program is free software; you can redistribute it and/or modify
#define MPLEX_BASE 7
-enum logcode {FNONE=0, FERROR=1, FINFO=2, FLOG=3};
+enum logcode {FNONE=0, FERROR=1, FINFO=2, FLOG=3 };
#include "errcode.h"
#endif
;
+/* This is just like rprintf, but it also tries to print some
+ * representation of the error code. Normally errcode = errno. */
+void rsyserr(enum logcode, int, const char *, ...)
+#ifdef __GNUC__
+ __attribute__ ((format (printf, 3, 4)))
+#endif
+ ;
+
#ifdef REPLACE_INET_NTOA
#define inet_ntoa rep_inet_ntoa
#endif