]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev/watch: use mapping from device ID -> watch on restart
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 22 Feb 2026 16:28:41 +0000 (01:28 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 15 May 2026 11:47:45 +0000 (13:47 +0200)
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.

src/udev/udev-watch.c

index 08bc3492bb0b0ab22ec2753056603b9641cc6726..0636c325e6bc6abde58e19cb6234b759ccd81b61 100644 (file)
@@ -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;
                 }