1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 06:25:37 +03:00

udev-node: do not create symlink to a non-existing device node

Previously, the stack directory contains empty regular files named with
device ID, and we create sd_device object from the device name.
Hence, we implicitly checked the existence of the device node.

However, now the files in the stack directory are symlink, and we
retrieve the path to the device node and its priority from the symlink.
Hence, the existence of the device node is not checked.
Let's check if the device node is still exist.
This commit is contained in:
Yu Watanabe 2022-09-14 06:07:09 +09:00
parent 13271e2dde
commit 69928b4f15

View File

@ -146,6 +146,13 @@ static int stack_directory_read_one(int dirfd, const char *id, bool is_symlink,
*colon = '\0'; *colon = '\0';
/* Of course, this check is racy, but it is not necessary to be perfect. Even if the device
* node will be removed after this check, we will receive 'remove' uevent, and the invalid
* symlink will be removed during processing the event. The check is just for shortening the
* timespan that the symlink points to a non-existing device node. */
if (access(colon + 1, F_OK) < 0)
return -errno;
r = safe_atoi(buf, &tmp_prio); r = safe_atoi(buf, &tmp_prio);
if (r < 0) if (r < 0)
return r; return r;