udev-rule: rework logging about udev rules

This makes the loggers take the most relevant object, i.e. when
applying udev rules to a device, the loggers take sd_device and
UdevRuleToken object, and when parsing udev rules, they take
UdevRuleLine or UdevRuleFile object.

To achieve that, this drops 'iterators' in UdevRules or friends named
`current_file` or so. Instead of that, each object now has its
parent object, e.g. UdevRuleToken.rule_line that references the
UdevRuleLine object the token belonging to. And each function previously
took UdevRules object now takes the most relevant object, e.g. UdevRuleToken.

Solves the discussion in https://github.com/systemd/systemd/pull/26698#discussion_r1129261193.
This commit is contained in:
Yu Watanabe
2023-03-13 21:25:45 +09:00
parent 560900be67
commit c06ab041c7
4 changed files with 448 additions and 452 deletions
+3 -4
View File
@@ -27,11 +27,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
fflush(f);
assert_se(rules = udev_rules_new(RESOLVE_NAME_EARLY));
r = udev_rules_parse_file(rules, filename);
r = udev_rules_parse_file(rules, filename, NULL);
log_info_errno(r, "Parsing %s: %m", filename);
assert_se(IN_SET(r,
0, /* OK */
-ENOBUFS /* line length exceeded */));
assert_se(r >= 0 || /* OK */
r == -ENOBUFS); /* line length exceeded */
return 0;
}
+437 -444
View File
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -6,6 +6,7 @@
#include "time-util.h"
#include "udev-util.h"
typedef struct UdevRuleFile UdevRuleFile;
typedef struct UdevRules UdevRules;
typedef struct UdevEvent UdevEvent;
@@ -17,8 +18,8 @@ typedef enum {
_ESCAPE_TYPE_INVALID = -EINVAL,
} UdevRuleEscapeType;
int udev_rules_parse_file(UdevRules *rules, const char *filename);
unsigned udev_check_current_rule_file(UdevRules *rules);
int udev_rules_parse_file(UdevRules *rules, const char *filename, UdevRuleFile **ret);
unsigned udev_rule_file_get_issues(UdevRuleFile *rule_file);
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);
+5 -2
View File
@@ -101,13 +101,16 @@ static int parse_argv(int argc, char *argv[]) {
}
static int verify_rules_file(UdevRules *rules, const char *fname) {
UdevRuleFile *file;
int r;
r = udev_rules_parse_file(rules, fname);
r = udev_rules_parse_file(rules, fname, &file);
if (r < 0)
return log_error_errno(r, "Failed to parse rules file %s: %m", fname);
if (r == 0) /* empty file. */
return 0;
unsigned issues = udev_check_current_rule_file(rules);
unsigned issues = udev_rule_file_get_issues(file);
unsigned mask = (1U << LOG_ERR) | (1U << LOG_WARNING);
if (issues & mask)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),