From: Yu Watanabe Date: Sun, 22 Feb 2026 16:28:41 +0000 (+0900) Subject: udev/watch: use mapping from device ID -> watch on restart X-Git-Tag: v261-rc1~144^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfe0e81de68c13219f1c8a7ac9390c21204fb496;p=thirdparty%2Fsystemd.git udev/watch: use mapping from device ID -> watch on restart The mapping from device ID to watch handle has been introduced by e7f781e473f5119bf9246208a6de9f6b76a39c5d (v249, released on 2021-07-07). Let's drop the runtime upgradability of udevd from an ancient version. --- diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 08bc3492bb0..0636c325e6b 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -337,21 +337,20 @@ static int udev_watch_restore(Manager *manager) { return log_warning_errno(errno, "Failed to open old watches directory '%s': %m", old); FOREACH_DIRENT(de, dir, break) { - - /* For backward compatibility, read symlink from watch handle to device ID. This is necessary - * when udevd is restarted after upgrading from v248 or older. The new format (ID -> wd) was - * introduced by e7f781e473f5119bf9246208a6de9f6b76a39c5d (v249). */ - - int wd; - if (safe_atoi(de->d_name, &wd) < 0) - continue; /* This should be ID -> wd symlink. Skipping. */ + if (in_charset(de->d_name, DIGITS)) + continue; /* This should be wd -> ID symlink. Skipping. */ _cleanup_(sd_device_unrefp) sd_device *dev = NULL; - r = device_new_from_watch_handle_at(&dev, dirfd(dir), wd); + r = sd_device_new_from_device_id(&dev, de->d_name); if (r < 0) { + _cleanup_free_ char *wd_str = NULL; + + if (ERRNO_IS_NEG_DEVICE_ABSENT(r) || DEBUG_LOGGING) + (void) readlinkat_malloc(dirfd(dir), de->d_name, &wd_str); + log_full_errno(ERRNO_IS_NEG_DEVICE_ABSENT(r) ? LOG_DEBUG : LOG_WARNING, r, - "Failed to create sd_device object from saved watch handle '%i', ignoring: %m", - wd); + "Failed to create sd_device object from device ID '%s' for watch handle '%s', ignoring: %m", + de->d_name, strna(wd_str)); continue; }