static int _ulog_threshold = LOG_DEBUG;
static int _ulog_initialized = 0;
static const char *_ulog_ident = NULL;
+static struct udebug_buf *udb = NULL;
static const char *ulog_default_ident(void)
{
FILE *self;
static char line[64];
char *p = NULL;
+ char *sbuf;
if ((self = fopen("/proc/self/status", "r")) != NULL) {
while (fgets(line, sizeof(line), self)) {
if (!strncmp(line, "Name:", 5)) {
- strtok(line, "\t\n");
- p = strtok(NULL, "\t\n");
+ strtok_r(line, "\t\n", &sbuf);
+ p = strtok_r(NULL, "\t\n", &sbuf);
break;
}
}
_ulog_initialized = 1;
}
+__attribute__((format(printf, 2, 0)))
static void ulog_kmsg(int priority, const char *fmt, va_list ap)
{
FILE *kmsg;
- if ((kmsg = fopen("/dev/kmsg", "w")) != NULL) {
+ if ((kmsg = fopen("/dev/kmsg", "r+")) != NULL) {
fprintf(kmsg, "<%u>", priority);
if (_ulog_ident)
}
}
+__attribute__((format(printf, 2, 0)))
static void ulog_stdio(int priority, const char *fmt, va_list ap)
{
FILE *out = stderr;
- if (priority == LOG_INFO || priority == LOG_NOTICE)
- out = stdout;
-
if (_ulog_ident)
fprintf(out, "%s: ", _ulog_ident);
vfprintf(out, fmt, ap);
}
+__attribute__((format(printf, 2, 0)))
static void ulog_syslog(int priority, const char *fmt, va_list ap)
{
vsyslog(priority, fmt, ap);
}
+void ulog_udebug(struct udebug_buf *_udb)
+{
+ udb = _udb;
+}
+
void ulog_open(int channels, int facility, const char *ident)
{
+ ulog_close();
+
_ulog_channels = channels;
_ulog_facility = facility;
_ulog_ident = ident;
}
+void ulog_close(void)
+{
+ if (!_ulog_initialized)
+ return;
+
+ if (_ulog_channels & ULOG_SYSLOG)
+ closelog();
+
+ _ulog_initialized = 0;
+}
+
void ulog_threshold(int threshold)
{
_ulog_threshold = threshold;
{
va_list ap;
+ if (udb) {
+ va_start(ap, fmt);
+ udebug_entry_init(udb);
+ udebug_entry_vprintf(udb, fmt, ap);
+ udebug_entry_add(udb);
+ va_end(ap);
+ }
+
if (priority > _ulog_threshold)
return;