]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: rename device_get_id_filename() -> device_get_device_id()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 7 Mar 2021 06:07:51 +0000 (15:07 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 30 Apr 2021 10:21:18 +0000 (19:21 +0900)
We have sd_device_new_from_device_id(), which takes device ID generated
from device_get_id_filename(). For consistency, let's rename the
function.

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-node.c
src/udev/udev-watch.c

index c7f9b5908773396b21db072495d98a23b5fb6f1e..6776ab3aa7689e2bb1bd7effcff7d766999f0c82 100644 (file)
@@ -67,7 +67,7 @@ struct sd_device {
         char *driver_subsystem; /* only set for the 'drivers' subsystem */
         char *driver;
 
-        char *id_filename;
+        char *device_id;
 
         usec_t usec_initialized;
 
index 7a7204b145b4397a47ce3fdf48be00baeffe7c50..cac7b98518bd478de32dd75a2abed3e5eaa18052 100644 (file)
@@ -761,7 +761,7 @@ static int device_tag(sd_device *device, const char *tag, bool add) {
         assert(device);
         assert(tag);
 
-        r = device_get_id_filename(device, &id);
+        r = device_get_device_id(device, &id);
         if (r < 0)
                 return r;
 
@@ -846,7 +846,7 @@ int device_update_db(sd_device *device) {
 
         has_info = device_has_info(device);
 
-        r = device_get_id_filename(device, &id);
+        r = device_get_device_id(device, &id);
         if (r < 0)
                 return r;
 
@@ -950,7 +950,7 @@ int device_delete_db(sd_device *device) {
 
         assert(device);
 
-        r = device_get_id_filename(device, &id);
+        r = device_get_device_id(device, &id);
         if (r < 0)
                 return r;
 
index ec76f772e5ff5386c2a3b3f354d2a93dcc4d1f14..8eafc7ef74b4403b16c4c13d5794b7ea23b19e8c 100644 (file)
@@ -13,7 +13,7 @@
 int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len);
 int device_new_from_strv(sd_device **ret, char **strv);
 
-int device_get_id_filename(sd_device *device, const char **ret);
+int device_get_device_id(sd_device *device, const char **ret);
 
 int device_get_devlink_priority(sd_device *device, int *priority);
 int device_get_watch_handle(sd_device *device, int *handle);
index 8ef5aa55bf79fc96be3bc4faf29c758cf17e4efe..decf9ae1d1c9446c045877cffa81a4f0da3b2c34 100644 (file)
@@ -62,7 +62,7 @@ static sd_device *device_free(sd_device *device) {
         free(device->subsystem);
         free(device->driver_subsystem);
         free(device->driver);
-        free(device->id_filename);
+        free(device->device_id);
         free(device->properties_strv);
         free(device->properties_nulstr);
 
@@ -1255,11 +1255,11 @@ static int handle_db_line(sd_device *device, char key, const char *value) {
         return 0;
 }
 
-int device_get_id_filename(sd_device *device, const char **ret) {
+int device_get_device_id(sd_device *device, const char **ret) {
         assert(device);
         assert(ret);
 
-        if (!device->id_filename) {
+        if (!device->device_id) {
                 _cleanup_free_ char *id = NULL;
                 const char *subsystem;
                 dev_t devnum;
@@ -1306,10 +1306,10 @@ int device_get_id_filename(sd_device *device, const char **ret) {
                                 return -ENOMEM;
                 }
 
-                device->id_filename = TAKE_PTR(id);
+                device->device_id = TAKE_PTR(id);
         }
 
-        *ret = device->id_filename;
+        *ret = device->device_id;
         return 0;
 }
 
@@ -1406,7 +1406,7 @@ int device_read_db_internal(sd_device *device, bool force) {
         if (device->db_loaded || (!force && device->sealed))
                 return 0;
 
-        r = device_get_id_filename(device, &id);
+        r = device_get_device_id(device, &id);
         if (r < 0)
                 return r;
 
index 96963a4343ef5cc2a9cd424eaeb94803242d507e..5dc205e36406e3afa29669c47b2d1c06b1977d93 100644 (file)
@@ -30,7 +30,7 @@
 
 static int node_symlink(sd_device *dev, const char *node, const char *slink) {
         _cleanup_free_ char *slink_dirname = NULL, *target = NULL;
-        const char *id_filename, *slink_tmp;
+        const char *id, *slink_tmp;
         struct stat stats;
         int r;
 
@@ -81,10 +81,10 @@ static int node_symlink(sd_device *dev, const char *node, const char *slink) {
         }
 
         log_device_debug(dev, "Atomically replace '%s'", slink);
-        r = device_get_id_filename(dev, &id_filename);
+        r = device_get_device_id(dev, &id);
         if (r < 0)
-                return log_device_error_errno(dev, r, "Failed to get id_filename: %m");
-        slink_tmp = strjoina(slink, ".tmp-", id_filename);
+                return log_device_error_errno(dev, r, "Failed to get device id: %m");
+        slink_tmp = strjoina(slink, ".tmp-", id);
         (void) unlink(slink_tmp);
         do {
                 r = mkdir_parents_label(slink_tmp, 0755);
@@ -147,7 +147,7 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir,
 
         FOREACH_DIRENT_ALL(dent, dir, break) {
                 _cleanup_(sd_device_unrefp) sd_device *dev_db = NULL;
-                const char *devnode, *id_filename;
+                const char *devnode, *id;
                 int db_prio = 0;
 
                 if (dent->d_name[0] == '\0')
@@ -157,11 +157,11 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir,
 
                 log_device_debug(dev, "Found '%s' claiming '%s'", dent->d_name, stackdir);
 
-                if (device_get_id_filename(dev, &id_filename) < 0)
+                if (device_get_device_id(dev, &id) < 0)
                         continue;
 
                 /* did we find ourself? */
-                if (streq(dent->d_name, id_filename))
+                if (streq(dent->d_name, id))
                         continue;
 
                 if (sd_device_new_from_device_id(&dev_db, dent->d_name) < 0)
@@ -229,21 +229,21 @@ static size_t escape_path(const char *src, char *dest, size_t size) {
 static int link_update(sd_device *dev, const char *slink, bool add) {
         _cleanup_free_ char *filename = NULL, *dirname = NULL;
         char name_enc[PATH_MAX];
-        const char *id_filename;
+        const char *id;
         int i, r, retries;
 
         assert(dev);
         assert(slink);
 
-        r = device_get_id_filename(dev, &id_filename);
+        r = device_get_device_id(dev, &id);
         if (r < 0)
-                return log_device_debug_errno(dev, r, "Failed to get id_filename: %m");
+                return log_device_debug_errno(dev, r, "Failed to get device id: %m");
 
         escape_path(slink + STRLEN("/dev"), name_enc, sizeof(name_enc));
         dirname = path_join("/run/udev/links/", name_enc);
         if (!dirname)
                 return log_oom();
-        filename = path_join(dirname, id_filename);
+        filename = path_join(dirname, id);
         if (!filename)
                 return log_oom();
 
@@ -348,7 +348,7 @@ int udev_node_update_old_links(sd_device *dev, sd_device *dev_old) {
 static int node_permissions_apply(sd_device *dev, bool apply_mac,
                                   mode_t mode, uid_t uid, gid_t gid,
                                   OrderedHashmap *seclabel_list) {
-        const char *devnode, *subsystem, *id_filename = NULL;
+        const char *devnode, *subsystem, *id = NULL;
         bool apply_mode, apply_uid, apply_gid;
         _cleanup_close_ int node_fd = -1;
         struct stat stats;
@@ -366,7 +366,7 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac,
         r = sd_device_get_devnum(dev, &devnum);
         if (r < 0)
                 return log_device_debug_errno(dev, r, "Failed to get devnum: %m");
-        (void) device_get_id_filename(dev, &id_filename);
+        (void) device_get_device_id(dev, &id);
 
         if (streq(subsystem, "block"))
                 mode |= S_IFBLK;
@@ -388,7 +388,7 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac,
 
         if ((mode != MODE_INVALID && (stats.st_mode & S_IFMT) != (mode & S_IFMT)) || stats.st_rdev != devnum) {
                 log_device_debug(dev, "Found node '%s' with non-matching devnum %s, skipping handling.",
-                                 devnode, id_filename);
+                                 devnode, strna(id));
                 return 0; /* We might process a device that already got replaced by the time we have a look
                            * at it, handle this gracefully and step away. */
         }
@@ -509,10 +509,10 @@ int udev_node_add(sd_device *dev, bool apply,
                 return log_device_debug_errno(dev, r, "Failed to get devnode: %m");
 
         if (DEBUG_LOGGING) {
-                const char *id_filename = NULL;
+                const char *id = NULL;
 
-                (void) device_get_id_filename(dev, &id_filename);
-                log_device_debug(dev, "Handling device node '%s', devnum=%s", devnode, strnull(id_filename));
+                (void) device_get_device_id(dev, &id);
+                log_device_debug(dev, "Handling device node '%s', devnum=%s", devnode, strna(id));
         }
 
         r = node_permissions_apply(dev, apply, mode, uid, gid, seclabel_list);
index e90fcd1bcc28b80432b0baa36e03eb105d7bf0b7..dca843e3f10e2b642febad505adf4fd6708898c7 100644 (file)
@@ -37,20 +37,20 @@ int udev_watch_restore(int inotify_fd) {
 
         FOREACH_DIRENT_ALL(ent, dir, break) {
                 _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
-                _cleanup_free_ char *device = NULL;
+                _cleanup_free_ char *id = NULL;
 
                 if (ent->d_name[0] == '.')
                         continue;
 
-                r = readlinkat_malloc(dirfd(dir), ent->d_name, &device);
+                r = readlinkat_malloc(dirfd(dir), ent->d_name, &id);
                 if (r < 0) {
                         log_debug_errno(r, "Failed to read link '/run/udev/watch.old/%s', ignoring: %m", ent->d_name);
                         goto unlink;
                 }
 
-                r = sd_device_new_from_device_id(&dev, device);
+                r = sd_device_new_from_device_id(&dev, id);
                 if (r < 0) {
-                        log_debug_errno(r, "Failed to create sd_device object for '%s', ignoring: %m", device);
+                        log_debug_errno(r, "Failed to create sd_device object for '%s', ignoring: %m", id);
                         goto unlink;
                 }
 
@@ -68,7 +68,7 @@ unlink:
 
 int udev_watch_begin(int inotify_fd, sd_device *dev) {
         char filename[STRLEN("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
-        const char *devnode, *id_filename;
+        const char *devnode, *id;
         int wd, r;
 
         assert(inotify_fd >= 0);
@@ -92,11 +92,11 @@ int udev_watch_begin(int inotify_fd, sd_device *dev) {
                 return log_device_error_errno(dev, r, "Failed to create parent directory of '%s': %m", filename);
         (void) unlink(filename);
 
-        r = device_get_id_filename(dev, &id_filename);
+        r = device_get_device_id(dev, &id);
         if (r < 0)
                 return log_device_error_errno(dev, r, "Failed to get device id-filename: %m");
 
-        if (symlink(id_filename, filename) < 0)
+        if (symlink(id, filename) < 0)
                 return log_device_error_errno(dev, errno, "Failed to create symlink %s: %m", filename);
 
         return 0;
@@ -131,24 +131,24 @@ int udev_watch_end(int inotify_fd, sd_device *dev) {
 
 int udev_watch_lookup(int wd, sd_device **ret) {
         char filename[STRLEN("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
-        _cleanup_free_ char *device = NULL;
+        _cleanup_free_ char *id = NULL;
         int r;
 
         assert(wd >= 0);
         assert(ret);
 
         xsprintf(filename, "/run/udev/watch/%d", wd);
-        r = readlink_malloc(filename, &device);
+        r = readlink_malloc(filename, &id);
         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);
+        r = sd_device_new_from_device_id(ret, id);
         if (r == -ENODEV)
                 return 0;
         if (r < 0)
-                return log_debug_errno(r, "Failed to create sd_device object for '%s': %m", device);
+                return log_debug_errno(r, "Failed to create sd_device object for '%s': %m", id);
 
         return 1;
 }