-
Notifications
You must be signed in to change notification settings - Fork 109
Open
Description
Environment:
- OS: Debian Bullseye
- Java version Temurin JDK 21 (repeatable in Amazon Corretto 17 and 11 as well)
- usb4java version 1.3.0
Bug description
When running an application on Linux on the host, you can run a java application and have the attach and detach events fire. When running the same application in a Docker container, those events will not fire. Further, trying to manually poll the USB devices and compare old/new is not possible, as the devices returned from UsbHostManager.getUsbServices().getRootUsbHub() are always the same. Ex. When a device is no longer attached, it will still appear in the list if it was attached at startup.
Reproduction
- Compile the code below into a jar file.
import javax.usb.UsbException;
import javax.usb.UsbHostManager;
import javax.usb.event.UsbServicesEvent;
import javax.usb.event.UsbServicesListener;
public class Application {
public static void main(String[] args) throws UsbException, InterruptedException {
UsbHostManager.getUsbServices().addUsbServicesListener(new UsbServicesListener() {
@Override
public void usbDeviceAttached(UsbServicesEvent event) {
System.out.println("Device attached.");
}
@Override
public void usbDeviceDetached(UsbServicesEvent event) {
System.out.println("Device detached.");
}
});
Thread.sleep(15000);
}
}
- Run on a linux machine with sudo.
sudo java -Djava.security.egd=file:/dev/./urandom -jar app.jar - Connect and disconnect USB devices to see console output.
- Build the jar into a container and use the below Dockerfile to build with
sudo docker build --build-arg="JAR_FILE=app.jar" -t test1 .
FROM eclipse-temurin:21-jre-jammy
ARG JAR_FILE
COPY ${JAR_FILE} /usr/app/app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/usr/app/app.jar"]
- Run the container with
sudo docker run -it --rm --privileged test1:latest - Observe that connecting and disconnecting does not fire the event.
Expected behavior
I expect that the application running in a container with the correct privileges' would allow firing of the attach and detach events.
Metadata
Metadata
Assignees
Labels
No labels