From 51fb2f5fb3f7420e01a1b0c6b593e9824233e3f4 Mon Sep 17 00:00:00 2001 From: Zhong Jianxin Date: Sat, 5 Aug 2023 20:38:56 +0800 Subject: [PATCH 1/2] Fix device hotplug Fix #27 --- src/jslisten.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/jslisten.c b/src/jslisten.c index 49917df..2eca80f 100644 --- a/src/jslisten.c +++ b/src/jslisten.c @@ -417,10 +417,15 @@ void listenJoy (void) { sysPath = udev_device_get_syspath(mydev); devPath = udev_device_get_devnode(mydev); - if (sysPath != NULL && devPath != NULL && strstr(sysPath, myDevPath) != 0) { - syslog(LOG_NOTICE, "Found Device: %s\n", devPath); - if ((joyFD = open(devPath, O_RDONLY)) < 0) { // Open the file descriptor - syslog(LOG_INFO, "error: failed to open fd\n"); + if (sysPath != NULL && devPath != NULL && strstr(sysPath, "/js") != 0) { + syslog (LOG_NOTICE, "Found Device: %s\n", devPath); + if (joyFD < 0 || strcmp(devPath, myDevPath) == 0) { + // Open the file descriptor + if ((joyFD = open(devPath, O_RDONLY)) < 0) { + syslog (LOG_INFO, "error: failed to open fd\n"); + } else { + syslog (LOG_NOTICE, "Watching: %s\n", devPath); + } } } From d79128689746be2fdaa37fa665068c538e3b8099 Mon Sep 17 00:00:00 2001 From: Zhong Jianxin Date: Mon, 7 Aug 2023 15:31:14 +0800 Subject: [PATCH 2/2] Fix parsing `--mode hold` args --- src/jslisten.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/jslisten.c b/src/jslisten.c index 2eca80f..da949ec 100644 --- a/src/jslisten.c +++ b/src/jslisten.c @@ -654,12 +654,10 @@ void parse_command_line(int argc, char* argv[]) { case 'm': if (strncmp(optarg, MODE_HOLD_STR, strlen(MODE_HOLD_STR)) == 0) { mode = HOLD; - } - if (strncmp(optarg, MODE_PLAIN_STR, strlen(MODE_PLAIN_STR)) == 0) { + } else if (strncmp(optarg, MODE_PLAIN_STR, strlen(MODE_PLAIN_STR)) == 0) { mode = PLAIN; } else { syslog(LOG_WARNING, "--mode %s parameter unknown. Using default.\n", optarg); - } break; case '?':