Fazecast / jSerialComm

Platform-independent serial port access for Java
GNU Lesser General Public License v3.0
1.35k stars 287 forks source link

Shared object folder's permissions block other users from running code #251

Closed dawnvandergracht-jhuapl closed 5 years ago

dawnvandergracht-jhuapl commented 5 years ago

We have multiple users on the same machine running code that uses jSerialComm to connect to a component. We run into a permissions issue when we attempt to do this. It looks like the first user who runs the code is the admin of the jSerialComm folder created in tmp with the shared object, but this folder's permissions do not allow the second user to access that folder. This means there is a FileNotFoundException and an UnsatisfiedLinkError.

Workarounds currently include setting VM options to set the java.io.tmpdir variable to a different location per user, or setting that variable directly in our code. While these get around the issue, they're not ideal solutions.

Here is the stack trace we get when the second user attempts to run the application:

java.io.FileNotFoundException: /tmp/jSerialComm/1572353209253-libjSerialComm.so (Permission denied) at java.io.FileOutputStream.open0(Native Method) at java.io.FileOutputStream.open(FileOutputStream.java:270) at java.io.FileOutputStream.(FileOutputStream.java:213) at java.io.FileOutputStream.(FileOutputStream.java:162) at com.fazecast.jSerialComm.SerialPort.(SerialPort.java:227)

java.lang.UnsatisfiedLinkError: com.fazecast.jSerialComm.SerialPort.getCommPorts()[Lcom/fazecast/jSerialComm/SerialPort;

at com.fazecast.jSerialComm.SerialPort.getCommPorts(Native Method)
hedgecrw commented 5 years ago

Please try this version of the library: https://www.dropbox.com/s/alfwmp2i2g3mjdb/jSerialComm-2.5.3b.jar?dl=0

I added code to make both the library and shared directory globally writable. You may need to manually delete the /tmp/jSerialComm directory before you test this the first time in case the user doing the testing wasn't the original directory owner. You should only have to do this once. Please report back if this works for you!

dawnvandergracht-jhuapl commented 5 years ago

Thank you for your quick response.

I'm using gradle for my dependencies. Is this version available yet in maven central?

hedgecrw commented 5 years ago

Not yet - I don't want to push it to Maven until I know whether or not it fixes the problem.

If you're using Gradle, you should be able to test the library as a local JAR by commenting out the dependency line that you are currently using for jSerialComm and instead adding a localfile implementation line in your dependencies block like so:

dependencies {
    implementation files("libs/jSerialComm-2.5.3b.jar")
}

Just make sure to replace the path shown above with the actual path on your own system (can also be a full absolute file path if that's easier)

dawnvandergracht-jhuapl commented 5 years ago

We ran our applications using the jar you sent and that appears to have fixed the problem.

Please keep me posted on when you push it to Maven so we can update our project accordingly. Thanks so much for your help.

hedgecrw commented 5 years ago

Fixed - this is present in current jSerialComm release v2.5.3.