static int log_size = LOG_DEFAULT_SIZE;
static struct log_head *log, *log_end, *oldest, *newest;
static int current_id = 0;
-regex_t pat_prio;
-regex_t pat_tstamp;
+static regex_t pat_prio;
+static regex_t pat_tstamp;
static struct log_head *log_next(struct log_head *h, int size)
{
int priority = 0;
int ret;
+ /* bounce out if we don't have init'ed yet (regmatch etc will blow) */
+ if (!log) {
+ fprintf(stderr, buf);
+ return;
+ }
+
/* strip trailing newline */
if (buf[size - 2] == '\n') {
buf[size - 2] = '\0';
newest = next;
}
+void log_printf(char *fmt, ...)
+{
+ static int buffer_len = 128;
+ static char *buffer;
+ va_list ap;
+ int n = 0;
+
+ do {
+ if (n)
+ buffer_len = n + 1;
+ if (!buffer)
+ buffer = malloc(buffer_len);
+ if (!buffer)
+ return;
+ va_start(ap, fmt);
+ n = vsnprintf(buffer, buffer_len, fmt, ap);
+ va_end(ap);
+ if (n < 1)
+ return;
+ if (n >= buffer_len) {
+ free(buffer);
+ buffer = NULL;
+ }
+ } while (n >= buffer_len);
+
+ log_add(buffer, n, SOURCE_INTERNAL);
+}
+
static void slog_cb(struct ustream *s, int bytes)
{
struct ustream_buf *buf = s->r.head;
struct ustream_fd slog = {
.stream.string_data = true,
- .stream.notify_read = slog_cb,
+ .stream.notify_read = slog_cb,
};
struct ustream_fd klog = {
.stream.string_data = true,
- .stream.notify_read = klog_cb,
+ .stream.notify_read = klog_cb,
};
static int klog_open(void)
return 0;
}
-int log_buffer_size(void)
-{
- return log_size;
-}
-
void log_init(void)
{
regcomp(&pat_prio, "^<([0-9]*)>(.*)", REG_EXTENDED);
syslog_open();
klog_open();
- openlog("procd", LOG_PID, LOG_DAEMON);
+ openlog("sysinit", LOG_CONS, LOG_DAEMON);
+}
+
+void log_shutdown(void)
+{
+ ustream_free(&slog.stream);
+ ustream_free(&klog.stream);
+ close(slog.fd.fd);
+ close(klog.fd.fd);
}