]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: move device_new_from_watch_handle_at() to udev-watch.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 14 Apr 2022 21:38:33 +0000 (06:38 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 11 Sep 2022 16:36:06 +0000 (01:36 +0900)
And drop unused watch handle related functions.

src/libsystemd/sd-device/device-internal.h
src/libsystemd/sd-device/device-private.c
src/libsystemd/sd-device/device-private.h
src/libsystemd/sd-device/sd-device.c
src/udev/udev-watch.c
src/udev/udev-watch.h

index 09325aae0454d7eedff31a5b1ffe8c3c02475465..9a4533a8f61713f991d5f932287d96014a9828d3 100644 (file)
@@ -21,8 +21,6 @@ struct sd_device {
          */
         unsigned database_version;
 
-        int watch_handle;
-
         sd_device *parent;
 
         OrderedHashmap *properties;
index a45389991073c53d54aeef623bc4f3373dd0d11c..9e120f734efd71c329409faf99cbc28a98a09490 100644 (file)
@@ -619,144 +619,6 @@ int device_get_devlink_priority(sd_device *device, int *ret) {
         return 0;
 }
 
-int device_get_watch_handle(sd_device *device) {
-        char path_wd[STRLEN("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
-        _cleanup_free_ char *buf = NULL;
-        const char *id, *path_id;
-        int wd, r;
-
-        assert(device);
-
-        if (device->watch_handle >= 0)
-                return device->watch_handle;
-
-        r = device_get_device_id(device, &id);
-        if (r < 0)
-                return r;
-
-        path_id = strjoina("/run/udev/watch/", id);
-        r = readlink_malloc(path_id, &buf);
-        if (r < 0)
-                return r;
-
-        r = safe_atoi(buf, &wd);
-        if (r < 0)
-                return r;
-
-        if (wd < 0)
-                return -EBADF;
-
-        buf = mfree(buf);
-        xsprintf(path_wd, "/run/udev/watch/%d", wd);
-        r = readlink_malloc(path_wd, &buf);
-        if (r < 0)
-                return r;
-
-        if (!streq(buf, id))
-                return -EBADF;
-
-        return device->watch_handle = wd;
-}
-
-static void device_remove_watch_handle(sd_device *device) {
-        const char *id;
-        int wd;
-
-        assert(device);
-
-        /* First, remove the symlink from handle to device id. */
-        wd = device_get_watch_handle(device);
-        if (wd >= 0) {
-                char path_wd[STRLEN("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
-
-                xsprintf(path_wd, "/run/udev/watch/%d", wd);
-                if (unlink(path_wd) < 0 && errno != ENOENT)
-                        log_device_debug_errno(device, errno,
-                                               "sd-device: failed to remove %s, ignoring: %m",
-                                               path_wd);
-        }
-
-        /* Next, remove the symlink from device id to handle. */
-        if (device_get_device_id(device, &id) >= 0) {
-                const char *path_id;
-
-                path_id = strjoina("/run/udev/watch/", id);
-                if (unlink(path_id) < 0 && errno != ENOENT)
-                        log_device_debug_errno(device, errno,
-                                               "sd-device: failed to remove %s, ignoring: %m",
-                                               path_id);
-        }
-
-        device->watch_handle = -1;
-}
-
-int device_set_watch_handle(sd_device *device, int wd) {
-        char path_wd[STRLEN("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
-        const char *id, *path_id;
-        int r;
-
-        assert(device);
-
-        if (wd >= 0 && wd == device_get_watch_handle(device))
-                return 0;
-
-        device_remove_watch_handle(device);
-
-        if (wd < 0)
-                /* negative wd means that the caller requests to clear saved watch handle. */
-                return 0;
-
-        r = device_get_device_id(device, &id);
-        if (r < 0)
-                return r;
-
-        path_id = strjoina("/run/udev/watch/", id);
-        xsprintf(path_wd, "/run/udev/watch/%d", wd);
-
-        r = mkdir_parents(path_wd, 0755);
-        if (r < 0)
-                return r;
-
-        if (symlink(id, path_wd) < 0)
-                return -errno;
-
-        if (symlink(path_wd + STRLEN("/run/udev/watch/"), path_id) < 0) {
-                r = -errno;
-                if (unlink(path_wd) < 0 && errno != ENOENT)
-                        log_device_debug_errno(device, errno,
-                                               "sd-device: failed to remove %s, ignoring: %m",
-                                               path_wd);
-                return r;
-        }
-
-        device->watch_handle = wd;
-
-        return 0;
-}
-
-int device_new_from_watch_handle_at(sd_device **ret, int dirfd, int wd) {
-        char path_wd[STRLEN("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
-        _cleanup_free_ char *id = NULL;
-        int r;
-
-        assert(ret);
-
-        if (wd < 0)
-                return -EBADF;
-
-        if (dirfd >= 0) {
-                xsprintf(path_wd, "%d", wd);
-                r = readlinkat_malloc(dirfd, path_wd, &id);
-        } else {
-                xsprintf(path_wd, "/run/udev/watch/%d", wd);
-                r = readlink_malloc(path_wd, &id);
-        }
-        if (r < 0)
-                return r;
-
-        return sd_device_new_from_device_id(ret, id);
-}
-
 int device_rename(sd_device *device, const char *name) {
         _cleanup_free_ char *new_syspath = NULL;
         const char *interface;
index d33cddcf80f0350f06e015d138f7d9aeb031d31d..724061a28cd2f328fec815766f77a5fdd0ac7612 100644 (file)
 int device_new_from_mode_and_devnum(sd_device **ret, mode_t mode, dev_t devnum);
 int device_new_from_nulstr(sd_device **ret, char *nulstr, size_t len);
 int device_new_from_strv(sd_device **ret, char **strv);
-int device_new_from_watch_handle_at(sd_device **ret, int dirfd, int wd);
-static inline int device_new_from_watch_handle(sd_device **ret, int wd) {
-        return device_new_from_watch_handle_at(ret, -1, wd);
-}
 
 int device_get_property_bool(sd_device *device, const char *key);
 int device_get_sysattr_unsigned(sd_device *device, const char *sysattr, unsigned *ret_value);
 int device_get_sysattr_bool(sd_device *device, const char *sysattr);
 int device_get_device_id(sd_device *device, const char **ret);
 int device_get_devlink_priority(sd_device *device, int *ret);
-int device_get_watch_handle(sd_device *device);
 int device_get_devnode_mode(sd_device *device, mode_t *ret);
 int device_get_devnode_uid(sd_device *device, uid_t *ret);
 int device_get_devnode_gid(sd_device *device, gid_t *ret);
@@ -34,7 +29,6 @@ int device_get_cached_sysattr_value(sd_device *device, const char *key, const ch
 
 void device_seal(sd_device *device);
 void device_set_is_initialized(sd_device *device);
-int device_set_watch_handle(sd_device *device, int wd);
 void device_set_db_persist(sd_device *device);
 void device_set_devlink_priority(sd_device *device, int priority);
 int device_ensure_usec_initialized(sd_device *device, sd_device *device_old);
index a7ba7dd6e980f7ed29d41fabf4bf9810c2949e7c..91af4a27ed8d4536c9fbe355e2797518880ae5d3 100644 (file)
@@ -46,7 +46,6 @@ int device_new_aux(sd_device **ret) {
 
         *device = (sd_device) {
                 .n_ref = 1,
-                .watch_handle = -1,
                 .devmode = MODE_INVALID,
                 .devuid = UID_INVALID,
                 .devgid = GID_INVALID,
index 0cc83ddb9c698c2839d918283f6c78782f3867d5..2a9ff2909b08f9cfeb6393ee378dda963da16632 100644 (file)
 #include "string-util.h"
 #include "udev-watch.h"
 
+int device_new_from_watch_handle_at(sd_device **ret, int dirfd, int wd) {
+        char path_wd[STRLEN("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
+        _cleanup_free_ char *id = NULL;
+        int r;
+
+        assert(ret);
+
+        if (wd < 0)
+                return -EBADF;
+
+        if (dirfd >= 0) {
+                xsprintf(path_wd, "%d", wd);
+                r = readlinkat_malloc(dirfd, path_wd, &id);
+        } else {
+                xsprintf(path_wd, "/run/udev/watch/%d", wd);
+                r = readlink_malloc(path_wd, &id);
+        }
+        if (r < 0)
+                return r;
+
+        return sd_device_new_from_device_id(ret, id);
+}
+
 int udev_watch_restore(int inotify_fd) {
         _cleanup_closedir_ DIR *dir = NULL;
         int r;
index d211d99f49de7937d629e99575eb4b5ae97c07cb..c454deead3cff2b7ac8801575638ce675084fc42 100644 (file)
@@ -3,6 +3,11 @@
 
 #include "sd-device.h"
 
+int device_new_from_watch_handle_at(sd_device **ret, int dirfd, int wd);
+static inline int device_new_from_watch_handle(sd_device **ret, int wd) {
+        return device_new_from_watch_handle_at(ret, -1, wd);
+}
+
 int udev_watch_restore(int inotify_fd);
 int udev_watch_begin(int inotify_fd, sd_device *dev);
 int udev_watch_end(int inotify_fd, sd_device *dev);