From 58a8c208a9960285e65eecd15a185d03b81a5c18 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Tue, 20 Apr 2010 14:22:13 +0200 Subject: [PATCH 2/4] notifier tty_list/tty_is_active functions --- drivers/char/tty_io.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/tty.h | 5 +++++ 2 files changed, 53 insertions(+), 0 deletions(-) diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index f0463d0..b4d4f60 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -159,6 +159,54 @@ static LIST_HEAD(tty_structs); /* linked list of tty structs */ static ATOMIC_NOTIFIER_HEAD(tty_notifier_list); /** + * tty_list - list all the active ttys + * @cb: callback function called for each active tty + * + * Returns true, if there's active tty for given type and line. + */ +void tty_list(cb_tty_list_t cb, void *data) +{ + struct tty_struct *tty; + + mutex_lock(&tty_mutex); + + list_for_each_entry(tty, &tty_structs, list) + cb(data, tty); + + mutex_unlock(&tty_mutex); +} +EXPORT_SYMBOL_GPL(tty_list); + +/** + * tty_is_active - checks wether the tty is active + * @type: tty driver type + * @line: tty line + * + * Returns true, if there's active tty for given type and line. + */ +bool tty_is_active(int type, int line) +{ + struct tty_struct *tty; + bool found = false; + + mutex_lock(&tty_mutex); + list_for_each_entry(tty, &tty_structs, list) { + struct tty_driver *driver = tty->driver; + + if (driver->type != type) + continue; + + if (line == tty->index) { + found = true; + break; + } + } + mutex_unlock(&tty_mutex); + return found; +} +EXPORT_SYMBOL_GPL(tty_is_active); + +/** * register_tty_notifier - register tty notifier * * Locking: none diff --git a/include/linux/tty.h b/include/linux/tty.h index 7d57719..3945347 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -343,8 +343,13 @@ struct tty_notifier_param { size_t size; }; +typedef void(*cb_tty_list_t)(void *data, struct tty_struct *tty); + extern int register_tty_notifier(struct notifier_block *nb); extern int unregister_tty_notifier(struct notifier_block *nb); +extern void tty_list(cb_tty_list_t cb, void *data); +extern bool tty_is_active(int type, int line); + #endif /* CONFIG_TTY_NOTIFIER */ -- 1.6.6.1