]> git.ipfire.org Git - thirdparty/systemd.git/commit
libudev: cache the errno for a failed parent lookup main
authorDaniel28972897 <danyboy28sep@gmail.com>
Wed, 29 Jul 2026 04:23:05 +0000 (22:23 -0600)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 29 Jul 2026 22:24:17 +0000 (07:24 +0900)
commitb2cd05007396222fe66bbff371ca1b81fb1f4a15
treea0386c9293fe3f49c46754024e035bf1ebc7e55f
parent9d4019b9b7ae26b18720e626774d3f1128fa831a
libudev: cache the errno for a failed parent lookup

udev_device_get_parent() caches the result of device_new_from_parent()
in udev_device->parent on first call. device_new_from_parent() sets
errno correctly via return_with_errno() when it fails, so a caller
gets the right errno on the first invocation. But on any subsequent
call for the same object, the cached NULL is returned directly without
recomputing anything, so errno reflects whatever happened in between
rather than the original failure reason.

Cache the errno alongside the parent pointer (new parent_errno field,
zero-initialized like the rest of the struct via udev_device_new()'s
compound literal) and restore it whenever the cached parent is NULL.
src/libudev/libudev-device.c