]> mj.ucw.cz Git - libucw.git/commitdiff
Don't log pid until log_fork() is called.
authorMartin Mares <mj@ucw.cz>
Sun, 28 Jan 2001 21:40:27 +0000 (21:40 +0000)
committerMartin Mares <mj@ucw.cz>
Sun, 28 Jan 2001 21:40:27 +0000 (21:40 +0000)
lib/log.c

index bc74de5b93e30e250b5b345e7d4b699e794e3639..4d81e85d36d7d068e50bd0f345461a9a845e5fda 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
 #include <unistd.h>
 #include <sys/time.h>
 
-static byte *log_progname;
+static char *log_progname;
 static pid_t log_pid;
 
 void
 log_fork(void)
 {
-  log_pid = 0;
+  log_pid = getpid();
 }
 
 static void
@@ -27,14 +27,23 @@ vlog(unsigned int cat, const char *msg, va_list args)
 {
   time_t tim = time(NULL);
   struct tm *tm = localtime(&tim);
+  char *prog = log_progname ?: "?";
   char buf[32];
 
-  if (!log_pid)
-    log_pid = getpid();
   strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm);
   fprintf(stderr, "%c %s ", cat, buf);
   if (log_progname)
-    fprintf(stderr, "[%s (%d)] ", log_progname, log_pid);
+    {
+      if (log_pid)
+       fprintf(stderr, "[%s (%d)] ", log_progname, log_pid);
+      else
+       fprintf(stderr, "[%s] ", log_progname);
+    }
+  else
+    {
+      if (log_pid)
+       fprintf(stderr, "[%d] ", log_pid);
+    }
   vfprintf(stderr, msg, args);
   fputc('\n', stderr);
   fflush(stderr);