debug-generator: add new kernel cmdline option systemd.wants= to add units to the initial transaction

This commit is contained in:
Lennart Poettering 2014-06-20 13:30:52 +02:00
parent 6b66097b95
commit 3c5a87a879
3 changed files with 67 additions and 22 deletions

View File

@ -100,14 +100,15 @@
<varlistentry> <varlistentry>
<term><varname>systemd.mask=</varname></term> <term><varname>systemd.mask=</varname></term>
<term><varname>systemd.wants=</varname></term>
<term><varname>systemd.debug-shell</varname></term> <term><varname>systemd.debug-shell</varname></term>
<listitem> <listitem>
<para>Additional parameters <para>Additional parameters
understood by understood by
<citerefentry><refentrytitle>systemd-debug-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>, <citerefentry><refentrytitle>systemd-debug-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
to mask specific units at to mask or start specific
boot, or invoke a debug shell units at boot, or invoke a
on tty9.</para> debug shell on tty9.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@ -53,7 +53,8 @@
<title>Description</title> <title>Description</title>
<para><filename>systemd-debug-generator</filename> is <para><filename>systemd-debug-generator</filename> is
a generator that reads the kernel command line and understands two options:</para> a generator that reads the kernel command line and
understands three options:</para>
<para>If the <option>systemd.mask=</option> option is <para>If the <option>systemd.mask=</option> option is
specified and followed by a unit name this unit is specified and followed by a unit name this unit is
@ -61,7 +62,14 @@
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
<command>mask</command> command. This is useful to <command>mask</command> command. This is useful to
boot with certain units removed from the initial boot boot with certain units removed from the initial boot
transaction for debugging system startup.</para> transaction for debugging system startup. May be
specified more than once.</para>
<para>If the <option>systemd.wants=</option> option is
specified and followed by a unit name a start job for
this unit is added to the initial transaction. This is
useful to start one ore more additional units at
boot. May be specified more than once.</para>
<para>If the <option>systemd.debug-shell</option> <para>If the <option>systemd.debug-shell</option>
option is specified the debug shell service option is specified the debug shell service

View File

@ -26,11 +26,14 @@
static const char *arg_dest = "/tmp"; static const char *arg_dest = "/tmp";
static char **arg_mask = NULL; static char **arg_mask = NULL;
static char **arg_wants = NULL;
static bool arg_debug_shell = false; static bool arg_debug_shell = false;
static int parse_proc_cmdline_item(const char *key, const char *value) { static int parse_proc_cmdline_item(const char *key, const char *value) {
int r; int r;
assert(key);
if (streq(key, "systemd.mask")) { if (streq(key, "systemd.mask")) {
if (!value) if (!value)
@ -38,7 +41,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
else { else {
char *n; char *n;
n = strdup(value); n = unit_name_mangle(value, MANGLE_NOGLOB);
if (!n) if (!n)
return log_oom(); return log_oom();
@ -46,6 +49,23 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
} }
} else if (streq(key, "systemd.wants")) {
if (!value)
log_error("Missing argument for systemd.want= kernel command line parameter.");
else {
char *n;
n = unit_name_mangle(value, MANGLE_NOGLOB);
if (!n)
return log_oom();
r = strv_consume(&arg_wants, n);
if (r < 0)
return log_oom();
}
} else if (streq(key, "systemd.debug-shell")) { } else if (streq(key, "systemd.debug-shell")) {
if (value) { if (value) {
@ -69,13 +89,9 @@ static int generate_mask_symlinks(void) {
return 0; return 0;
STRV_FOREACH(u, arg_mask) { STRV_FOREACH(u, arg_mask) {
_cleanup_free_ char *m = NULL, *p = NULL; _cleanup_free_ char *p = NULL;
m = unit_name_mangle(*u, MANGLE_NOGLOB); p = strjoin(arg_dest, "/", *u, NULL);
if (!m)
return log_oom();
p = strjoin(arg_dest, "/", m, NULL);
if (!p) if (!p)
return log_oom(); return log_oom();
@ -88,22 +104,33 @@ static int generate_mask_symlinks(void) {
return r; return r;
} }
static int generate_debug_shell_symlink(void) { static int generate_wants_symlinks(void) {
const char *p; char **u;
int r = 0;
if (!arg_debug_shell) if (strv_isempty(arg_wants))
return 0; return 0;
p = strappenda(arg_dest, "/default.target.wants/debug-shell.service"); STRV_FOREACH(u, arg_wants) {
_cleanup_free_ char *p = NULL, *f = NULL;
mkdir_parents_label(p, 0755); p = strjoin(arg_dest, "/default.target.wants/", *u, NULL);
if (!p)
return log_oom();
if (symlink(SYSTEM_DATA_UNIT_PATH "/debug-shell.service", p) < 0) { f = strappend(SYSTEM_DATA_UNIT_PATH "/", *u);
log_error("Failed to create %s symlink: %m", p); if (!f)
return -errno; return log_oom();
mkdir_parents_label(p, 0755);
if (symlink(f, p) < 0) {
log_error("Failed to create wants symlink %s: %m", p);
r = -errno;
}
} }
return 0; return r;
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -126,12 +153,21 @@ int main(int argc, char *argv[]) {
if (parse_proc_cmdline(parse_proc_cmdline_item) < 0) if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
if (arg_debug_shell) {
r = strv_extend(&arg_wants, "debug-shell.service");
if (r < 0) {
r = log_oom();
goto finish;
}
}
r = generate_mask_symlinks(); r = generate_mask_symlinks();
q = generate_debug_shell_symlink(); q = generate_wants_symlinks();
if (q < 0) if (q < 0)
r = q; r = q;
finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} }