]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm-control: allow to enable/disable trace logging in systemd-udevd 36070/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 11 Jan 2025 17:05:43 +0000 (02:05 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 20 Jan 2025 19:12:18 +0000 (04:12 +0900)
Should be useful for debugging udev rules.

man/udevadm.xml
shell-completion/bash/udevadm
shell-completion/zsh/_udevadm
src/udev/udevadm-control.c
test/units/TEST-17-UDEV.10.sh

index 07169f2e504a1a69affbc7a71574ab606dd8573a..01d662a0767a6c1c283bc940c5ddd847e68a0cd5 100644 (file)
             <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>
index c4aea7039c620633ede9e76847479c2095b6e6af..c8a08f68d74e75941e8df324cb9776ee3e39c6e8 100644 (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=''
                         ;;
index c0141e5cd381a787ad0df68fe91ba171fa7e9ee4..8a88aa694e02874a42da2a4f24e75b603ab43961 100644 (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'
 }
 
index 3ccc6213570c8f530a2dad54e9e5fb35a4a81917..1fa5a42018295889a63babefa8a7603534e35b64 100644 (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;
 }
 
index 5ee1cd3e429fc9e93795dc92272c018d3c64768f..8643e9e6bb48a44705143a930a6a4df68d58160b 100755 (executable)
@@ -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