diff options
| author | Russell King <rmk@arm.linux.org.uk> | 2004-06-29 05:16:30 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2004-06-29 05:16:30 -0700 |
| commit | d070a4344d28190dbdfeaebc416681a569e2cded (patch) | |
| tree | 34acd1d884b198f949dcd32a96f7fd6667e990c2 | |
| parent | f8bd2a5f6a89fa37b3e896b938b5bda5c643eacb (diff) | |
[PATCH] Provide console_device()
[This patch series has also been separately sent to the architecture
maintainers]
Add console_device() to return the console tty driver structure and the
index. Acquire the console lock while scanning the list of console drivers
to protect us against console driver list manipulations.
Signed-off-by: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
| -rw-r--r-- | drivers/char/tty_io.c | 9 | ||||
| -rw-r--r-- | include/linux/console.h | 1 | ||||
| -rw-r--r-- | kernel/printk.c | 20 |
3 files changed, 23 insertions, 7 deletions
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 280be2c98a19..5e49ad38cff6 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -1363,13 +1363,8 @@ retry_open: } #endif if (device == MKDEV(TTYAUX_MAJOR,1)) { - struct console *c = console_drivers; - for (c = console_drivers; c; c = c->next) { - if (!c->device) - continue; - driver = c->device(c, &index); - if (!driver) - continue; + driver = console_device(&index); + if (driver) { /* Don't let /dev/console block */ filp->f_flags |= O_NONBLOCK; noctty = 1; diff --git a/include/linux/console.h b/include/linux/console.h index c8a8fe4f27b3..ee29ca6d2ae3 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -104,6 +104,7 @@ extern void acquire_console_sem(void); extern void release_console_sem(void); extern void console_conditional_schedule(void); extern void console_unblank(void); +extern struct tty_driver *console_device(int *); extern int is_console_locked(void); /* Some debug stub to catch some of the obvious races in the VT code */ diff --git a/kernel/printk.c b/kernel/printk.c index 9e34ce41beb6..224c37c0e28d 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -684,6 +684,26 @@ void console_unblank(void) EXPORT_SYMBOL(console_unblank); /* + * Return the console tty driver structure and its associated index + */ +struct tty_driver *console_device(int *index) +{ + struct console *c; + struct tty_driver *driver = NULL; + + acquire_console_sem(); + for (c = console_drivers; c != NULL; c = c->next) { + if (!c->device) + continue; + driver = c->device(c, index); + if (driver) + break; + } + release_console_sem(); + return driver; +} + +/* * The console driver calls this routine during kernel initialization * to register the console printing procedure with printk() and to * print any messages that were printed by the kernel before the |
