1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 17:51:22 +03:00

udev-watch: make udev_watch_lookup() return 1 when device found

This commit is contained in:
Yu Watanabe 2018-10-27 08:19:51 +09:00
parent b7759e0403
commit 7fe3324c5e
2 changed files with 11 additions and 10 deletions

View File

@ -147,22 +147,23 @@ int udev_watch_lookup(int wd, sd_device **ret) {
assert(ret);
if (inotify_fd < 0)
return log_error_errno(EINVAL, "Invalid inotify descriptor.");
return log_debug_errno(EINVAL, "Invalid inotify descriptor.");
if (wd < 0)
return log_error_errno(EINVAL, "Invalid watch handle.");
return log_debug_errno(EINVAL, "Invalid watch handle.");
xsprintf(filename, "/run/udev/watch/%d", wd);
r = readlink_malloc(filename, &device);
if (r < 0) {
if (r != -ENOENT)
return log_error_errno(errno, "Failed to read link '%s': %m", filename);
if (r == -ENOENT)
return 0;
}
if (r < 0)
return log_debug_errno(r, "Failed to read link '%s': %m", filename);
r = sd_device_new_from_device_id(ret, device);
if (r < 0)
return log_error_errno(r, "Failed to create sd_device object for '%s': %m", device);
if (r == -ENODEV)
return 0;
if (r < 0)
return log_debug_errno(r, "Failed to create sd_device object for '%s': %m", device);
return 1;
}

View File

@ -1169,13 +1169,13 @@ static int on_inotify(sd_event_source *s, int fd, uint32_t revents, void *userda
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
const char *devnode;
if (udev_watch_lookup(e->wd, &dev) < 0)
if (udev_watch_lookup(e->wd, &dev) <= 0)
continue;
if (sd_device_get_devname(dev, &devnode) < 0)
continue;
log_debug("inotify event: %x for %s", e->mask, devnode);
log_device_debug(dev, "Inotify event: %x for %s", e->mask, devnode);
if (e->mask & IN_CLOSE_WRITE) {
synthesize_change(dev);