]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Add systemd.default_debug_tty=
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 8 Feb 2024 09:54:54 +0000 (10:54 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 9 Feb 2024 10:47:53 +0000 (11:47 +0100)
Let's allow configuring the debug tty independently of enabling/disabling
the debug shell. This allows mkosi to configure the correct tty while
leaving enabling/disabling the debug tty to the user.

man/kernel-command-line.xml
man/systemd-debug-generator.xml
src/debug-generator/debug-generator.c
test/units/testsuite-81.debug-generator.sh

index 8f179deec83d39a75e22c63ce89d8727ec231a2f..d4b005f8769f581f458ceb8e6b634f066e2a4172 100644 (file)
@@ -86,6 +86,7 @@
         <term><varname>systemd.mask=</varname></term>
         <term><varname>systemd.wants=</varname></term>
         <term><varname>systemd.debug_shell</varname></term>
+        <term><varname>systemd.default_debug_tty=</varname></term>
         <listitem>
           <para>Additional parameters understood by
           <citerefentry><refentrytitle>systemd-debug-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
index 5d2dbe2cd5f284a0ed613e19bb707a50973e306f..2f27f0fe4eeb304e0a960064bd83ce170a57eb9d 100644 (file)
     RAM disk (initrd) while <option>systemd.wants=</option> is
     honored only in the main system.</para>
 
-    <para>If the <option>systemd.debug_shell</option> or
-    <option>rd.systemd.debug_shell</option> option is
-    specified, the debug shell service
-    <literal>debug-shell.service</literal> is pulled into the boot
-    transaction and a debug shell will be spawned during early boot.
-    By default, <filename>&DEBUGTTY;</filename> is used, but a specific tty can also be set,
-    either with or without the <filename>/dev/</filename> prefix.
-    Note that the shell may also be turned on persistently by enabling it with
-    <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
-    <command>enable</command> command.
-    <option>rd.systemd.debug_shell=</option> is honored only by initial
-    RAM disk (initrd) while <option>systemd.debug_shell</option> is
-    honored only in the main system.</para>
+    <para>If the <option>systemd.debug_shell</option> or <option>rd.systemd.debug_shell</option> option is
+    specified, the debug shell service <literal>debug-shell.service</literal> is pulled into the boot
+    transaction and a debug shell will be spawned during early boot. By default,
+    <filename>&DEBUGTTY;</filename> is used, but a specific tty can also be specified, either with or without
+    the <filename>/dev/</filename> prefix. To set the tty to use without enabling the debug shell, the
+    <option>systemd.default_debug_tty=</option> option can be used which also takes a tty with or without the
+    <filename>/dev/</filename> prefix. Note that the shell may also be turned on persistently by enabling it
+    with <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
+    <command>enable</command> command. <option>rd.systemd.debug_shell=</option> is honored only by initial
+    RAM disk (initrd) while <option>systemd.debug_shell</option> is honored only in the main system.</para>
 
     <para><filename>systemd-debug-generator</filename> implements
     <citerefentry><refentrytitle>systemd.generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
index 8a474c58cfa4e738a525e708ae1423ce6dd7e715..741b59f32024b3fd720d9eee74b090d6c9df74ee 100644 (file)
@@ -20,12 +20,15 @@ static const char *arg_dest = NULL;
 static char *arg_default_unit = NULL;
 static char **arg_mask = NULL;
 static char **arg_wants = NULL;
-static char *arg_debug_shell = NULL;
+static bool arg_debug_shell = false;
+static char *arg_debug_tty = NULL;
+static char *arg_default_debug_tty = NULL;
 
 STATIC_DESTRUCTOR_REGISTER(arg_default_unit, freep);
 STATIC_DESTRUCTOR_REGISTER(arg_mask, strv_freep);
 STATIC_DESTRUCTOR_REGISTER(arg_wants, strv_freep);
-STATIC_DESTRUCTOR_REGISTER(arg_debug_shell, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_debug_tty, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_default_debug_tty, freep);
 
 static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
         int r;
@@ -61,15 +64,18 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
                         return log_oom();
 
         } else if (proc_cmdline_key_streq(key, "systemd.debug_shell")) {
-                const char *t = NULL;
-
                 r = value ? parse_boolean(value) : 1;
-                if (r < 0)
-                        t = skip_dev_prefix(value);
-                else if (r > 0)
-                        t = skip_dev_prefix(DEBUGTTY);
+                arg_debug_shell = r != 0;
+                if (r >= 0)
+                        return 0;
+
+                return free_and_strdup_warn(&arg_debug_tty, skip_dev_prefix(value));
+
+        } else if (proc_cmdline_key_streq(key, "systemd.default_debug_tty")) {
+                if (proc_cmdline_value_missing(key, value))
+                        return 0;
 
-                return free_and_strdup_warn(&arg_debug_shell, t);
+                return free_and_strdup_warn(&arg_default_debug_tty, skip_dev_prefix(value));
 
         } else if (streq(key, "systemd.unit")) {
 
@@ -136,9 +142,10 @@ static int generate_wants_symlinks(void) {
 }
 
 static void install_debug_shell_dropin(const char *dir) {
+        const char *tty = arg_debug_tty ?: arg_default_debug_tty;
         int r;
 
-        if (streq(arg_debug_shell, skip_dev_prefix(DEBUGTTY)))
+        if (!tty || path_equal(tty, skip_dev_prefix(DEBUGTTY)))
                 return;
 
         r = write_drop_in_format(dir, "debug-shell.service", 50, "tty",
@@ -147,7 +154,7 @@ static void install_debug_shell_dropin(const char *dir) {
                         "ConditionPathExists=\n"
                         "[Service]\n"
                         "TTYPath=/dev/%s",
-                        arg_debug_shell, arg_debug_shell);
+                        tty, tty);
         if (r < 0)
                 log_warning_errno(r, "Failed to write drop-in for debug-shell.service, ignoring: %m");
 }
index fddf85a54c661510eb1587f765d491571a9d99e3..ef1e205aacfeee6fda2048b391374d81a20e177a 100755 (executable)
@@ -62,6 +62,13 @@ SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
 link_endswith "$OUT_DIR/early/default.target.wants/debug-shell.service" /lib/systemd/system/debug-shell.service
 grep -F "/dev/tty666" "$OUT_DIR/early/debug-shell.service.d/50-tty.conf"
 
+# Same thing, but with custom tty using systemd.default_debug_tty
+: "debug-shell: regular + systemd.default_debug_tty=/dev/tty666 systemd.debug_shell=yes"
+CMDLINE="$CMDLINE systemd.default_debug_tty=/dev/tty666 systemd.debug_shell=yes"
+SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
+link_endswith "$OUT_DIR/early/default.target.wants/debug-shell.service" /lib/systemd/system/debug-shell.service
+grep -F "/dev/tty666" "$OUT_DIR/early/debug-shell.service.d/50-tty.conf"
+
 # Now override the default target via systemd.unit=
 : "debug-shell: regular + systemd.unit="
 CMDLINE="$CMDLINE systemd.unit=my-fancy.target"