1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
From 33949820c7029bde6a22cbe277ed5edee82255ca Mon Sep 17 00:00:00 2001
From: Jiri Olsa <Jiri Olsa jolsa@redhat.com>
Date: Wed, 14 Apr 2010 12:04:23 +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 1f77159..4375844 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
|