1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 09:21:26 +03:00

udev: builtin - do not fail builtin initialization if one of them returns an error

This commit is contained in:
Kay Sievers 2012-10-26 03:43:56 +02:00
parent a4bcff5ba3
commit 4af113f997
3 changed files with 16 additions and 21 deletions

View File

@ -311,11 +311,14 @@ static int builtin_hwdb_init(struct udev *udev)
return 0;
trie.f = fopen(SYSCONFDIR "/udev/hwdb.bin", "re");
if (!trie.f)
if (!trie.f) {
if (errno != EEXIST)
log_error("Error reading " SYSCONFDIR "/udev/hwdb.bin: %m");
return -errno;
}
if (fstat(fileno(trie.f), &st) < 0 || (size_t)st.st_size < offsetof(struct trie_header_f, strings_len) + 8) {
log_error("Error reading '%s'.", SYSCONFDIR "/udev/hwdb.bin: %m");
log_error("Error reading " SYSCONFDIR "/udev/hwdb.bin: %m");
fclose(trie.f);
zero(trie);
return -EINVAL;
@ -323,7 +326,7 @@ static int builtin_hwdb_init(struct udev *udev)
trie.map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fileno(trie.f), 0);
if (trie.map == MAP_FAILED) {
log_error("Error mapping '%s'.", SYSCONFDIR "/udev/hwdb.bin: %m");
log_error("Error mapping " SYSCONFDIR "/udev/hwdb.bin: %m");
fclose(trie.f);
return -EINVAL;
}
@ -331,7 +334,7 @@ static int builtin_hwdb_init(struct udev *udev)
trie.map_size = st.st_size;
if (memcmp(trie.map, sig, sizeof(trie.head->signature)) != 0 || (size_t)st.st_size != le64toh(trie.head->file_size)) {
log_error("Unable to recognize the format of '%s'.", SYSCONFDIR "/udev/hwdb.bin");
log_error("Unable to recognize the format of " SYSCONFDIR "/udev/hwdb.bin.");
log_error("Please try 'udevadm hwdb --update' to re-create it.");
munmap((void *)trie.map, st.st_size);
fclose(trie.f);

View File

@ -41,24 +41,18 @@ static const struct udev_builtin *builtins[] = {
#endif
};
int udev_builtin_init(struct udev *udev)
void udev_builtin_init(struct udev *udev)
{
unsigned int i;
int err = 0;
if (initialized)
return 0;
return;
for (i = 0; i < ELEMENTSOF(builtins); i++) {
if (builtins[i]->init) {
err = builtins[i]->init(udev);
if (err < 0)
break;
}
}
for (i = 0; i < ELEMENTSOF(builtins); i++)
if (builtins[i]->init)
builtins[i]->init(udev);
initialized = true;
return err;
}
void udev_builtin_exit(struct udev *udev)
@ -78,13 +72,11 @@ void udev_builtin_exit(struct udev *udev)
bool udev_builtin_validate(struct udev *udev)
{
unsigned int i;
bool change = false;
for (i = 0; i < ELEMENTSOF(builtins); i++)
if (builtins[i]->validate)
if (builtins[i]->validate(udev))
change = true;
return change;
if (builtins[i]->validate && builtins[i]->validate(udev))
return true;
return false;
}
void udev_builtin_list(struct udev *udev)

View File

@ -165,7 +165,7 @@ extern const struct udev_builtin udev_builtin_kmod;
extern const struct udev_builtin udev_builtin_path_id;
extern const struct udev_builtin udev_builtin_usb_id;
extern const struct udev_builtin udev_builtin_uaccess;
int udev_builtin_init(struct udev *udev);
void udev_builtin_init(struct udev *udev);
void udev_builtin_exit(struct udev *udev);
enum udev_builtin_cmd udev_builtin_lookup(const char *command);
const char *udev_builtin_name(enum udev_builtin_cmd cmd);