systemd/0172-udev-rules-add-trace-logs-for-GOTO-and-parent-condit.patch
Jan Macku 490ac630af systemd-257-4
Resolves: RHEL-57603,RHEL-73780,RHEL-75774
2025-01-30 09:29:29 +01:00

104 lines
4.6 KiB
Diff

From 7f14a15e480fd4392bc86f7927c9b14dfe833d83 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 13 Jan 2025 05:18:25 +0900
Subject: [PATCH] udev-rules: add trace logs for GOTO and parent conditions
(cherry picked from commit c547b9e278b86cd2318cb69319aaadad9004d96a)
Resolves: RHEL-75774
---
src/udev/udev-rules.c | 48 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 43 insertions(+), 5 deletions(-)
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index c5fa2c660c..4f2021b8c4 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -345,6 +345,20 @@ static bool token_is_for_parents(UdevRuleToken *token) {
#define log_event_truncated(event, token, what, format) \
_log_event_truncated(event, token, UNIQ_T(t, UNIQ), what, format)
+#define _log_event_line(event, event_u, line, ...) \
+ ({ \
+ UdevEvent *event_u = ASSERT_PTR(event); \
+ \
+ event_u->trace ? \
+ log_udev_rule_line_full( \
+ event_u->dev, line, \
+ LOG_DEBUG, 0, __VA_ARGS__) : \
+ 0; \
+ })
+
+#define log_event_line(event, line, ...) \
+ _log_event_line(event, UNIQ_T(e, UNIQ), line, __VA_ARGS__)
+
/* Mainly used when parsing .rules files. */
#define log_file_full_errno_zerook(...) \
log_udev_rule_file_full(NULL, __VA_ARGS__)
@@ -2977,14 +2991,30 @@ static int udev_rule_apply_parent_token_to_event(UdevRuleToken *head_token, Udev
int r;
assert(head_token);
+ assert(token_is_for_parents(head_token));
assert(event);
+ UdevRuleLine *line = head_token->rule_line;
+ if (event->trace) {
+ _cleanup_free_ char *joined = NULL;
+
+ LIST_FOREACH(tokens, token, head_token)
+ if (token_is_for_parents(token))
+ (void) strextend_with_separator(&joined, ", ", token->token_str);
+ else
+ break;
+
+ log_event_line(event, line, "Checking conditions for parent devices: %s", strna(joined));
+ }
+
event->dev_parent = ASSERT_PTR(event->dev);
for (;;) {
LIST_FOREACH(tokens, token, head_token) {
- if (!token_is_for_parents(token))
- return true; /* All parent tokens match. */
+ if (!token_is_for_parents(token)) {
+ r = 1; /* avoid false maybe-uninitialized warning */
+ break; /* All parent tokens match. */
+ }
r = udev_rule_apply_token_to_event(token, event->dev_parent, event);
if (r < 0)
@@ -2992,12 +3022,18 @@ static int udev_rule_apply_parent_token_to_event(UdevRuleToken *head_token, Udev
if (r == 0)
break;
}
- if (r > 0)
- /* All parent tokens match, and no more token (except for GOTO) in the line. */
+ if (r > 0) {
+ if (event->trace) {
+ const char *s = NULL;
+ (void) sd_device_get_syspath(event->dev_parent, &s);
+ log_event_line(event, line, "Parent device \"%s\" passed all parent conditions.", strna(s));
+ }
return true;
+ }
if (sd_device_get_parent(event->dev_parent, &event->dev_parent) < 0) {
event->dev_parent = NULL;
+ log_event_line(event, line, "No parent device passed parent conditions.");
return false;
}
}
@@ -3054,8 +3090,10 @@ static int udev_rule_apply_line_to_event(
return r;
}
- if (line->goto_line)
+ if (line->goto_line) {
+ log_event_line(event, line, "GOTO=%s", strna(line->goto_label));
*next_line = line->goto_line; /* update next_line only when the line has GOTO token. */
+ }
return 0;
}