diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fuzz/fuzz-udev-rules.c | 2 | ||||
-rw-r--r-- | src/test/test-udev.c | 2 | ||||
-rw-r--r-- | src/udev/udev-rules.c | 30 | ||||
-rw-r--r-- | src/udev/udev-rules.h | 4 | ||||
-rw-r--r-- | src/udev/udevadm-test.c | 2 | ||||
-rw-r--r-- | src/udev/udevd.c | 4 |
6 files changed, 27 insertions, 17 deletions
diff --git a/src/fuzz/fuzz-udev-rules.c b/src/fuzz/fuzz-udev-rules.c index 3194f7aa88..a4a1adec3e 100644 --- a/src/fuzz/fuzz-udev-rules.c +++ b/src/fuzz/fuzz-udev-rules.c @@ -99,7 +99,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { assert_se(fwrite(data, size, 1, f) == 1); assert_se(fclose(f) == 0); - assert_se(udev_rules_new(&rules, RESOLVE_NAME_EARLY) == 0); + assert_se(udev_rules_load(&rules, RESOLVE_NAME_EARLY) == 0); assert_se(cleanup_fake_filesystems(runtime_dir) >= 0); return 0; diff --git a/src/test/test-udev.c b/src/test/test-udev.c index 2c32f898c6..493d6df2a8 100644 --- a/src/test/test-udev.c +++ b/src/test/test-udev.c @@ -87,7 +87,7 @@ static int run(int argc, char *argv[]) { action = argv[1]; devpath = argv[2]; - assert_se(udev_rules_new(&rules, RESOLVE_NAME_EARLY) == 0); + assert_se(udev_rules_load(&rules, RESOLVE_NAME_EARLY) == 0); const char *syspath = strjoina("/sys", devpath); r = device_new_from_synthetic_event(&dev, syspath, action); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 1b501da39f..95951bceef 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1175,7 +1175,7 @@ static void rule_resolve_goto(UdevRuleFile *rule_file) { } } -static int parse_file(UdevRules *rules, const char *filename) { +int udev_rules_parse_file(UdevRules *rules, const char *filename) { _cleanup_free_ char *continuation = NULL, *name = NULL; _cleanup_fclose_ FILE *f = NULL; UdevRuleFile *rule_file; @@ -1278,30 +1278,38 @@ static int parse_file(UdevRules *rules, const char *filename) { return 0; } -int udev_rules_new(UdevRules **ret_rules, ResolveNameTiming resolve_name_timing) { - _cleanup_(udev_rules_freep) UdevRules *rules = NULL; - _cleanup_strv_free_ char **files = NULL; - char **f; - int r; - +UdevRules* udev_rules_new(ResolveNameTiming resolve_name_timing) { assert(resolve_name_timing >= 0 && resolve_name_timing < _RESOLVE_NAME_TIMING_MAX); - rules = new(UdevRules, 1); + UdevRules *rules = new(UdevRules, 1); if (!rules) - return -ENOMEM; + return NULL; *rules = (UdevRules) { .resolve_name_timing = resolve_name_timing, }; + return rules; +} + +int udev_rules_load(UdevRules **ret_rules, ResolveNameTiming resolve_name_timing) { + _cleanup_(udev_rules_freep) UdevRules *rules = NULL; + _cleanup_strv_free_ char **files = NULL; + char **f; + int r; + + rules = udev_rules_new(resolve_name_timing); + if (!rules) + return -ENOMEM; + (void) udev_rules_check_timestamp(rules); r = conf_files_list_strv(&files, ".rules", NULL, 0, RULES_DIRS); if (r < 0) - return log_error_errno(r, "Failed to enumerate rules files: %m"); + return log_debug_errno(r, "Failed to enumerate rules files: %m"); STRV_FOREACH(f, files) - (void) parse_file(rules, *f); + (void) udev_rules_parse_file(rules, *f); *ret_rules = TAKE_PTR(rules); return 0; diff --git a/src/udev/udev-rules.h b/src/udev/udev-rules.h index 6d94a468c3..cdb98e8cec 100644 --- a/src/udev/udev-rules.h +++ b/src/udev/udev-rules.h @@ -16,7 +16,9 @@ typedef enum { _ESCAPE_TYPE_INVALID = -1 } UdevRuleEscapeType; -int udev_rules_new(UdevRules **ret_rules, ResolveNameTiming resolve_name_timing); +int udev_rules_parse_file(UdevRules *rules, const char *filename); +UdevRules* udev_rules_new(ResolveNameTiming resolve_name_timing); +int udev_rules_load(UdevRules **ret_rules, ResolveNameTiming resolve_name_timing); UdevRules *udev_rules_free(UdevRules *rules); DEFINE_TRIVIAL_CLEANUP_FUNC(UdevRules*, udev_rules_free); diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index 3f8bdc2812..5b9b65439a 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -123,7 +123,7 @@ int test_main(int argc, char *argv[], void *userdata) { udev_builtin_init(); - r = udev_rules_new(&rules, arg_resolve_name_timing); + r = udev_rules_load(&rules, arg_resolve_name_timing); if (r < 0) { log_error_errno(r, "Failed to read udev rules: %m"); goto out; diff --git a/src/udev/udevd.c b/src/udev/udevd.c index d86c1484c3..db24caf00d 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -925,7 +925,7 @@ static void event_queue_start(Manager *manager) { udev_builtin_init(); if (!manager->rules) { - r = udev_rules_new(&manager->rules, arg_resolve_name_timing); + r = udev_rules_load(&manager->rules, arg_resolve_name_timing); if (r < 0) { log_warning_errno(r, "Failed to read udev rules: %m"); return; @@ -1787,7 +1787,7 @@ static int main_loop(Manager *manager) { udev_builtin_init(); - r = udev_rules_new(&manager->rules, arg_resolve_name_timing); + r = udev_rules_load(&manager->rules, arg_resolve_name_timing); if (!manager->rules) return log_error_errno(r, "Failed to read udev rules: %m"); |