summaryrefslogtreecommitdiff
path: root/src/systemd-debug-generator
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-05-10 15:51:29 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-05-10 15:51:29 -0400
commit7ad5d6bf5d7fcc61eace7e933b305f69d439fcc9 (patch)
treebaae5aa0698a26b78b9965fb1a49d1efc7b42ed5 /src/systemd-debug-generator
parent93010a5bde39a26d51751edee9276c4c514f7bf4 (diff)
./tools/notsd-move
Diffstat (limited to 'src/systemd-debug-generator')
l---------src/systemd-debug-generator/GNUmakefile1
-rw-r--r--src/systemd-debug-generator/Makefile34
-rw-r--r--src/systemd-debug-generator/debug-generator.c202
-rw-r--r--src/systemd-debug-generator/systemd-debug-generator.xml95
4 files changed, 332 insertions, 0 deletions
diff --git a/src/systemd-debug-generator/GNUmakefile b/src/systemd-debug-generator/GNUmakefile
new file mode 120000
index 0000000000..0f24a727ed
--- /dev/null
+++ b/src/systemd-debug-generator/GNUmakefile
@@ -0,0 +1 @@
+GNUmakefile \ No newline at end of file
diff --git a/src/systemd-debug-generator/Makefile b/src/systemd-debug-generator/Makefile
new file mode 100644
index 0000000000..542d8b5a5a
--- /dev/null
+++ b/src/systemd-debug-generator/Makefile
@@ -0,0 +1,34 @@
+# -*- Mode: makefile; indent-tabs-mode: t -*-
+#
+# This file is part of systemd.
+#
+# Copyright 2010-2012 Lennart Poettering
+# Copyright 2010-2012 Kay Sievers
+# Copyright 2013 Zbigniew Jędrzejewski-Szmek
+# Copyright 2013 David Strauss
+# Copyright 2016 Luke Shumaker
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# systemd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with systemd; If not, see <http://www.gnu.org/licenses/>.
+include $(dir $(lastword $(MAKEFILE_LIST)))/../../config.mk
+include $(topsrcdir)/build-aux/Makefile.head.mk
+
+systemgenerator_PROGRAMS += systemd-debug-generator
+
+systemd_debug_generator_SOURCES = \
+ src/debug-generator/debug-generator.c
+
+systemd_debug_generator_LDADD = \
+ libsystemd-shared.la
+
+include $(topsrcdir)/build-aux/Makefile.tail.mk
diff --git a/src/systemd-debug-generator/debug-generator.c b/src/systemd-debug-generator/debug-generator.c
new file mode 100644
index 0000000000..88324894ac
--- /dev/null
+++ b/src/systemd-debug-generator/debug-generator.c
@@ -0,0 +1,202 @@
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "systemd-basic/alloc-util.h"
+#include "systemd-basic/mkdir.h"
+#include "systemd-basic/parse-util.h"
+#include "systemd-basic/proc-cmdline.h"
+#include "systemd-basic/special.h"
+#include "systemd-basic/string-util.h"
+#include "systemd-basic/strv.h"
+#include "systemd-basic/unit-name.h"
+#include "systemd-basic/util.h"
+
+static char *arg_default_unit = NULL;
+static const char *arg_dest = "/tmp";
+static char **arg_mask = NULL;
+static char **arg_wants = NULL;
+static bool arg_debug_shell = false;
+
+static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
+ int r;
+
+ assert(key);
+
+ if (streq(key, "systemd.mask")) {
+
+ if (!value)
+ log_error("Missing argument for systemd.mask= kernel command line parameter.");
+ else {
+ char *n;
+
+ r = unit_name_mangle(value, UNIT_NAME_NOGLOB, &n);
+ if (r < 0)
+ return log_error_errno(r, "Failed to glob unit name: %m");
+
+ r = strv_consume(&arg_mask, n);
+ if (r < 0)
+ 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;
+
+ r = unit_name_mangle(value, UNIT_NAME_NOGLOB, &n);
+ if (r < 0)
+ return log_error_errno(r, "Failed to glob unit name: %m");
+
+ r = strv_consume(&arg_wants, n);
+ if (r < 0)
+ return log_oom();
+ }
+
+ } else if (streq(key, "systemd.debug-shell")) {
+
+ if (value) {
+ r = parse_boolean(value);
+ if (r < 0)
+ log_error("Failed to parse systemd.debug-shell= argument '%s', ignoring.", value);
+ else
+ arg_debug_shell = r;
+ } else
+ arg_debug_shell = true;
+ } else if (streq(key, "systemd.unit")) {
+
+ if (!value)
+ log_error("Missing argument for systemd.unit= kernel command line parameter.");
+ else {
+ r = free_and_strdup(&arg_default_unit, value);
+ if (r < 0)
+ return log_error_errno(r, "Failed to set default unit %s: %m", value);
+ }
+ } else if (!value) {
+ const char *target;
+
+ target = runlevel_to_target(key);
+ if (target) {
+ r = free_and_strdup(&arg_default_unit, target);
+ if (r < 0)
+ return log_error_errno(r, "Failed to set default unit %s: %m", target);
+ }
+ }
+
+ return 0;
+}
+
+static int generate_mask_symlinks(void) {
+ char **u;
+ int r = 0;
+
+ if (strv_isempty(arg_mask))
+ return 0;
+
+ STRV_FOREACH(u, arg_mask) {
+ _cleanup_free_ char *p = NULL;
+
+ p = strjoin(arg_dest, "/", *u, NULL);
+ if (!p)
+ return log_oom();
+
+ if (symlink("/dev/null", p) < 0)
+ r = log_error_errno(errno,
+ "Failed to create mask symlink %s: %m",
+ p);
+ }
+
+ return r;
+}
+
+static int generate_wants_symlinks(void) {
+ char **u;
+ int r = 0;
+
+ if (strv_isempty(arg_wants))
+ return 0;
+
+ STRV_FOREACH(u, arg_wants) {
+ _cleanup_free_ char *p = NULL, *f = NULL;
+
+ p = strjoin(arg_dest, "/", arg_default_unit, ".wants/", *u, NULL);
+ if (!p)
+ return log_oom();
+
+ f = strappend(SYSTEM_DATA_UNIT_PATH "/", *u);
+ if (!f)
+ return log_oom();
+
+ mkdir_parents_label(p, 0755);
+
+ if (symlink(f, p) < 0)
+ r = log_error_errno(errno,
+ "Failed to create wants symlink %s: %m",
+ p);
+ }
+
+ return r;
+}
+
+int main(int argc, char *argv[]) {
+ int r, q;
+
+ if (argc > 1 && argc != 4) {
+ log_error("This program takes three or no arguments.");
+ return EXIT_FAILURE;
+ }
+
+ if (argc > 1)
+ arg_dest = argv[2];
+
+ log_set_target(LOG_TARGET_SAFE);
+ log_parse_environment();
+ log_open();
+
+ umask(0022);
+
+ r = free_and_strdup(&arg_default_unit, SPECIAL_DEFAULT_TARGET);
+ if (r < 0) {
+ log_error_errno(r, "Failed to set default unit %s: %m", SPECIAL_DEFAULT_TARGET);
+ goto finish;
+ }
+
+ r = parse_proc_cmdline(parse_proc_cmdline_item, NULL, false);
+ if (r < 0)
+ log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
+
+ if (arg_debug_shell) {
+ r = strv_extend(&arg_wants, "debug-shell.service");
+ if (r < 0) {
+ r = log_oom();
+ goto finish;
+ }
+ }
+
+ r = generate_mask_symlinks();
+
+ q = generate_wants_symlinks();
+ if (q < 0)
+ r = q;
+
+finish:
+ return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+
+}
diff --git a/src/systemd-debug-generator/systemd-debug-generator.xml b/src/systemd-debug-generator/systemd-debug-generator.xml
new file mode 100644
index 0000000000..5c5e9fc4a1
--- /dev/null
+++ b/src/systemd-debug-generator/systemd-debug-generator.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0"?>
+<!--*-nxml-*-->
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+<!--
+ This file is part of systemd.
+
+ Copyright 2014 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+-->
+<refentry id="systemd-debug-generator">
+
+ <refentryinfo>
+ <title>systemd-debug-generator</title>
+ <productname>systemd</productname>
+
+ <authorgroup>
+ <author>
+ <contrib>Developer</contrib>
+ <firstname>Lennart</firstname>
+ <surname>Poettering</surname>
+ <email>lennart@poettering.net</email>
+ </author>
+ </authorgroup>
+ </refentryinfo>
+
+ <refmeta>
+ <refentrytitle>systemd-debug-generator</refentrytitle>
+ <manvolnum>8</manvolnum>
+ </refmeta>
+
+ <refnamediv>
+ <refname>systemd-debug-generator</refname>
+ <refpurpose>Generator for enabling a runtime debug shell and
+ masking specific units at boot</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <para><filename>/usr/lib/systemd/system-generators/systemd-debug-generator</filename></para>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+
+ <para><filename>systemd-debug-generator</filename> is a generator
+ that reads the kernel command line and understands three
+ options:</para>
+
+ <para>If the <option>systemd.mask=</option> option is specified
+ and followed by a unit name, this unit is masked for the runtime,
+ similar to the effect of
+ <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
+ <command>mask</command> command. This is useful to boot with
+ certain units removed from the initial boot 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 or more
+ additional units at boot. May be specified more than once.</para>
+
+ <para>If the <option>systemd.debug-shell</option> option is
+ specified, the debug shell service
+ <literal>debug-shell.service</literal> is pulled into the boot
+ transaction. It will spawn a debug shell on tty9 during early
+ system startup. 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.</para>
+
+ <para><filename>systemd-debug-generator</filename> implements
+ <citerefentry><refentrytitle>systemd.generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
+ </refsect1>
+
+ <refsect1>
+ <title>See Also</title>
+ <para>
+ <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>
+ </para>
+ </refsect1>
+
+</refentry>