diff --git a/src/main/c/Posix/PosixHelperFunctions.c b/src/main/c/Posix/PosixHelperFunctions.c index 3e565659..7fa69007 100644 --- a/src/main/c/Posix/PosixHelperFunctions.c +++ b/src/main/c/Posix/PosixHelperFunctions.c @@ -1640,37 +1640,41 @@ int verifyAndSetUserPortGroup(const char *portFile) // Attempt to acquire access if not available if (!userCanAccess) { - // Check if the user is part of the group that owns the port + // Ensure that the port still exists struct stat fileStats; - gid_t *userGroups = (gid_t*)malloc(numGroups * sizeof(gid_t)); - if ((stat(portFile, &fileStats) == 0) && (getgroups(numGroups, userGroups) >= 0)) - for (int i = 0; i < numGroups; ++i) - if (userGroups[i] == fileStats.st_gid) - { - userPartOfPortGroup = 1; - break; - } - - // Attempt to add the user to the group that owns the port - char *addUserToGroupCmd = (char*)malloc(256); - if (!userPartOfPortGroup) + if (stat(portFile, &fileStats) == 0) { - struct group *portGroup; - struct passwd *userDetails; - if ((portGroup = getgrgid(fileStats.st_gid)) && (userDetails = getpwuid(geteuid()))) + // Check if the user is part of the group that owns the port + gid_t *userGroups = (gid_t*)malloc(numGroups * sizeof(gid_t)); + if (getgroups(numGroups, userGroups) >= 0) + for (int i = 0; i < numGroups; ++i) + if (userGroups[i] == fileStats.st_gid) + { + userPartOfPortGroup = 1; + break; + } + + // Attempt to add the user to the group that owns the port + char *addUserToGroupCmd = (char*)malloc(256); + if (!userPartOfPortGroup) { - snprintf(addUserToGroupCmd, 256, "sudo usermod -a -G %s %s", portGroup->gr_name, userDetails->pw_name); - userCanAccess = (system(addUserToGroupCmd) == 0); + struct group *portGroup; + struct passwd *userDetails; + if ((portGroup = getgrgid(fileStats.st_gid)) && (userDetails = getpwuid(geteuid()))) + { + snprintf(addUserToGroupCmd, 256, "sudo usermod -a -G %s %s", portGroup->gr_name, userDetails->pw_name); + userCanAccess = (system(addUserToGroupCmd) == 0); + } } - } - // Attempt to enable all read/write port permissions - snprintf(addUserToGroupCmd, 256, "sudo chmod 666 %s", portFile); - userCanAccess = (system(addUserToGroupCmd) == 0) || userCanAccess; + // Attempt to enable all read/write port permissions + snprintf(addUserToGroupCmd, 256, "sudo chmod 666 %s", portFile); + userCanAccess = (system(addUserToGroupCmd) == 0) || userCanAccess; - // Clean up memory - free(addUserToGroupCmd); - free(userGroups); + // Clean up memory + free(addUserToGroupCmd); + free(userGroups); + } } // Return whether the user can currently access the serial port diff --git a/src/main/resources/Android/arm64-v8a/libjSerialComm.so b/src/main/resources/Android/arm64-v8a/libjSerialComm.so index dccfce20..8819a6bf 100644 Binary files a/src/main/resources/Android/arm64-v8a/libjSerialComm.so and b/src/main/resources/Android/arm64-v8a/libjSerialComm.so differ diff --git a/src/main/resources/Android/armeabi-v7a/libjSerialComm.so b/src/main/resources/Android/armeabi-v7a/libjSerialComm.so index 0ad0f199..68baf779 100644 Binary files a/src/main/resources/Android/armeabi-v7a/libjSerialComm.so and b/src/main/resources/Android/armeabi-v7a/libjSerialComm.so differ diff --git a/src/main/resources/Android/x86/libjSerialComm.so b/src/main/resources/Android/x86/libjSerialComm.so index 6d48a3a1..ef7d68ae 100644 Binary files a/src/main/resources/Android/x86/libjSerialComm.so and b/src/main/resources/Android/x86/libjSerialComm.so differ diff --git a/src/main/resources/Android/x86_64/libjSerialComm.so b/src/main/resources/Android/x86_64/libjSerialComm.so index d07dfcd4..eeb5f79b 100644 Binary files a/src/main/resources/Android/x86_64/libjSerialComm.so and b/src/main/resources/Android/x86_64/libjSerialComm.so differ diff --git a/src/main/resources/FreeBSD/arm64/libjSerialComm.so b/src/main/resources/FreeBSD/arm64/libjSerialComm.so index 67e75ac9..34d0b695 100644 Binary files a/src/main/resources/FreeBSD/arm64/libjSerialComm.so and b/src/main/resources/FreeBSD/arm64/libjSerialComm.so differ diff --git a/src/main/resources/FreeBSD/x86/libjSerialComm.so b/src/main/resources/FreeBSD/x86/libjSerialComm.so index e6d31962..deb5ea5a 100644 Binary files a/src/main/resources/FreeBSD/x86/libjSerialComm.so and b/src/main/resources/FreeBSD/x86/libjSerialComm.so differ diff --git a/src/main/resources/FreeBSD/x86_64/libjSerialComm.so b/src/main/resources/FreeBSD/x86_64/libjSerialComm.so index 25ca12b3..1a4eb6ad 100644 Binary files a/src/main/resources/FreeBSD/x86_64/libjSerialComm.so and b/src/main/resources/FreeBSD/x86_64/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv5/libjSerialComm.so b/src/main/resources/Linux/armv5/libjSerialComm.so index 554953c9..dd68e959 100644 Binary files a/src/main/resources/Linux/armv5/libjSerialComm.so and b/src/main/resources/Linux/armv5/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv6/libjSerialComm.so b/src/main/resources/Linux/armv6/libjSerialComm.so index 4da21ced..e56b9fbd 100644 Binary files a/src/main/resources/Linux/armv6/libjSerialComm.so and b/src/main/resources/Linux/armv6/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv6hf/libjSerialComm.so b/src/main/resources/Linux/armv6hf/libjSerialComm.so index 4784edfa..4d3e0c89 100644 Binary files a/src/main/resources/Linux/armv6hf/libjSerialComm.so and b/src/main/resources/Linux/armv6hf/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv7/libjSerialComm.so b/src/main/resources/Linux/armv7/libjSerialComm.so index a492f6cb..a9f0f98a 100644 Binary files a/src/main/resources/Linux/armv7/libjSerialComm.so and b/src/main/resources/Linux/armv7/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv7hf/libjSerialComm.so b/src/main/resources/Linux/armv7hf/libjSerialComm.so index 28e4d5a8..06476391 100644 Binary files a/src/main/resources/Linux/armv7hf/libjSerialComm.so and b/src/main/resources/Linux/armv7hf/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv8_32/libjSerialComm.so b/src/main/resources/Linux/armv8_32/libjSerialComm.so index d991076f..87aeefd3 100644 Binary files a/src/main/resources/Linux/armv8_32/libjSerialComm.so and b/src/main/resources/Linux/armv8_32/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv8_64/libjSerialComm.so b/src/main/resources/Linux/armv8_64/libjSerialComm.so index 532d2184..255ca946 100644 Binary files a/src/main/resources/Linux/armv8_64/libjSerialComm.so and b/src/main/resources/Linux/armv8_64/libjSerialComm.so differ diff --git a/src/main/resources/Linux/ppc64le/libjSerialComm.so b/src/main/resources/Linux/ppc64le/libjSerialComm.so index 5e3daf6e..11990140 100644 Binary files a/src/main/resources/Linux/ppc64le/libjSerialComm.so and b/src/main/resources/Linux/ppc64le/libjSerialComm.so differ diff --git a/src/main/resources/Linux/x86/libjSerialComm.so b/src/main/resources/Linux/x86/libjSerialComm.so index 3711b287..fa81f4fb 100644 Binary files a/src/main/resources/Linux/x86/libjSerialComm.so and b/src/main/resources/Linux/x86/libjSerialComm.so differ diff --git a/src/main/resources/Linux/x86_64/libjSerialComm.so b/src/main/resources/Linux/x86_64/libjSerialComm.so index fbc1682f..c515924d 100644 Binary files a/src/main/resources/Linux/x86_64/libjSerialComm.so and b/src/main/resources/Linux/x86_64/libjSerialComm.so differ diff --git a/src/main/resources/OSX/aarch64/libjSerialComm.jnilib b/src/main/resources/OSX/aarch64/libjSerialComm.jnilib index 0d3b48ed..9d19987b 100755 Binary files a/src/main/resources/OSX/aarch64/libjSerialComm.jnilib and b/src/main/resources/OSX/aarch64/libjSerialComm.jnilib differ diff --git a/src/main/resources/OSX/x86/libjSerialComm.jnilib b/src/main/resources/OSX/x86/libjSerialComm.jnilib index 42183f97..8398d41c 100644 Binary files a/src/main/resources/OSX/x86/libjSerialComm.jnilib and b/src/main/resources/OSX/x86/libjSerialComm.jnilib differ diff --git a/src/main/resources/OSX/x86_64/libjSerialComm.jnilib b/src/main/resources/OSX/x86_64/libjSerialComm.jnilib index de8c2132..b415707e 100755 Binary files a/src/main/resources/OSX/x86_64/libjSerialComm.jnilib and b/src/main/resources/OSX/x86_64/libjSerialComm.jnilib differ diff --git a/src/main/resources/OpenBSD/amd64/libjSerialComm.so b/src/main/resources/OpenBSD/amd64/libjSerialComm.so index 9f4bdcf9..a822d680 100644 Binary files a/src/main/resources/OpenBSD/amd64/libjSerialComm.so and b/src/main/resources/OpenBSD/amd64/libjSerialComm.so differ diff --git a/src/main/resources/OpenBSD/x86/libjSerialComm.so b/src/main/resources/OpenBSD/x86/libjSerialComm.so index 85192e1f..443cfb99 100644 Binary files a/src/main/resources/OpenBSD/x86/libjSerialComm.so and b/src/main/resources/OpenBSD/x86/libjSerialComm.so differ diff --git a/src/main/resources/Solaris/sparcv8plus_32/libjSerialComm.so b/src/main/resources/Solaris/sparcv8plus_32/libjSerialComm.so index 87f8ad5b..bdab949e 100644 Binary files a/src/main/resources/Solaris/sparcv8plus_32/libjSerialComm.so and b/src/main/resources/Solaris/sparcv8plus_32/libjSerialComm.so differ diff --git a/src/main/resources/Solaris/sparcv9_64/libjSerialComm.so b/src/main/resources/Solaris/sparcv9_64/libjSerialComm.so index 50213fef..77e274a0 100644 Binary files a/src/main/resources/Solaris/sparcv9_64/libjSerialComm.so and b/src/main/resources/Solaris/sparcv9_64/libjSerialComm.so differ diff --git a/src/main/resources/Solaris/x86/libjSerialComm.so b/src/main/resources/Solaris/x86/libjSerialComm.so index 244f20a0..7f7425b7 100644 Binary files a/src/main/resources/Solaris/x86/libjSerialComm.so and b/src/main/resources/Solaris/x86/libjSerialComm.so differ diff --git a/src/main/resources/Solaris/x86_64/libjSerialComm.so b/src/main/resources/Solaris/x86_64/libjSerialComm.so index 0ee3d703..ad00b748 100644 Binary files a/src/main/resources/Solaris/x86_64/libjSerialComm.so and b/src/main/resources/Solaris/x86_64/libjSerialComm.so differ diff --git a/src/test/java/com/fazecast/jSerialComm/SerialPortTest.java b/src/test/java/com/fazecast/jSerialComm/SerialPortTest.java index be2a6538..66633ab2 100644 --- a/src/test/java/com/fazecast/jSerialComm/SerialPortTest.java +++ b/src/test/java/com/fazecast/jSerialComm/SerialPortTest.java @@ -268,18 +268,22 @@ public void run() ubxPort.addDataListener(new SerialPortDataListener() { @Override public int getListeningEvents() { return SerialPort.LISTENING_EVENT_PARITY_ERROR | SerialPort.LISTENING_EVENT_DATA_WRITTEN | SerialPort.LISTENING_EVENT_BREAK_INTERRUPT | - SerialPort.LISTENING_EVENT_CARRIER_DETECT | SerialPort.LISTENING_EVENT_CTS | SerialPort.LISTENING_EVENT_DSR | SerialPort.LISTENING_EVENT_RING_INDICATOR | + SerialPort.LISTENING_EVENT_CARRIER_DETECT | SerialPort.LISTENING_EVENT_CTS | SerialPort.LISTENING_EVENT_DSR | SerialPort.LISTENING_EVENT_RING_INDICATOR | SerialPort.LISTENING_EVENT_PORT_DISCONNECTED | SerialPort.LISTENING_EVENT_FRAMING_ERROR | SerialPort.LISTENING_EVENT_FIRMWARE_OVERRUN_ERROR | SerialPort.LISTENING_EVENT_SOFTWARE_OVERRUN_ERROR | SerialPort.LISTENING_EVENT_DATA_AVAILABLE; } @Override public void serialEvent(SerialPortEvent event) { - System.out.println("Received event type: " + event.getEventType()); if (event.getEventType() == SerialPort.LISTENING_EVENT_DATA_AVAILABLE) { + System.out.println("Received event type: LISTENING_EVENT_DATA_AVAILABLE"); byte[] buffer = new byte[event.getSerialPort().bytesAvailable()]; event.getSerialPort().readBytes(buffer, buffer.length); System.out.println(" Reading " + buffer.length + " bytes"); } + else if (event.getEventType() == SerialPort.LISTENING_EVENT_PORT_DISCONNECTED) + System.out.println("Received event type: LISTENING_EVENT_PORT_DISCONNECTED"); + else + System.out.println("Received event type: " + event.getEventType()); } }); try { Thread.sleep(5000); } catch (Exception e) {} @@ -311,29 +315,6 @@ public void serialEvent(SerialPortEvent event) ubxPort.removeDataListener(); System.out.println("\nClosing " + ubxPort.getDescriptivePortName() + ": " + ubxPort.closePort()); - /*System.out.println("\nPhysically unplug device within the next 10 seconds to see if the disconnect event fires..."); - ubxPort.addDataListener(new SerialPortDataListener() { - @Override - public int getListeningEvents() { return SerialPort.LISTENING_EVENT_PORT_DISCONNECTED | SerialPort.LISTENING_EVENT_DATA_AVAILABLE; } - @Override - public void serialEvent(SerialPortEvent event) - { - if (event.getEventType() == SerialPort.LISTENING_EVENT_DATA_AVAILABLE) - { - System.out.println("Received event type: LISTENING_EVENT_DATA_AVAILABLE"); - byte[] buffer = new byte[event.getSerialPort().bytesAvailable()]; - event.getSerialPort().readBytes(buffer, buffer.length); - System.out.println(" Reading " + buffer.length + " bytes"); - } - else - { - System.out.println("Received event type: LISTENING_EVENT_PORT_DISCONNECTED"); - } - } - }); - try { Thread.sleep(10000); } catch (Exception e) {} - ubxPort.closePort();*/ - /*System.out.println("\n\nAttempting to read from two serial ports simultaneously\n"); System.out.println("\nAvailable Ports:\n"); for (int i = 0; i < ports.length; ++i)