aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/printk.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier.adi@gmail.com>2007-10-17 02:26:43 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-17 11:42:50 -0400
commit0b15d04af3dd996035d8fa81fc849d049171f9c3 (patch)
treecb0dc973b6485edb6fdf0bcdf4a2eeef9a48adad /kernel/printk.c
parentd823e3e7541c39b4dfe9c79dbf052b4c39da2965 (diff)
printk: add interfaces for external access to the log buffer
Add two new functions for reading the kernel log buffer. The intention is for them to be used by recovery/dump/debug code so the kernel log can be easily retrieved/parsed in a crash scenario, but they are generic enough for other people to dream up other fun uses. [akpm@linux-foundation.org: buncha fixes] Signed-off-by: Mike Frysinger <vapier@gentoo.org> Cc: Robin Getz <rgetz@blackfin.uclinux.org> Cc: Greg Ungerer <gerg@snapgear.com> Cc: Russell King <rmk@arm.linux.org.uk> Cc: Paul Mundt <lethal@linux-sh.org> Acked-by: Tim Bird <tim.bird@am.sony.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/printk.c')
-rw-r--r--kernel/printk.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/kernel/printk.c b/kernel/printk.c
index b2b5c3a22a36..52493474f0ab 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -220,6 +220,58 @@ static inline void boot_delay_msec(void)
220#endif 220#endif
221 221
222/* 222/*
223 * Return the number of unread characters in the log buffer.
224 */
225int log_buf_get_len(void)
226{
227 return logged_chars;
228}
229
230/*
231 * Copy a range of characters from the log buffer.
232 */
233int log_buf_copy(char *dest, int idx, int len)
234{
235 int ret, max;
236 bool took_lock = false;
237
238 if (!oops_in_progress) {
239 spin_lock_irq(&logbuf_lock);
240 took_lock = true;
241 }
242
243 max = log_buf_get_len();
244 if (idx < 0 || idx >= max) {
245 ret = -1;
246 } else {
247 if (len > max)
248 len = max;
249 ret = len;
250 idx += (log_end - max);
251 while (len-- > 0)
252 dest[len] = LOG_BUF(idx + len);
253 }
254
255 if (took_lock)
256 spin_unlock_irq(&logbuf_lock);
257
258 return ret;
259}
260
261/*
262 * Extract a single character from the log buffer.
263 */
264int log_buf_read(int idx)
265{
266 char ret;
267
268 if (log_buf_copy(&ret, idx, 1) == 1)
269 return ret;
270 else
271 return -1;
272}
273
274/*
223 * Commands to do_syslog: 275 * Commands to do_syslog:
224 * 276 *
225 * 0 -- Close the log. Currently a NOP. 277 * 0 -- Close the log. Currently a NOP.