-
-
Notifications
You must be signed in to change notification settings - Fork 251
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
Async uevent #1298
Async uevent #1298
Conversation
757fc0c
to
2411fee
Compare
Great, thanks for the contribution! Would be nice to update the PR:
|
Add an sync socket as thin layer on top of AsyncNetlinkSocket analogous to UeventSocket on top of NetlinkSocket.
Uevent has no multipart messages with NLMSG_DONE at the end. So have get() yield messages individually until all are consumed. Avoids error: File "pyroute2/pyroute2/netlink/marshal.py", line 134, in is_enough return msg['header']['type'] == NLMSG_DONE ~~~~~~~~~~~~~^^^^^^^^ KeyError: 'type'
udevd sends messages to libudev consumers on the same socket as the kernel but with a different group. Handle the different format with binary header. See: https://insujang.github.io/2018-11-27/udev-device-manager-for-the-linux-kernel-in-userspace/#libudev-and-kobject_uevent-message-groups
Although unlikely, it seems a good measure to account for possible decoding errors in marshalling.
Define kernel and udevd message group constants and allow to specify them on bind.
2411fee
to
abace8d
Compare
There is an issue with the CI, so some jobs are failing; I'm to fix that tonight |
|
The CI is fixed. We can merge the code, and the annotations, and occasionally some tests you can push later as a separate PR. |
Do not reassign variables to avoid type conflict reports from mypy. Find a more efficient way for splitting lines into key and value while at it. Turn parse() on MarshalUevent into a generator so it matches the superclass' signature. Not sure if this is still semantically correct, the return in the error case and Generator SendType and ReturnType in particular. (my generator-fu is weak) Add superclass parameters to parse() to match signature (and ignore them). Annotating bind() on UeventSocket seems to work because mypy can't follow the *argv, **kwargs on the superclass back into AsyncNetlinkSocket. No such luck on AsyncUeventSocket: While bind()'s signature can be made compatible with that of AsyncNetlinkSocket, the one of AsyncCoreSocket is plain incompatible (addr arg). So we basically have to promise mypy that we know what we're doing at this point. See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
Here's an attempt at typing. Way more than what I bargained for. :) |
Add two test messages to test_marshal, one from kernel and one from udevd.
Great! Thanks a lot! |
Thanks for this awesome library!
Here are some (hopefully self-explanatory) extensions to uevent handling. I use them to listen for backlight changes. Would you be interested in including those? What would potentially need doing to get them in?