#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;
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);
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
{
write(2, buf, l + l0);
return;
}
- buflen = l + l0;
+ buflen = l + l0 + 1;
}
}
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);
}
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
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