]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-node: make stack_directory_read_one() accept NULL for devnode
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 20 Feb 2023 05:43:58 +0000 (14:43 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 20 Feb 2023 10:40:31 +0000 (19:40 +0900)
No functional change, as currently the function is always called with
non-NULL argument. Just a preparation for #26048 or #25839.

src/udev/udev-node.c

index 5f3dc61f09fa02b0974c8b10daa73f44ca1bf90d..e49e959cd8029b82e2589edbe41522490d4e5c77 100644 (file)
@@ -110,12 +110,14 @@ static int stack_directory_read_one(int dirfd, const char *id, char **devnode, i
 
         assert(dirfd >= 0);
         assert(id);
-        assert(devnode);
         assert(priority);
 
+        /* This reads priority and device node from the symlink under /run/udev/links (or udev database).
+         * If 'devnode' is NULL, obtained priority is always set to '*priority'. If 'devnode' is non-NULL,
+         * this updates '*devnode' and '*priority'. */
+
         /* First, let's try to read the entry with the new format, which should replace the old format pretty
          * quickly. */
-
         r = readlinkat_malloc(dirfd, id, &buf);
         if (r >= 0) {
                 char *colon;
@@ -139,6 +141,9 @@ static int stack_directory_read_one(int dirfd, const char *id, char **devnode, i
                 if (r < 0)
                         return r;
 
+                if (!devnode)
+                        goto finalize;
+
                 if (*devnode && tmp_prio <= *priority)
                         return 0; /* Unchanged */
 
@@ -160,6 +165,9 @@ static int stack_directory_read_one(int dirfd, const char *id, char **devnode, i
                 if (r < 0)
                         return r;
 
+                if (!devnode)
+                        goto finalize;
+
                 if (*devnode && tmp_prio <= *priority)
                         return 0; /* Unchanged */
 
@@ -174,6 +182,7 @@ static int stack_directory_read_one(int dirfd, const char *id, char **devnode, i
         } else
                 return r == -ENOENT ? -ENODEV : r;
 
+finalize:
         *priority = tmp_prio;
         return 1; /* Updated */
 }