[Devel] [PATCH RH9 1/8] ve/kbd: add file kbd_bind in sysfs, which allow unbind keyboard from tty (v2)

Cyrill Gorcunov gorcunov at gmail.com
Thu Oct 7 18:18:46 MSK 2021


From: Andrey Vagin <avagin at openvz.org>

port of 2.6.32-x diff-ms-input-detach-input-from-console
ported by Dmitry Guryanov <dguryanov at parallels.com>

Signed-off-by: Andrey Vagin <avagin at openvz.org>
Signed-off-by: Dmitry Guryanov <dguryanov at parallels.com>

Author: Andrey Vagin
Email: avagin at openvz.org
Subject: kbd: add file kbd_bind in sysfs, which allow unbind keyboard from tty (v2)
Date: Tue, 18 Jan 2011 13:15:34 +0300

It's necessary when we want move keyboard to CT.

To unbind keyboard need write "unbind" in kbd_bind.
To bind keyboard need write "all" in kbd_bind.
In future we will can send tty "name", that bind keyboard to specified tty.

https://jira.sw.ru/browse/PCLIN-28731

Was requested by Disney - they wanted CT X user not to affect system console.

+++
ve/device: input_mutex isn't static now

port of 2.6.32-x diff-ms-input-unstatic-input_mutex
ported by Dmitry Guryanov <dguryanov at parallels.com>

Signed-off-by: Andrey Vagin <avagin at openvz.org>
Signed-off-by: Dmitry Guryanov <dguryanov at parallels.com>

Author: Andrey Vagin
Email: avagin at openvz.org
Subject: device: input_mutex isn't static now
Date: Tue, 18 Jan 2011 13:15:33 +0300

 https://jira.sw.ru/browse/PCLIN-28731

(cherry picked from commit e099d5a58856d3639475543d211192123c96574d)
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>

khorenko@: Teradici cards have usb ports which can be used for
keyboard input.
---
 drivers/input/input.c     |  2 +-
 drivers/tty/vt/keyboard.c | 74 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index ccaeb2426385..4b3fe7f5b6f4 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -43,7 +43,7 @@ static LIST_HEAD(input_handler_list);
  * be mutually exclusive which simplifies locking in drivers implementing
  * input handlers.
  */
-static DEFINE_MUTEX(input_mutex);
+DEFINE_MUTEX(input_mutex);
 
 static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 };
 
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 4b0d69042ceb..1cafb885ccc1 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -46,6 +46,7 @@
 #include <linux/tty.h>
 #include <linux/uaccess.h>
 #include <linux/vt_kern.h>
+#include <linux/device.h>
 
 #include <asm/irq_regs.h>
 
@@ -1560,7 +1561,7 @@ static bool kbd_match(struct input_handler *handler, struct input_dev *dev)
  * likes it, it can open it and get events from it. In this (kbd_connect)
  * function, we should decide which VT to bind that keyboard to initially.
  */
-static int kbd_connect(struct input_handler *handler, struct input_dev *dev,
+static int __kbd_connect(struct input_handler *handler, struct input_dev *dev,
 			const struct input_device_id *id)
 {
 	struct input_handle *handle;
@@ -1591,13 +1592,82 @@ static int kbd_connect(struct input_handler *handler, struct input_dev *dev,
 	return error;
 }
 
-static void kbd_disconnect(struct input_handle *handle)
+static void __kbd_disconnect(struct input_handle *handle)
 {
 	input_close_device(handle);
 	input_unregister_handle(handle);
 	kfree(handle);
 }
 
+extern struct mutex input_mutex;
+/*
+ * To unbind keyboard need write "unbind" in kbd_bind
+ * To bind keyboard to all TTYs need write "all" in kbd_bind (by default)
+ * To bind keyboard to specified TTY... (not implemented)
+ */
+static ssize_t kbd_bind_store(struct device *dev,
+                                struct device_attribute *attr,
+                                const char *buf, size_t len)
+{
+	struct list_head *node;
+	int ret = -EINVAL;
+	struct input_dev *idev;
+	char *s;
+
+	if (buf[len] != '\0')
+		return -EINVAL;
+
+/*	if (!ve_is_super(get_exec_env()))
+		return -EPERM;
+*/
+	s = strchr(buf, '\n');
+	if (s)
+		*s = '\0';
+
+	mutex_lock(&input_mutex);
+	if (!strcmp(buf, "unbind")) {
+		list_for_each(node, &kbd_handler.h_list) {
+			struct input_handle *handle = container_of(node,
+					struct input_handle, h_node);
+			idev = handle->dev;
+			if (&idev->dev == dev) {
+				__kbd_disconnect(handle);
+				ret = len;
+				break;
+			}
+		}
+	} else if (!strcmp(buf, "all")) {
+		idev = container_of(dev, struct input_dev, dev);
+		ret = __kbd_connect(&kbd_handler, idev, NULL);
+		if (!ret)
+			ret = len;
+	}
+	mutex_unlock(&input_mutex);
+
+	return ret;
+}
+
+static DEVICE_ATTR(kbd_bind, S_IWUSR, NULL , kbd_bind_store);
+
+static int kbd_connect(struct input_handler *handler, struct input_dev *dev,
+			const struct input_device_id *id)
+{
+	int error;
+	error = device_create_file(&dev->dev, &dev_attr_kbd_bind);
+	if (error)
+		return error;
+	error = __kbd_connect(handler, dev, id);
+	if (error)
+		device_remove_file(&dev->dev, &dev_attr_kbd_bind);
+	return error;
+}
+
+static void kbd_disconnect(struct input_handle *handle)
+{
+	device_remove_file(&handle->dev->dev, &dev_attr_kbd_bind);
+	__kbd_disconnect(handle);
+}
+
 /*
  * Start keyboard handler on the new keyboard by refreshing LED state to
  * match the rest of the system.
-- 
2.31.1



More information about the Devel mailing list