static const char *arg_hwdb_bin_dir = "/etc/udev";
static const char *arg_root = "";
+static bool arg_strict;
static const char * const conf_file_dirs[] = {
"/etc/udev/hwdb.d",
_cleanup_strv_free_ char **match_list = NULL;
uint32_t line_number = 0;
char *match = NULL;
- int r;
+ int r = 0, err;
f = fopen(filename, "re");
if (!f)
if (line[0] == ' ') {
log_syntax(NULL, LOG_WARNING, filename, line_number, EINVAL,
"Match expected but got indented property \"%s\", ignoring line", line);
+ r = -EINVAL;
break;
}
if (!match)
return -ENOMEM;
- r = strv_consume(&match_list, match);
- if (r < 0)
- return r;
+ err = strv_consume(&match_list, match);
+ if (err < 0)
+ return err;
break;
if (len == 0) {
log_syntax(NULL, LOG_WARNING, filename, line_number, EINVAL,
"Property expected, ignoring record with no properties");
-
+ r = -EINVAL;
state = HW_NONE;
strv_clear(match_list);
break;
if (!match)
return -ENOMEM;
- r = strv_consume(&match_list, match);
- if (r < 0)
- return r;
+ err = strv_consume(&match_list, match);
+ if (err < 0)
+ return err;
break;
}
/* first data */
state = HW_DATA;
- insert_data(trie, match_list, line, filename, file_priority, line_number);
+ err = insert_data(trie, match_list, line, filename, file_priority, line_number);
+ if (err < 0)
+ r = err;
break;
case HW_DATA:
if (line[0] != ' ') {
log_syntax(NULL, LOG_WARNING, filename, line_number, EINVAL,
"Property or empty line expected, got \"%s\", ignoring record", line);
+ r = -EINVAL;
state = HW_NONE;
strv_clear(match_list);
break;
}
- insert_data(trie, match_list, line, filename, file_priority, line_number);
+ err = insert_data(trie, match_list, line, filename, file_priority, line_number);
+ if (err < 0)
+ r = err;
break;
};
}
log_syntax(NULL, LOG_WARNING, filename, line_number, EINVAL,
"Property expected, ignoring record with no properties");
- return 0;
+ return r;
}
static int hwdb_query(int argc, char *argv[], void *userdata) {
_cleanup_strv_free_ char **files = NULL;
char **f;
uint16_t file_priority = 1;
- int r;
+ int r = 0, err;
trie = new0(struct trie, 1);
if (!trie)
trie->nodes_count++;
- r = conf_files_list_strv(&files, ".hwdb", arg_root, 0, conf_file_dirs);
- if (r < 0)
- return log_error_errno(r, "Failed to enumerate hwdb files: %m");
+ err = conf_files_list_strv(&files, ".hwdb", arg_root, 0, conf_file_dirs);
+ if (err < 0)
+ return log_error_errno(err, "Failed to enumerate hwdb files: %m");
STRV_FOREACH(f, files) {
log_debug("Reading file \"%s\"", *f);
- import_file(trie, *f, file_priority++);
+ err = import_file(trie, *f, file_priority++);
+ if (err < 0 && arg_strict)
+ r = err;
}
strbuf_complete(trie->strings);
return -ENOMEM;
mkdir_parents_label(hwdb_bin, 0755);
- r = trie_store(trie, hwdb_bin);
- if (r < 0)
- return log_error_errno(r, "Failure writing database %s: %m", hwdb_bin);
+ err = trie_store(trie, hwdb_bin);
+ if (err < 0)
+ return log_error_errno(err, "Failure writing database %s: %m", hwdb_bin);
+
+ err = label_fix(hwdb_bin, 0);
+ if (err < 0)
+ return err;
- return label_fix(hwdb_bin, 0);
+ return r;
}
static void help(void) {
"Update or query the hardware database.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
+ " -s --strict When updating, return non-zero exit value on any parsing\n"
+ " error\n"
" --usr Generate in " UDEVLIBEXECDIR " instead of /etc/udev\n"
" -r --root=PATH Alternative root path in the filesystem\n\n"
"Commands:\n"
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, ARG_VERSION },
{ "usr", no_argument, NULL, ARG_USR },
+ { "strict", no_argument, NULL, 's' },
{ "root", required_argument, NULL, 'r' },
{}
};
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "ut:r:h", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "ust:r:h", options, NULL)) >= 0) {
switch(c) {
case 'h':
arg_hwdb_bin_dir = UDEVLIBEXECDIR;
break;
+ case 's':
+ arg_strict = true;
+ break;
+
case 'r':
arg_root = optarg;
break;