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
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 $
35 #include "ircd_defs.h"
38 #include "sprintf_irc.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
;
59 static struct log_struct log_table
[LAST_LOGFILE
] =
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
}
73 init_main_logfile(void)
76 log_main
= fopen(LPATH
, "a");
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");
106 ilog(ilogfile dest
, const char *format
, ...)
108 FILE *logfile
= *log_table
[dest
].logfile
;
116 va_start(args
, format
);
117 ircvsnprintf(buf
, sizeof(buf
), format
, args
);
120 ircsnprintf(buf2
, sizeof(buf2
), "%s %s\n", smalldate(), buf
);
122 if(fputs(buf2
, logfile
) < 0)
125 *log_table
[dest
].logfile
= NULL
;
132 _iprint(const char *domain
, char *buf
)
134 if (domain
== NULL
|| buf
== NULL
)
137 fprintf(stderr
, "%8s: %s\n", domain
, buf
);
141 inotice(const char *format
, ...)
146 va_start(args
, format
);
147 ircvsnprintf(buf
, sizeof(buf
), format
, args
);
150 _iprint("notice", buf
);
152 ilog(L_MAIN
, "%s", buf
);
156 iwarn(const char *format
, ...)
161 va_start(args
, format
);
162 ircvsnprintf(buf
, sizeof(buf
), format
, args
);
165 _iprint("warning", buf
);
167 ilog(L_MAIN
, "%s", buf
);
171 ierror(const char *format
, ...)
176 va_start(args
, format
);
177 ircvsnprintf(buf
, sizeof(buf
), format
, args
);
180 _iprint("error", buf
);
182 ilog(L_MAIN
, "%s", buf
);
188 static char buf
[MAX_DATE_STRING
];
190 time_t ltime
= CurrentTime
;
192 lt
= localtime(<ime
);
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
);
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
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
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
));