]> mj.ucw.cz Git - libucw.git/blobdiff - lib/log.c
indexer rewritten to generate redirect brackets
[libucw.git] / lib / log.c
index 447e7ad11f1ed65fc719358e7e553b218753879a..d83a84e4bc43549ac64eb8a7faf196fdb97d6828 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -16,8 +16,9 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <time.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <time.h>
+#include <alloca.h>
 
 
-static char *log_progname, *log_name_patt, *log_name;
+static char log_progname[32], *log_name_patt, *log_name;
 static pid_t log_pid;
 static int log_params;
 static int log_name_size;
 static pid_t log_pid;
 static int log_params;
 static int log_name_size;
@@ -71,7 +72,7 @@ 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);
       p = buf = alloca(buflen);
       *p++ = cat;
       p += strftime(p, buflen, " %Y-%m-%d %H:%M:%S ", tm);
-      if (log_progname)
+      if (log_progname[0])
        {
          if (log_pid)
            p += sprintf(p, "[%s (%d)] ", log_progname, log_pid);
        {
          if (log_pid)
            p += sprintf(p, "[%s (%d)] ", log_progname, log_pid);
@@ -100,12 +101,12 @@ vlog(unsigned int cat, const char *msg, va_list args)
          write(2, buf, l + l0);
          return;
        }
          write(2, buf, l + l0);
          return;
        }
-      buflen = l + l0;
+      buflen = l + l0 + 1;
     }
 }
 
 void
     }
 }
 
 void
-log(unsigned int cat, const char *msg, ...)
+log_msg(unsigned int cat, const char *msg, ...)
 {
   va_list args;
 
 {
   va_list args;
 
@@ -155,7 +156,10 @@ void
 log_init(byte *argv0)
 {
   if (argv0)
 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;
+    }
 }
 
 void
 }
 
 void