From: Yu Watanabe Date: Tue, 5 Aug 2025 18:08:05 +0000 (+0900) Subject: udev-rules: add OPTIONS="dump-json" to dump current status in JSON format X-Git-Tag: v259-rc1~542 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd1351e3c83c8630edb971a50af6614ac5746081;p=thirdparty%2Fsystemd.git udev-rules: add OPTIONS="dump-json" to dump current status in JSON format This produces the output similar to 'udevadm test --json=short'. --- diff --git a/man/udev.xml b/man/udev.xml index 232dd4021cb..cd3d42133a8 100644 --- a/man/udev.xml +++ b/man/udev.xml @@ -729,6 +729,14 @@ SUBSYSTEM=="net", OPTIONS="log_level=debug" + + + + Similar to , but dump the status of the event in JSON format. + + + + diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index f82e18ee2aa..87c57d7487e 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1011,7 +1011,9 @@ static int parse_token( op = OP_ASSIGN; if (streq(value, "dump")) - r = rule_line_add_token(rule_line, TK_A_OPTIONS_DUMP, op, NULL, NULL, /* is_case_insensitive = */ false, token_str); + r = rule_line_add_token(rule_line, TK_A_OPTIONS_DUMP, op, NULL, UINT_TO_PTR(SD_JSON_FORMAT_OFF), /* is_case_insensitive = */ false, token_str); + else if (streq(value, "dump-json")) + r = rule_line_add_token(rule_line, TK_A_OPTIONS_DUMP, op, NULL, UINT_TO_PTR(SD_JSON_FORMAT_NEWLINE), /* is_case_insensitive = */ false, token_str); else if (streq(value, "string_escape=none")) r = rule_line_add_token(rule_line, TK_A_OPTIONS_STRING_ESCAPE_NONE, op, NULL, NULL, /* is_case_insensitive = */ false, token_str); else if (streq(value, "string_escape=replace")) @@ -2593,6 +2595,8 @@ static int udev_rule_apply_token_to_event( return token_match_string(event, token, event->program_result, /* log_result = */ true); case TK_A_OPTIONS_DUMP: { + sd_json_format_flags_t flags = PTR_TO_UINT(token->data); + log_event_info(event, token, "Dumping current state:"); _cleanup_(memstream_done) MemStream m = {}; @@ -2600,7 +2604,7 @@ static int udev_rule_apply_token_to_event( if (!f) return log_oom(); - (void) dump_event(event, SD_JSON_FORMAT_OFF, f); + (void) dump_event(event, flags, f); _cleanup_free_ char *buf = NULL; r = memstream_finalize(&m, &buf, NULL);