static int hwdb_new(const char *path, sd_hwdb **ret) {
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
- const char *hwdb_bin_path = NULL;
const char sig[] = HWDB_SIG;
assert_return(ret, -EINVAL);
hwdb->n_ref = 1;
- /* find hwdb.bin in hwdb_bin_paths, or from an explicit path if provided */
+ /* Find hwdb.bin in the explicit path if provided, or iterate over hwdb_bin_paths otherwise */
if (!isempty(path)) {
log_debug("Trying to open \"%s\"...", path);
hwdb->f = fopen(path, "re");
if (!hwdb->f)
return log_debug_errno(errno, "Failed to open %s: %m", path);
} else {
- NULSTR_FOREACH(hwdb_bin_path, hwdb_bin_paths) {
- log_debug("Trying to open \"%s\"...", hwdb_bin_path);
- hwdb->f = fopen(hwdb_bin_path, "re");
+ NULSTR_FOREACH(path, hwdb_bin_paths) {
+ log_debug("Trying to open \"%s\"...", path);
+ hwdb->f = fopen(path, "re");
if (hwdb->f)
break;
if (errno != ENOENT)
- return log_debug_errno(errno, "Failed to open %s: %m", hwdb_bin_path);
+ return log_debug_errno(errno, "Failed to open %s: %m", path);
}
if (!hwdb->f)
}
if (fstat(fileno(hwdb->f), &hwdb->st) < 0)
- return log_debug_errno(errno, "Failed to stat %s: %m", hwdb_bin_path);
+ return log_debug_errno(errno, "Failed to stat %s: %m", path);
if (hwdb->st.st_size < (off_t) offsetof(struct trie_header_f, strings_len) + 8)
- return log_debug_errno(SYNTHETIC_ERRNO(EIO),
- "File %s is too short: %m", hwdb_bin_path);
+ return log_debug_errno(SYNTHETIC_ERRNO(EIO), "File %s is too short: %m", path);
if (file_offset_beyond_memory_size(hwdb->st.st_size))
- return log_debug_errno(SYNTHETIC_ERRNO(EFBIG),
- "File %s is too long: %m", hwdb_bin_path);
+ return log_debug_errno(SYNTHETIC_ERRNO(EFBIG), "File %s is too long: %m", path);
hwdb->map = mmap(0, hwdb->st.st_size, PROT_READ, MAP_SHARED, fileno(hwdb->f), 0);
if (hwdb->map == MAP_FAILED)
- return log_debug_errno(errno, "Failed to map %s: %m", hwdb_bin_path);
+ return log_debug_errno(errno, "Failed to map %s: %m", path);
if (memcmp(hwdb->map, sig, sizeof(hwdb->head->signature)) != 0 ||
(size_t) hwdb->st.st_size != le64toh(hwdb->head->file_size))
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
- "Failed to recognize the format of %s",
- hwdb_bin_path);
+ "Failed to recognize the format of %s", path);
log_debug("=== trie on-disk ===");
log_debug("tool version: %"PRIu64, le64toh(hwdb->head->tool_version));