]> mj.ucw.cz Git - libucw.git/blobdiff - lib/log.c
Including <stdarg.h> in lib/lib.h enables us to finally export vlog_msg()
[libucw.git] / lib / log.c
index 3ab60eb4e8866105c01ccd974aa57b6b2cd57549..381f7257830c453e32b5a28b83cffaae15fdc75b 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
 #include <fcntl.h>
 #include <unistd.h>
 #include <time.h>
+#include <alloca.h>
 
-static char *log_progname, *log_name_patt, *log_name;
-static pid_t log_pid;
+static char log_progname[32], *log_name_patt, *log_name;
+char *log_title;
+static int log_pid;
 static int log_params;
 static int log_name_size;
 static int log_switching;
@@ -56,8 +58,8 @@ log_switch(struct tm *tm)
   log_switching--;
 }
 
-static void
-vlog(unsigned int cat, const char *msg, va_list args)
+void
+vlog_msg(unsigned int cat, const char *msg, va_list args)
 {
   time_t tim = time(NULL);
   struct tm *tm = localtime(&tim);
@@ -71,12 +73,12 @@ vlog(unsigned int cat, const char *msg, va_list args)
       p = buf = alloca(buflen);
       *p++ = cat;
       p += strftime(p, buflen, " %Y-%m-%d %H:%M:%S ", tm);
-      if (log_progname)
+      if (log_title)
        {
          if (log_pid)
-           p += sprintf(p, "[%s (%d)] ", log_progname, log_pid);
+           p += sprintf(p, "[%s (%d)] ", log_title, log_pid);
          else
-           p += sprintf(p, "[%s] ", log_progname);
+           p += sprintf(p, "[%s] ", log_title);
        }
       else
        {
@@ -105,12 +107,12 @@ vlog(unsigned int cat, const char *msg, va_list args)
 }
 
 void
-log(unsigned int cat, const char *msg, ...)
+log_msg(unsigned int cat, const char *msg, ...)
 {
   va_list args;
 
   va_start(args, msg);
-  vlog(cat, msg, args);
+  vlog_msg(cat, msg, args);
   va_end(args);
 }
 
@@ -120,9 +122,13 @@ die(byte *msg, ...)
   va_list args;
 
   va_start(args, msg);
-  vlog(L_FATAL, msg, args);
+  vlog_msg(L_FATAL, msg, args);
   va_end(args);
+#ifdef DEBUG_DIE_BY_ABORT
+  abort();
+#else
   exit(1);
+#endif
 }
 
 #ifdef DEBUG
@@ -155,7 +161,11 @@ void
 log_init(byte *argv0)
 {
   if (argv0)
-    log_progname = log_basename(argv0);
+    {
+      strncpy(log_progname, log_basename(argv0), sizeof(log_progname)-1);
+      log_progname[sizeof(log_progname)-1] = 0;
+      log_title = log_progname;
+    }
 }
 
 void