1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-22 06:50:18 +03:00

udevadm-control: allow to enable/disable trace logging in systemd-udevd

Should be useful for debugging udev rules.
This commit is contained in:
Yu Watanabe 2025-01-12 02:05:43 +09:00
parent 993b481ad1
commit 25a2e4738b
5 changed files with 37 additions and 2 deletions

View File

@ -743,6 +743,14 @@
<xi:include href="version-info.xml" xpointer="v241"/>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--trace=<replaceable>BOOL</replaceable></option></term>
<listitem>
<para>Enable/disable trace logging in <command>systemd-udevd</command>.</para>
<xi:include href="version-info.xml" xpointer="v258"/>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-t</option></term>
<term><option>--timeout=<replaceable>seconds</replaceable></option></term>

View File

@ -66,7 +66,7 @@ _udevadm() {
[SETTLE]='-t --timeout -E --exit-if-exists'
[CONTROL_STANDALONE]='-e --exit -s --stop-exec-queue -S --start-exec-queue -R --reload --ping
--load-credentials'
[CONTROL_ARG]='-l --log-priority -p --property -m --children-max -t --timeout'
[CONTROL_ARG]='-l --log-priority -p --property -m --children-max -t --timeout --trace'
[MONITOR_STANDALONE]='-k --kernel -u --udev -p --property'
[MONITOR_ARG]='-s --subsystem-match -t --tag-match'
[TEST_STANDALONE]='-v --verbose'
@ -191,6 +191,9 @@ _udevadm() {
-l|--log-priority)
comps='alert crit debug emerg err info notice warning'
;;
--trace)
comps='yes no'
;;
*)
comps=''
;;

View File

@ -66,6 +66,7 @@ _udevadm_control(){
'(-R --reload)'{-R,--reload}'[Signal systemd-udevd to reload the rules files and other databases like the kernel module index.]' \
'(-p --property)'{-p,--property=}'[Set a global property for all events.]:KEY=VALUE' \
'(-m --children-max=)'{-m,--children-max=}'[Set the maximum number of events.]:N' \
'--trace=[Enable/disable trace logging.]:BOOL' \
'(-t --timeout=)'{-t,--timeout=}'[The maximum number of seconds to wait for a reply from systemd-udevd.]:SECONDS'
}

View File

@ -10,6 +10,7 @@
#include "creds-util.h"
#include "errno-util.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "process-util.h"
#include "static-destruct.h"
@ -30,6 +31,7 @@ static bool arg_exit = false;
static int arg_max_children = -1;
static int arg_log_level = -1;
static int arg_start_exec_queue = -1;
static int arg_trace = -1;
static bool arg_load_credentials = false;
STATIC_DESTRUCTOR_REGISTER(arg_env, strv_freep);
@ -42,7 +44,8 @@ static bool arg_has_control_commands(void) {
arg_reload ||
!strv_isempty(arg_env) ||
arg_max_children >= 0 ||
arg_ping;
arg_ping ||
arg_trace >= 0;
}
static int help(void) {
@ -58,6 +61,7 @@ static int help(void) {
" -p --property=KEY=VALUE Set a global property for all events\n"
" -m --children-max=N Maximum number of children\n"
" --ping Wait for udev to respond to a ping message\n"
" --trace=BOOL Enable/disable trace logging\n"
" -t --timeout=SECONDS Maximum time to block for a reply\n"
" --load-credentials Load udev rules from credentials\n",
program_invocation_short_name);
@ -68,6 +72,7 @@ static int help(void) {
static int parse_argv(int argc, char *argv[]) {
enum {
ARG_PING = 0x100,
ARG_TRACE,
ARG_LOAD_CREDENTIALS,
};
@ -83,6 +88,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "env", required_argument, NULL, 'p' }, /* alias for -p */
{ "children-max", required_argument, NULL, 'm' },
{ "ping", no_argument, NULL, ARG_PING },
{ "trace", required_argument, NULL, ARG_TRACE },
{ "timeout", required_argument, NULL, 't' },
{ "load-credentials", no_argument, NULL, ARG_LOAD_CREDENTIALS },
{ "version", no_argument, NULL, 'V' },
@ -143,6 +149,14 @@ static int parse_argv(int argc, char *argv[]) {
arg_ping = true;
break;
case ARG_TRACE:
r = parse_boolean_argument("--trace=", optarg, NULL);
if (r < 0)
return r;
arg_trace = r;
break;
case 't':
r = parse_sec(optarg, &arg_timeout);
if (r < 0)
@ -296,6 +310,13 @@ static int send_control_commands(void) {
return r;
}
if (arg_trace >= 0) {
r = varlink_callbo_and_log(link, "io.systemd.Udev.SetTrace", /* reply = */ NULL,
SD_JSON_BUILD_PAIR_BOOLEAN("enable", arg_trace));
if (r < 0)
return r;
}
return 0;
}

View File

@ -52,6 +52,8 @@ udevadm control -R
udevadm control -p HELLO=world
udevadm control -m 42
udevadm control --ping -t 5
udevadm control --trace yes
udevadm control --trace no
udevadm control --load-credentials
udevadm control -h