From aa7a92872c2d78c69b1363fbe2dbd12516a59919 Mon Sep 17 00:00:00 2001 From: Hosung Kim Date: Sat, 13 Jun 2015 13:15:44 +0900 Subject: [PATCH] [COMMON] printk: add hooking function for exynos-snapshot This commit adds hooking function for gathering kernel log in exynos-snapshot. Change-Id: I4132288aec8664861f2b51873feb52d8a7da981b Signed-off-by: Hosung Kim --- kernel/printk/printk.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index c911f8f7fa2d..c23ba5e402b0 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -586,6 +586,43 @@ static size_t print_process(const struct printk_log *msg, char *buf) #endif module_param_named(process, printk_process, bool, S_IRUGO | S_IWUSR); +#ifdef CONFIG_EXYNOS_SNAPSHOT +static size_t hook_size; +static char hook_text[LOG_LINE_MAX + PREFIX_MAX]; +static void (*func_hook_logbuf)(const char *buf, size_t size); +static size_t msg_print_text(const struct printk_log *msg, + bool syslog, char *buf, size_t size); +void register_hook_logbuf(void (*func)(const char *buf, size_t size)) +{ + unsigned long flags; + + raw_spin_lock_irqsave(&logbuf_lock, flags); + /* + * In register hooking function, we should check messages already + * printed on log_buf. If so, they will be copyied to backup + * exynos log buffer + * */ + if (log_first_seq != log_next_seq) { + unsigned int step_seq, step_idx, start, end; + struct printk_log *msg; + start = log_first_seq; + end = log_next_seq; + step_idx = log_first_idx; + for (step_seq = start; step_seq < end; step_seq++) { + msg = (struct printk_log *)(log_buf + step_idx); + hook_size = msg_print_text(msg, + true, hook_text, LOG_LINE_MAX + PREFIX_MAX); + func(hook_text, hook_size); + step_idx = log_next(step_idx); + } + } + func_hook_logbuf = func; + raw_spin_unlock_irqrestore(&logbuf_lock, flags); +} +EXPORT_SYMBOL(register_hook_logbuf); +#endif + + /* * Define how much of the log buffer we could take at maximum. The value * must be greater than two. Note that only half of the buffer is available @@ -672,6 +709,13 @@ static int log_store(int facility, int level, msg->cpu = smp_processor_id(); msg->in_interrupt = in_interrupt() ? 1 : 0; } +#endif +#ifdef CONFIG_EXYNOS_SNAPSHOT + if (func_hook_logbuf) { + hook_size = msg_print_text(msg, + true, hook_text, LOG_LINE_MAX + PREFIX_MAX); + func_hook_logbuf(hook_text, hook_size); + } #endif /* insert message */ log_next_idx += msg->len; -- 2.20.1