Jinjinov/Usb.Events

Missing existing device metadata while running in docker, until device is removed and then added

tcochunk opened this issue · 1 comments

I have downloaded your latest version 11.1.0.1 and it is working GREAT on the Raspberry PI....THANK YOU for all your effort on issue #29

Now, I am trying to run the application within a docker container. When the application first loads up, I list out all the connected devices. When the devices are listed they are missing all the meta data, but I need the device information when the container is first turned on for all the connected devices:
image

Within the container, if I unplug and plug in the device, the meta data shows up during the add event (but not until i remove and add the device):
image

However, when i run it directly on the PI, the data shows up immediately when the program starts.
image

Interestingly, in both scenarios (container and on pi directly) the existing device counts are 0 and then all the devices get "Added"

My containers Image is based on mcr.microsoft.com/dotnet/runtime:7.0.15-bullseye-slim-arm64v8
and then i install udev and setup some udev rules:

RUN apt-get update -y && \
apt-get install -y udev usbutils && \
echo '\
ACTION=="add", RUN+="mknod %N c %M %m"\n\
ACTION=="remove", RUN+="rm %N"\n\
' > /etc/udev/rules.d/99-togglePico.rules

The container is run in privilege mode. My understanding is that if i run in privilege mode, I dont have to map any devices or volumes but maybe i am wrong.
sudo docker run -it --privileged usb_test_image

and the udev service is restarted before my program is run:
cmd service udev restart && ./USBDetectionTesting

I suspect I am missing some basic dependency in the container but cant figure out what i am missing so your code can find the meta data of the existing devices.

Any help/insight would be appreciated.

Uf, this sounds like a complicated problem. I don't have much experience with Docker...

The good news is that I bought a Raspberry Pi 5 last month :)

The bad news is that I have a LOT of things that I have to do right now and I don't have the time to investigate this...

If there were no events at all, I would suggest looking into UDEV, if it is properly installed. But since you said that it works after you remove and insert it again, I have no ideas what you could do...

The only thing I can think of right now is that you try debugging the native C code in Docker, if that is possible... that code is the only place that can give you any clues about the problem...

EnumerateDevices finds existing devices:
https://github.com/Jinjinov/Usb.Events/blob/master/Usb.Events/Linux/UsbEventWatcher.Linux.c#L162

Set a breakpoint where it is called in StartLinuxWatcher:
https://github.com/Jinjinov/Usb.Events/blob/master/Usb.Events/Linux/UsbEventWatcher.Linux.c#L310

After that, the MonitorDevices is called where the code runs continuously inside a while loop...