mirror of
https://github.com/systemd/systemd.git
synced 2025-01-23 02:04:32 +03:00
udev: simplify a bit stack_directory_find_prioritized_devnode()
And make the new format the one we expect as it should replace the old one pretty quickly.
This commit is contained in:
parent
e8a54a4e75
commit
6d90488acb
@ -104,7 +104,8 @@ static int node_symlink(sd_device *dev, const char *devnode, const char *slink)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stack_directory_read_one(int dirfd, const char *id, bool is_symlink, char **devnode, int *priority) {
|
static int stack_directory_read_one(int dirfd, const char *id, char **devnode, int *priority) {
|
||||||
|
_cleanup_free_ char *buf = NULL;
|
||||||
int tmp_prio, r;
|
int tmp_prio, r;
|
||||||
|
|
||||||
assert(dirfd >= 0);
|
assert(dirfd >= 0);
|
||||||
@ -112,15 +113,14 @@ static int stack_directory_read_one(int dirfd, const char *id, bool is_symlink,
|
|||||||
assert(devnode);
|
assert(devnode);
|
||||||
assert(priority);
|
assert(priority);
|
||||||
|
|
||||||
if (is_symlink) {
|
/* First, let's try to read the entry with the new format, which should replace the old format pretty
|
||||||
_cleanup_free_ char *buf = NULL;
|
* quickly. */
|
||||||
|
|
||||||
|
r = readlinkat_malloc(dirfd, id, &buf);
|
||||||
|
if (r >= 0) {
|
||||||
char *colon;
|
char *colon;
|
||||||
|
|
||||||
/* New format. The devnode and priority can be obtained from symlink. */
|
/* With the new format, the devnode and priority can be obtained from symlink itself. */
|
||||||
|
|
||||||
r = readlinkat_malloc(dirfd, id, &buf);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
colon = strchr(buf, ':');
|
colon = strchr(buf, ':');
|
||||||
if (!colon || colon == buf)
|
if (!colon || colon == buf)
|
||||||
@ -146,7 +146,7 @@ static int stack_directory_read_one(int dirfd, const char *id, bool is_symlink,
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
} else {
|
} else if (r == -EINVAL) { /* Not a symlink ? try the old format */
|
||||||
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
|
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
|
||||||
const char *val;
|
const char *val;
|
||||||
|
|
||||||
@ -170,7 +170,9 @@ static int stack_directory_read_one(int dirfd, const char *id, bool is_symlink,
|
|||||||
r = free_and_strdup(devnode, val);
|
r = free_and_strdup(devnode, val);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
|
||||||
|
} else
|
||||||
|
return r == -ENOENT ? -ENODEV : r;
|
||||||
|
|
||||||
*priority = tmp_prio;
|
*priority = tmp_prio;
|
||||||
return 1; /* Updated */
|
return 1; /* Updated */
|
||||||
@ -213,22 +215,15 @@ static int stack_directory_find_prioritized_devnode(sd_device *dev, int dirfd, b
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
FOREACH_DIRENT_ALL(de, dir, break) {
|
FOREACH_DIRENT(de, dir, break) {
|
||||||
if (de->d_name[0] == '.')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* skip ourself */
|
/* skip ourself */
|
||||||
if (streq(de->d_name, id))
|
if (streq(de->d_name, id))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!IN_SET(de->d_type, DT_LNK, DT_REG))
|
r = stack_directory_read_one(dirfd, de->d_name, &devnode, &priority);
|
||||||
continue;
|
if (r < 0 && r != -ENODEV)
|
||||||
|
|
||||||
r = stack_directory_read_one(dirfd, de->d_name, /* is_symlink = */ de->d_type == DT_LNK, &devnode, &priority);
|
|
||||||
if (r < 0) {
|
|
||||||
log_debug_errno(r, "Failed to read '%s', ignoring: %m", de->d_name);
|
log_debug_errno(r, "Failed to read '%s', ignoring: %m", de->d_name);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*ret = TAKE_PTR(devnode);
|
*ret = TAKE_PTR(devnode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user