2 Copyright (C) Andrew Tridgell 1998
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 logging and utility functions
28 static void logit(int priority, char *buf)
31 fprintf(logfile,"%s", buf);
34 syslog(priority, "%s", buf);
40 static int initialised;
41 int options = LOG_PID;
44 if (initialised) return;
48 logfile = fopen(lp_log_file(), "a");
53 options |= LOG_NDELAY;
57 openlog("rsyncd", options, lp_syslog_facility());
59 openlog("rsyncd", options);
63 logit(LOG_INFO,"rsyncd started\n");
66 /* this looks pointless, but it is needed in order for the
67 C library on some systems to fetch the timezone info
74 /* this is the rsync debugging function. Call it with FINFO or FERROR */
75 void rprintf(int fd, const char *format, ...)
82 /* recursion can happen with certain fatal conditions */
90 len = vslprintf(buf, sizeof(buf)-1, format, ap);
93 if (len < 0) exit_cleanup(1);
95 if (len > sizeof(buf)-1) exit_cleanup(1);
100 int priority = LOG_INFO;
101 if (fd == FERROR) priority = LOG_WARNING;
104 if (!io_multiplex_write(fd, buf, strlen(buf))) {
105 logit(priority, buf);
117 extern int am_server;
124 if (!f) exit_cleanup(1);
126 if (fwrite(buf, len, 1, f) != 1) exit_cleanup(1);
128 if (buf[len-1] == '\r' || buf[len-1] == '\n') fflush(f);
136 extern int am_daemon;
147 extern int am_server;
154 if (!f) exit_cleanup(1);