Apply minor fixes from patches@, SF tracker, and others.
[ircu2.10.12-pk.git] / ircd / ircd_log.c
index ab65f3b563e1c6d26a50609b9efb0ecddd18317a..c9dc203447696ad6881840d61620782a3cf48209 100644 (file)
  *
  *   $Id$
  */
+#include "config.h"
+
 #include "ircd_log.h"
 #include "client.h"
-#include "config.h"
 #include "ircd_alloc.h"
 #include "ircd_reply.h"
 #include "ircd_snprintf.h"
@@ -40,6 +41,8 @@
 #include <fcntl.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/uio.h>
@@ -232,7 +235,7 @@ log_debug_reopen(void)
 void
 log_debug_init(int usetty)
 {
-  logInfo.dbfile = MyMalloc(sizeof(struct LogFile));
+  logInfo.dbfile = (struct LogFile*) MyMalloc(sizeof(struct LogFile));
 
   logInfo.dbfile->next = 0; /* initialize debugging filename */
   logInfo.dbfile->prev_p = 0;
@@ -392,7 +395,7 @@ log_vwrite(enum LogSys subsys, enum LogLevel severity, unsigned int flags,
 
   /* Build the basic log string */
   vd.vd_format = fmt;
-  vd.vd_args = vl;
+  va_copy(vd.vd_args, vl);
 
   /* save the length for writev */
   /* Log format: "SYSTEM [SEVERITY]: log message" */
@@ -415,7 +418,7 @@ log_vwrite(enum LogSys subsys, enum LogLevel severity, unsigned int flags,
     vector[0].iov_base = timebuf;
     vector[1].iov_base = buf;
 
-    vector[2].iov_base = "\n"; /* terminate lines with a \n */
+    vector[2].iov_base = (void*) "\n"; /* terminate lines with a \n */
     vector[2].iov_len = 1;
 
     /* write it out to the log file */
@@ -435,15 +438,16 @@ log_vwrite(enum LogSys subsys, enum LogLevel severity, unsigned int flags,
 /* log kills for fun and profit */
 void
 log_write_kill(const struct Client *victim, const struct Client *killer,
-              const char *inpath, const char *path)
+              const char *inpath, const char *path, const char *msg)
 {
   if (MyUser(victim))
     log_write(IsServer(killer) ? LS_SERVKILL : LS_OPERKILL, L_TRACE, 0,
-             "A local client %#C KILLED by %#C Path: %s!%s",
-             victim, killer, inpath, path);
+             "A local client %#C KILLED by %#C Path: %s!%s %s",
+             victim, killer, inpath, path, msg);
   else
     log_write(IsServer(killer) ? LS_SERVKILL : LS_OPERKILL, L_TRACE, 0,
-             "KILL from %C For %C Path: %s!%s", killer, victim, inpath, path);
+             "KILL from %C For %C Path: %s!%s %s", killer, victim, inpath,
+             path, msg);
 }
 
 /* return a struct LogFile for a specific filename--reference counted */
@@ -465,7 +469,7 @@ log_file_create(const char *file)
     tmp = logInfo.freelist;
     logInfo.freelist = tmp->next;
   } else /* allocate a new one */
-    tmp = MyMalloc(sizeof(struct LogFile));
+    tmp = (struct LogFile*) MyMalloc(sizeof(struct LogFile));
 
   tmp->fd = -1; /* initialize the structure */
   tmp->ref = 1;
@@ -633,7 +637,8 @@ log_set_file(const char *subsys, const char *filename)
     desc->mark &= ~LOG_MARK_FILE; /* file has been reset to defaults */
 
   /* no change, don't go to the trouble of destroying and recreating */
-  if (desc->file && filename && !strcmp(desc->file->file, filename))
+  if (desc->file && desc->file->file && filename &&
+      !strcmp(desc->file->file, filename))
     return 0;
 
   /* debug log is special, since it has to be opened on fd 2 */
@@ -828,7 +833,7 @@ log_feature_unmark(void)
 }
 
 /* Reset unmarked fields to defaults... */
-void
+int
 log_feature_mark(int flag)
 {
   int i;
@@ -854,6 +859,8 @@ log_feature_mark(int flag)
     if (!(logDesc[i].mark & LOG_MARK_LEVEL)) /* set default level */
       logDesc[i].level = L_DEFAULT;
   }
+
+  return 0; /* we don't have a notify handler */
 }
 
 /* Report feature settings */
@@ -862,10 +869,12 @@ log_feature_report(struct Client *to, int flag)
 {
   int i;
 
-  for (i = 0; i < LS_LAST_SYSTEM; i++) {
+  for (i = 0; i < LS_LAST_SYSTEM; i++)
+  {
     if (logDesc[i].mark & LOG_MARK_FILE) /* report file */
       send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F LOG %s FILE %s",
-                logDesc[i].name, logDesc[i].file->file);
+                 logDesc[i].name, (logDesc[i].file && logDesc[i].file->file ?
+                                   logDesc[i].file->file : "(terminal)"));
 
     if (logDesc[i].mark & LOG_MARK_FACILITY) /* report facility */
       send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F LOG %s FACILITY %s",