aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/vt.c
diff options
context:
space:
mode:
authorBernhard Walle <bernhard@bwalle.de>2009-12-14 21:00:43 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-15 11:53:28 -0500
commit5ada918b82399eef3afd6a71e3637697d6bd719f (patch)
tree9bff5251d9d21960726078c2117a0ab19ca25956 /drivers/char/vt.c
parentc95d1e53ed89b75a4d7b68d1cbae4607b1479243 (diff)
vt: introduce and use vt_kmsg_redirect() function
The kernel offers with TIOCL_GETKMSGREDIRECT ioctl() the possibility to redirect the kernel messages to a specific console. However, since it's not possible to switch to the kernel message console after a panic(), it would be nice if the kernel would print the panic message on the current console. This patch series adds a new interface to access the global kmsg_redirect variable by a function to be able to use it in code where CONFIG_VT_CONSOLE is not set (kernel/panic.c). This patch: Instead of using and exporting a global value kmsg_redirect, introduce a function vt_kmsg_redirect() that both can set and return the console where messages are printed. Change all users of kmsg_redirect (the VT code itself and kernel/power.c) to the new interface. The main advantage is that vt_kmsg_redirect() can also be used when CONFIG_VT_CONSOLE is not set. Signed-off-by: Bernhard Walle <bernhard@bwalle.de> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/vt.c')
-rw-r--r--drivers/char/vt.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 1e3d728dbf7e..e43fbc66aef0 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -184,12 +184,10 @@ static DECLARE_WORK(console_work, console_callback);
184 * fg_console is the current virtual console, 184 * fg_console is the current virtual console,
185 * last_console is the last used one, 185 * last_console is the last used one,
186 * want_console is the console we want to switch to, 186 * want_console is the console we want to switch to,
187 * kmsg_redirect is the console for kernel messages,
188 */ 187 */
189int fg_console; 188int fg_console;
190int last_console; 189int last_console;
191int want_console = -1; 190int want_console = -1;
192int kmsg_redirect;
193 191
194/* 192/*
195 * For each existing display, we have a pointer to console currently visible 193 * For each existing display, we have a pointer to console currently visible
@@ -2434,6 +2432,37 @@ struct tty_driver *console_driver;
2434 2432
2435#ifdef CONFIG_VT_CONSOLE 2433#ifdef CONFIG_VT_CONSOLE
2436 2434
2435/**
2436 * vt_kmsg_redirect() - Sets/gets the kernel message console
2437 * @new: The new virtual terminal number or -1 if the console should stay
2438 * unchanged
2439 *
2440 * By default, the kernel messages are always printed on the current virtual
2441 * console. However, the user may modify that default with the
2442 * TIOCL_SETKMSGREDIRECT ioctl call.
2443 *
2444 * This function sets the kernel message console to be @new. It returns the old
2445 * virtual console number. The virtual terminal number 0 (both as parameter and
2446 * return value) means no redirection (i.e. always printed on the currently
2447 * active console).
2448 *
2449 * The parameter -1 means that only the current console is returned, but the
2450 * value is not modified. You may use the macro vt_get_kmsg_redirect() in that
2451 * case to make the code more understandable.
2452 *
2453 * When the kernel is compiled without CONFIG_VT_CONSOLE, this function ignores
2454 * the parameter and always returns 0.
2455 */
2456int vt_kmsg_redirect(int new)
2457{
2458 static int kmsg_con;
2459
2460 if (new != -1)
2461 return xchg(&kmsg_con, new);
2462 else
2463 return kmsg_con;
2464}
2465
2437/* 2466/*
2438 * Console on virtual terminal 2467 * Console on virtual terminal
2439 * 2468 *
@@ -2448,6 +2477,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
2448 const ushort *start; 2477 const ushort *start;
2449 ushort cnt = 0; 2478 ushort cnt = 0;
2450 ushort myx; 2479 ushort myx;
2480 int kmsg_console;
2451 2481
2452 /* console busy or not yet initialized */ 2482 /* console busy or not yet initialized */
2453 if (!printable) 2483 if (!printable)
@@ -2455,8 +2485,9 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
2455 if (!spin_trylock(&printing_lock)) 2485 if (!spin_trylock(&printing_lock))
2456 return; 2486 return;
2457 2487
2458 if (kmsg_redirect && vc_cons_allocated(kmsg_redirect - 1)) 2488 kmsg_console = vt_get_kmsg_redirect();
2459 vc = vc_cons[kmsg_redirect - 1].d; 2489 if (kmsg_console && vc_cons_allocated(kmsg_console - 1))
2490 vc = vc_cons[kmsg_console - 1].d;
2460 2491
2461 /* read `x' only after setting currcons properly (otherwise 2492 /* read `x' only after setting currcons properly (otherwise
2462 the `x' macro will read the x of the foreground console). */ 2493 the `x' macro will read the x of the foreground console). */
@@ -2613,7 +2644,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2613 ret = set_vesa_blanking(p); 2644 ret = set_vesa_blanking(p);
2614 break; 2645 break;
2615 case TIOCL_GETKMSGREDIRECT: 2646 case TIOCL_GETKMSGREDIRECT:
2616 data = kmsg_redirect; 2647 data = vt_get_kmsg_redirect();
2617 ret = __put_user(data, p); 2648 ret = __put_user(data, p);
2618 break; 2649 break;
2619 case TIOCL_SETKMSGREDIRECT: 2650 case TIOCL_SETKMSGREDIRECT:
@@ -2623,7 +2654,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2623 if (get_user(data, p+1)) 2654 if (get_user(data, p+1))
2624 ret = -EFAULT; 2655 ret = -EFAULT;
2625 else 2656 else
2626 kmsg_redirect = data; 2657 vt_kmsg_redirect(data);
2627 } 2658 }
2628 break; 2659 break;
2629 case TIOCL_GETFGCONSOLE: 2660 case TIOCL_GETFGCONSOLE: