- log_pid = getpid();
-}
-
-static void
-log_switch(struct tm *tm)
-{
- int fd;
- char name[64];
-
- if (!log_name_patt[0] ||
- log_name[0] && !log_params)
- return;
- strftime(name, sizeof(name), log_name_patt, tm);
- if (!strcmp(name, log_name))
- return;
- strcpy(log_name, name);
- fd = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666);
- if (fd < 0)
- die("Unable to open log file %s: %m", name);
- close(2);
- dup(fd);
- close(fd);
-}
-
-static void
-vlog(unsigned int cat, const char *msg, va_list args)
-{
- time_t tim = time(NULL);
- struct tm *tm = localtime(&tim);
- char buf[32];
-
- log_switch(tm);
- strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm);
- fprintf(stderr, "%c %s ", cat, buf);
- if (log_progname)
+ struct timeval tv;
+ struct tm tm;
+ byte *buf, *p;
+ int buflen = 256;
+ int l, l0, r;
+ va_list args2;
+
+ gettimeofday(&tv, NULL);
+ if (!localtime_r(&tv.tv_sec, &tm))
+ bzero(&tm, sizeof(tm));
+
+ if (log_switch_hook)
+ log_switch_hook(&tm);
+ while (1)