Remove spy hooks.
[seven.git] / src / s_log.c
blobe65f3e121dbe44332fedaee942288b5f4262f245
1 /*
2 * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
4 * Copyright (C) 2003 Lee H <lee@leeh.co.uk>
5 * Copyright (C) 2003-2005 ircd-ratbox development team
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
11 * 1.Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2.Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3.The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 * $Id: s_log.c 62 2006-09-22 23:51:46Z spb $
34 #include "stdinc.h"
35 #include "ircd_defs.h"
36 #include "s_log.h"
37 #include "s_conf.h"
38 #include "sprintf_irc.h"
39 #include "send.h"
40 #include "client.h"
41 #include "s_serv.h"
43 static FILE *log_main;
44 static FILE *log_user;
45 static FILE *log_fuser;
46 static FILE *log_oper;
47 static FILE *log_foper;
48 static FILE *log_server;
49 static FILE *log_kill;
50 static FILE *log_kline;
51 static FILE *log_ioerror;
53 struct log_struct
55 char **name;
56 FILE **logfile;
59 static struct log_struct log_table[LAST_LOGFILE] =
61 { NULL, &log_main },
62 { &ConfigFileEntry.fname_userlog, &log_user },
63 { &ConfigFileEntry.fname_fuserlog, &log_fuser },
64 { &ConfigFileEntry.fname_operlog, &log_oper },
65 { &ConfigFileEntry.fname_foperlog, &log_foper },
66 { &ConfigFileEntry.fname_serverlog, &log_server },
67 { &ConfigFileEntry.fname_killlog, &log_kill },
68 { &ConfigFileEntry.fname_klinelog, &log_kline },
69 { &ConfigFileEntry.fname_ioerrorlog, &log_ioerror }
72 void
73 init_main_logfile(void)
75 if(log_main == NULL)
76 log_main = fopen(LPATH, "a");
79 void
80 open_logfiles(void)
82 int i;
84 if(log_main != NULL)
85 fclose(log_main);
87 log_main = fopen(LPATH, "a");
89 /* log_main is handled above, so just do the rest */
90 for(i = 1; i < LAST_LOGFILE; i++)
92 /* close open logfiles */
93 if(*log_table[i].logfile != NULL)
95 fclose(*log_table[i].logfile);
96 *log_table[i].logfile = NULL;
99 /* reopen those with paths */
100 if(!EmptyString(*log_table[i].name))
101 *log_table[i].logfile = fopen(*log_table[i].name, "a");
105 void
106 ilog(ilogfile dest, const char *format, ...)
108 FILE *logfile = *log_table[dest].logfile;
109 char buf[BUFSIZE];
110 char buf2[BUFSIZE];
111 va_list args;
113 if(logfile == NULL)
114 return;
116 va_start(args, format);
117 ircvsnprintf(buf, sizeof(buf), format, args);
118 va_end(args);
120 ircsnprintf(buf2, sizeof(buf2), "%s %s\n", smalldate(), buf);
122 if(fputs(buf2, logfile) < 0)
124 fclose(logfile);
125 *log_table[dest].logfile = NULL;
128 fflush(logfile);
131 static void
132 _iprint(const char *domain, char *buf)
134 if (domain == NULL || buf == NULL)
135 return;
137 fprintf(stderr, "%8s: %s\n", domain, buf);
140 void
141 inotice(const char *format, ...)
143 char buf[BUFSIZE];
144 va_list args;
146 va_start(args, format);
147 ircvsnprintf(buf, sizeof(buf), format, args);
148 va_end(args);
150 _iprint("notice", buf);
152 ilog(L_MAIN, "%s", buf);
155 void
156 iwarn(const char *format, ...)
158 char buf[BUFSIZE];
159 va_list args;
161 va_start(args, format);
162 ircvsnprintf(buf, sizeof(buf), format, args);
163 va_end(args);
165 _iprint("warning", buf);
167 ilog(L_MAIN, "%s", buf);
170 void
171 ierror(const char *format, ...)
173 char buf[BUFSIZE];
174 va_list args;
176 va_start(args, format);
177 ircvsnprintf(buf, sizeof(buf), format, args);
178 va_end(args);
180 _iprint("error", buf);
182 ilog(L_MAIN, "%s", buf);
185 const char *
186 smalldate(void)
188 static char buf[MAX_DATE_STRING];
189 struct tm *lt;
190 time_t ltime = CurrentTime;
192 lt = localtime(&ltime);
194 ircsnprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d",
195 lt->tm_year + 1900, lt->tm_mon + 1,
196 lt->tm_mday, lt->tm_hour, lt->tm_min);
198 return buf;
202 * report_error - report an error from an errno.
203 * Record error to log and also send a copy to all *LOCAL* opers online.
205 * text is a *format* string for outputing error. It must
206 * contain only two '%s', the first will be replaced
207 * by the sockhost from the client_p, and the latter will
208 * be taken from sys_errlist[errno].
210 * client_p if not NULL, is the *LOCAL* client associated with
211 * the error.
213 * Cannot use perror() within daemon. stderr is closed in
214 * ircd and cannot be used. And, worse yet, it might have
215 * been reassigned to a normal connection...
217 * Actually stderr is still there IFF ircd was run with -s --Rodder
220 void
221 report_error(const char *text, const char *who, const char *wholog, int error)
223 who = (who) ? who : "";
224 wholog = (wholog) ? wholog : "";
226 sendto_realops_snomask(SNO_DEBUG, L_ALL, text, who, strerror(error));
228 ilog(L_IOERROR, text, wholog, strerror(error));