From: Jo-Philipp Wich Date: Wed, 18 Feb 2015 18:25:36 +0000 (+0100) Subject: block: add support for logging to dmesg X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=325d23c5dad92c22720c6d1027c5761aaf12319c;p=project%2Ffstools.git block: add support for logging to dmesg Signed-off-by: Jo-Philipp Wich --- diff --git a/block.c b/block.c index 2726b1c..6eb1933 100644 --- a/block.c +++ b/block.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -41,9 +42,35 @@ #include "libubi/libubi.h" #endif +static int kmsg = 0; + +static void klog(int prio, const char *fmt, ...) +{ + va_list ap; + FILE *f = fopen("/dev/kmsg", "w"); + + if (f) { + fprintf(f, "<%d>", prio); + + va_start(ap, fmt); + vfprintf(f, fmt, ap); + va_end(ap); + + fclose(f); + } +} + +#define KINFO(fmt, ...) do { \ + if (kmsg) klog(LOG_INFO, "block: " fmt, ## __VA_ARGS__); \ + } while (0) + #define ERROR(fmt, ...) do { \ - syslog(LOG_ERR, fmt, ## __VA_ARGS__); \ - fprintf(stderr, "block: "fmt, ## __VA_ARGS__); \ + if (kmsg) \ + klog(LOG_ERR, "block: " fmt, ## __VA_ARGS__); \ + else { \ + syslog(LOG_ERR, fmt, ## __VA_ARGS__); \ + fprintf(stderr, "block: "fmt, ## __VA_ARGS__); \ + } \ } while (0) enum { @@ -1062,6 +1089,8 @@ static int main_extroot(int argc, char **argv) return -1; } + kmsg = 1; + mkblkdev(); cache_load(1);