From: Yu Watanabe Date: Mon, 20 Feb 2023 05:43:58 +0000 (+0900) Subject: udev-node: make stack_directory_read_one() accept NULL for devnode X-Git-Tag: v254-rc1~1232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=135e5a201a3eb411a6767c1c16e704eaa0431d33;p=thirdparty%2Fsystemd.git udev-node: make stack_directory_read_one() accept NULL for devnode No functional change, as currently the function is always called with non-NULL argument. Just a preparation for #26048 or #25839. --- diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 5f3dc61f09f..e49e959cd80 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -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 */ }