-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race condition #9
Comments
Well, that's in part what the |
Consider the following example: #!/bin/sh
# this is /sbin/init
# some initialization is going on here
mdevd & # this doesn't block
mdevd-coldplug # trigger uevents for cold-plugged devices
# synchronization is needed here
sway # this will fail because mdevd doesn't have enough time to handle uevents and set permissions for devnodes
Sway(well libinput) uses /dev/input to initialize cold-plugged devices. If it encounter devnode with bad permissions(because of race condition), it will exit(1). In order to fix this, some kind of synchronization(like udevadm settle) is needed between mdevd-coldplug and sway to ensure that all uevents are processed before running sway. |
Technically, sway doesn't need all uevents to be processed; it just needs the But yes, I understand that what you want is an equivalent to |
Sway is just an example. There are also potential problems with kernel modules and modprobe due to this race condition.
Maybe. Depends on how you want to implement it. |
The idea would be to make |
This is interesting. I wonder how you intend to determine that last device. |
I found something interesting: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-uevent Turns out you can pass your own variables to uevent. This could be leveraged to implement detection of the last device. |
Oh, I don't think you need this. You just need to record the DEVPATH of the last device (which can be trivially achieved by keeping the DEVPATH of every device in a variable that gets overwritten every loop iteration, and the last value when the loop exits is the correct one). |
Good idea |
@illiliti Can you test with the latest git head? |
I got segfault at mdevd/src/mdevd/mdevd-coldplug.c Line 155 in 6e21f54
gdb says x is 0x0 |
That's worrying: is there a path where the MDEV variable is not set by mdevd? Can I see your |
https://github.com/kiss-community/repo/blob/master/extra/mdevd/files/mdevd.conf Plus
|
Yeah that makes sense. The MDEV variable is actually only supposed to be exported in spawned helper commands, it doesn't belong to the uevent itself, and the fact that it was visible in the rebroadcasted events was a bug. My own I removed MDEV from the rebroadcasted events and made |
I don't see segfault anymore, but race condition is still present. |
That doesn't sound possible, or points to a more fundamental design issue.
If you're still seeing the race condition, then either I'm missing something fundamental about how all this is working, or there's something else in your workflow that makes the uevent appear ready earlier than it should. |
@illiliti What steps could I take to reproduce the problem without firing up a graphical interface? |
I guess you have to modify your init. That's what i'm doing Anyway, i fixed race condition by running mdevd-coldplug twice. I have no idea whether it's proper fix though. Maybe running it twice gives mdevd more time to handles uevents, hence no race. I don't know I'll investigate this a bit more, but if it is proper fix, then linux hotplugging/coldplugging is totally fucked. I don't even want to look how udev handles this cursed stuff. |
Due to lack of synchronization, a race condition may occur when e.g other programs/services need rw access to /dev/input/*. Since mdevd doesn't provide a way to request its state of processing coldplug uevents, those programs/services have no synchronization with mdevd which may lead to breakage due to bad permissions in /dev/input/*.
This is tricky issue to fix i think. Udev has
udevadm settle
which blocks until all events are processed. Mdev hasmdev -s
which set proper permissions in /dev/* without need for daemon. What mdevd should do? Looking forward to your ideas!The text was updated successfully, but these errors were encountered: