summaryrefslogtreecommitdiff
path: root/src/debug-generator
diff options
context:
space:
mode:
authorJan Synacek <jsynacek@redhat.com>2019-04-25 12:19:16 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-02 09:51:27 +0200
commit93912e872fb14e9c372e090409e429084a6450f5 (patch)
tree4b8eedffbb710921ecc78e3e10cd45df98097b65 /src/debug-generator
parent8fabb625ac505d3a5af4d465822d07cc67ad5e56 (diff)
downloadsystemd-93912e872fb14e9c372e090409e429084a6450f5.tar.gz
debug-generator: enable custom systemd.debug_shell tty
Diffstat (limited to 'src/debug-generator')
-rw-r--r--src/debug-generator/debug-generator.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c
index 5faf8d7ddf..09220dc98c 100644
--- a/src/debug-generator/debug-generator.c
+++ b/src/debug-generator/debug-generator.c
@@ -3,6 +3,7 @@
#include <unistd.h>
#include "alloc-util.h"
+#include "dropin.h"
#include "generator.h"
#include "mkdir.h"
#include "parse-util.h"
@@ -17,11 +18,12 @@ static const char *arg_dest = NULL;
static char *arg_default_unit = NULL;
static char **arg_mask = NULL;
static char **arg_wants = NULL;
-static bool arg_debug_shell = false;
+static char *arg_debug_shell = 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 int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
int r;
@@ -57,15 +59,16 @@ 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;
- 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;
+ r = value ? parse_boolean(value) : 1;
+ if (r < 0)
+ t = skip_dev_prefix(value);
+ else if (r > 0)
+ t = skip_dev_prefix(DEBUGTTY);
+
+ if (free_and_strdup(&arg_debug_shell, t) < 0)
+ return log_oom();
} else if (streq(key, "systemd.unit")) {
@@ -143,6 +146,23 @@ static int generate_wants_symlinks(void) {
return r;
}
+static void install_debug_shell_dropin(const char *dir) {
+ int r;
+
+ if (streq(arg_debug_shell, skip_dev_prefix(DEBUGTTY)))
+ return;
+
+ r = write_drop_in_format(dir, "debug-shell.service", 50, "tty",
+ "[Unit]\n"
+ "Description=Early root shell on /dev/%s FOR DEBUGGING ONLY\n"
+ "ConditionPathExists=\n"
+ "[Service]\n"
+ "TTYPath=/dev/%s",
+ arg_debug_shell, arg_debug_shell);
+ if (r < 0)
+ log_warning_errno(r, "Failed to write drop-in for debug-shell.service, ignoring: %m");
+}
+
static int run(const char *dest, const char *dest_early, const char *dest_late) {
int r, q;
@@ -156,6 +176,8 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
r = strv_extend(&arg_wants, "debug-shell.service");
if (r < 0)
return log_oom();
+
+ install_debug_shell_dropin(arg_dest);
}
r = generate_mask_symlinks();