All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] keytable: use DEV_NAME if available
@ 2017-09-02 11:43 Sean Young
  2017-09-02 11:43 ` [PATCH 2/2] keytable: if the protocols cannot be changed, don't try Sean Young
  0 siblings, 1 reply; 2+ messages in thread
From: Sean Young @ 2017-09-02 11:43 UTC (permalink / raw)
  To: linux-media

The result from EVIOCGNAME can be truncated.

Signed-off-by: Sean Young <sean@mess.org>
---
 utils/keytable/keytable.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c
index 5d12ec31..7b0d1acb 100644
--- a/utils/keytable/keytable.c
+++ b/utils/keytable/keytable.c
@@ -271,6 +271,7 @@ struct rc_device {
 	char *sysfs_name;	/* Device sysfs node name */
 	char *input_name;	/* Input device file name */
 	char *drv_name;		/* Kernel driver that implements it */
+	char *dev_name;		/* Kernel device name */
 	char *keytable_name;	/* Keycode table name */
 
 	enum sysfs_ver version; /* sysfs version */
@@ -1076,6 +1077,10 @@ static int get_attribs(struct rc_device *rc_dev, char *sysfs_name)
 			rc_dev->drv_name = malloc(strlen(uevent->value) + 1);
 			strcpy(rc_dev->drv_name, uevent->value);
 		}
+		if (!strcmp(uevent->key, "DEV_NAME")) {
+			rc_dev->dev_name = malloc(strlen(uevent->value) + 1);
+			strcpy(rc_dev->dev_name, uevent->value);
+		}
 		if (!strcmp(uevent->key, "NAME")) {
 			rc_dev->keytable_name = malloc(strlen(uevent->value) + 1);
 			strcpy(rc_dev->keytable_name, uevent->value);
@@ -1416,9 +1421,8 @@ static void show_evdev_attribs(int fd)
 	get_rate(fd, &delay, &period);
 }
 
-static void device_info(int fd, char *prepend)
+static void device_name(int fd, char *prepend)
 {
-	struct input_id id;
 	char buf[32];
 	int rc;
 
@@ -1427,6 +1431,12 @@ static void device_info(int fd, char *prepend)
 		fprintf(stderr,_("%sName: %.*s\n"),prepend, rc, buf);
 	else
 		perror ("EVIOCGNAME");
+}
+
+static void device_info(int fd, char *prepend)
+{
+	struct input_id id;
+	int rc;
 
 	rc = ioctl(fd, EVIOCGID, &id);
 	if (rc >= 0)
@@ -1452,7 +1462,10 @@ static int show_sysfs_attribs(struct rc_device *rc_dev, char *name)
 			fprintf(stderr, _("Found %s (%s) with:\n"),
 				rc_dev->sysfs_name,
 				rc_dev->input_name);
-			fprintf(stderr, _("\tDriver %s, table %s\n"),
+			if (rc_dev->dev_name)
+				fprintf(stderr, _("\tName: %s\n"),
+					rc_dev->dev_name);
+			fprintf(stderr, _("\tDriver: %s, table: %s\n"),
 				rc_dev->drv_name,
 				rc_dev->keytable_name);
 			fprintf(stderr, _("\tSupported protocols: "));
@@ -1461,6 +1474,8 @@ static int show_sysfs_attribs(struct rc_device *rc_dev, char *name)
 			display_proto(rc_dev);
 			fd = open(rc_dev->input_name, O_RDONLY);
 			if (fd > 0) {
+				if (!rc_dev->dev_name)
+					device_name(fd, "\t");
 				device_info(fd, "\t");
 				show_evdev_attribs(fd);
 				close(fd);
@@ -1495,6 +1510,7 @@ int main(int argc, char *argv[])
 				perror(_("Can't open device"));
 				return -1;
 			}
+			device_name(fd, "");
 			device_info(fd, "");
 			close(fd);
 			return 0;
-- 
2.13.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] keytable: if the protocols cannot be changed, don't try
  2017-09-02 11:43 [PATCH 1/2] keytable: use DEV_NAME if available Sean Young
@ 2017-09-02 11:43 ` Sean Young
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Young @ 2017-09-02 11:43 UTC (permalink / raw)
  To: linux-media

Note that if an invalid protocol was selected, we already get the error
"Invalid protocols selected".

Signed-off-by: Sean Young <sean@mess.org>
---
 utils/keytable/keytable.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c
index 7b0d1acb..1fd545b0 100644
--- a/utils/keytable/keytable.c
+++ b/utils/keytable/keytable.c
@@ -23,6 +23,7 @@
 #include <linux/input.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <dirent.h>
 #include <argp.h>
 #include <stdbool.h>
@@ -991,10 +992,14 @@ static int v2_set_protocols(struct rc_device *rc_dev)
 {
 	FILE *fp;
 	char name[4096];
+	struct stat st;
 
 	strcpy(name, rc_dev->sysfs_name);
 	strcat(name, "/protocols");
 
+	if (!stat(name, &st) && !(st.st_mode & 0222))
+		return 0;
+
 	fp = fopen(name, "w");
 	if (!fp) {
 		perror(name);
-- 
2.13.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-02 11:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-02 11:43 [PATCH 1/2] keytable: use DEV_NAME if available Sean Young
2017-09-02 11:43 ` [PATCH 2/2] keytable: if the protocols cannot be changed, don't try Sean Young

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.