|
|
99043cc |
From 33d882e04c830b8ca7854f2d00e00f8e6ac66e2f Mon Sep 17 00:00:00 2001
|
|
|
99043cc |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
99043cc |
Date: Tue, 22 May 2012 02:35:22 +0200
|
|
|
99043cc |
Subject: [PATCH] main: properly queue default.target after switched root
|
|
|
99043cc |
|
|
|
99043cc |
This also introduces rd.systemd.unit= to specify the unit to boot into
|
|
|
99043cc |
in the initrd.
|
|
|
99043cc |
(cherry picked from commit bf4df7c3b6cb24918d94835cafd9dd60881c8981)
|
|
|
99043cc |
---
|
|
|
99043cc |
src/core/main.c | 34 +++++++++++++++++++++++++---------
|
|
|
99043cc |
1 file changed, 25 insertions(+), 9 deletions(-)
|
|
|
99043cc |
|
|
|
99043cc |
diff --git a/src/core/main.c b/src/core/main.c
|
|
|
99043cc |
index 12679cb..6931627 100644
|
|
|
99043cc |
--- a/src/core/main.c
|
|
|
99043cc |
+++ b/src/core/main.c
|
|
|
99043cc |
@@ -77,6 +77,7 @@ static bool arg_crash_shell = false;
|
|
|
99043cc |
static int arg_crash_chvt = -1;
|
|
|
99043cc |
static bool arg_confirm_spawn = false;
|
|
|
99043cc |
static bool arg_show_status = true;
|
|
|
99043cc |
+static bool arg_switched_root = false;
|
|
|
99043cc |
#ifdef HAVE_SYSV_COMPAT
|
|
|
99043cc |
static bool arg_sysv_console = true;
|
|
|
99043cc |
#endif
|
|
|
99043cc |
@@ -231,11 +232,13 @@ static int set_default_unit(const char *u) {
|
|
|
99043cc |
|
|
|
99043cc |
assert(u);
|
|
|
99043cc |
|
|
|
99043cc |
- if (!(c = strdup(u)))
|
|
|
99043cc |
+ c = strdup(u);
|
|
|
99043cc |
+ if (!c)
|
|
|
99043cc |
return -ENOMEM;
|
|
|
99043cc |
|
|
|
99043cc |
free(arg_default_unit);
|
|
|
99043cc |
arg_default_unit = c;
|
|
|
99043cc |
+
|
|
|
99043cc |
return 0;
|
|
|
99043cc |
}
|
|
|
99043cc |
|
|
|
99043cc |
@@ -257,10 +260,17 @@ static int parse_proc_cmdline_word(const char *word) {
|
|
|
99043cc |
|
|
|
99043cc |
assert(word);
|
|
|
99043cc |
|
|
|
99043cc |
- if (startswith(word, "systemd.unit="))
|
|
|
99043cc |
- return set_default_unit(word + 13);
|
|
|
99043cc |
+ if (startswith(word, "systemd.unit=")) {
|
|
|
99043cc |
+
|
|
|
99043cc |
+ if (!in_initrd())
|
|
|
99043cc |
+ return set_default_unit(word + 13);
|
|
|
99043cc |
+
|
|
|
99043cc |
+ } else if (startswith(word, "rd.systemd.unit=")) {
|
|
|
99043cc |
+
|
|
|
99043cc |
+ if (in_initrd())
|
|
|
99043cc |
+ return set_default_unit(word + 16);
|
|
|
99043cc |
|
|
|
99043cc |
- else if (startswith(word, "systemd.log_target=")) {
|
|
|
99043cc |
+ } else if (startswith(word, "systemd.log_target=")) {
|
|
|
99043cc |
|
|
|
99043cc |
if (log_set_target_from_string(word + 19) < 0)
|
|
|
99043cc |
log_warning("Failed to parse log target %s. Ignoring.", word + 19);
|
|
|
99043cc |
@@ -369,6 +379,7 @@ static int parse_proc_cmdline_word(const char *word) {
|
|
|
99043cc |
|
|
|
99043cc |
log_info("Supported kernel switches:\n"
|
|
|
99043cc |
"systemd.unit=UNIT Default unit to start\n"
|
|
|
99043cc |
+ "rd.systemd.unit=UNIT Default unit to start when run in initrd\n"
|
|
|
99043cc |
"systemd.dump_core=0|1 Dump core on crash\n"
|
|
|
99043cc |
"systemd.crash_shell=0|1 Run shell on crash\n"
|
|
|
99043cc |
"systemd.crash_chvt=N Change to VT #N on crash\n"
|
|
|
99043cc |
@@ -966,7 +977,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|
|
99043cc |
}
|
|
|
99043cc |
|
|
|
99043cc |
case ARG_SWITCHED_ROOT:
|
|
|
99043cc |
- /* Nothing special yet */
|
|
|
99043cc |
+ arg_switched_root = true;
|
|
|
99043cc |
break;
|
|
|
99043cc |
|
|
|
99043cc |
case ARG_INTROSPECT: {
|
|
|
99043cc |
@@ -1209,6 +1220,7 @@ int main(int argc, char *argv[]) {
|
|
|
99043cc |
int j;
|
|
|
99043cc |
bool loaded_policy = false;
|
|
|
99043cc |
bool arm_reboot_watchdog = false;
|
|
|
99043cc |
+ bool queue_default_job = false;
|
|
|
99043cc |
char *switch_root_dir = NULL, *switch_root_init = NULL;
|
|
|
99043cc |
|
|
|
99043cc |
#ifdef HAVE_SYSV_COMPAT
|
|
|
99043cc |
@@ -1503,16 +1515,18 @@ int main(int argc, char *argv[]) {
|
|
|
99043cc |
|
|
|
99043cc |
manager_set_show_status(m, arg_show_status);
|
|
|
99043cc |
|
|
|
99043cc |
+ /* Remember whether we should queue the default job */
|
|
|
99043cc |
+ queue_default_job = !serialization || arg_switched_root;
|
|
|
99043cc |
+
|
|
|
99043cc |
before_startup = now(CLOCK_MONOTONIC);
|
|
|
99043cc |
|
|
|
99043cc |
r = manager_startup(m, serialization, fds);
|
|
|
99043cc |
if (r < 0)
|
|
|
99043cc |
log_error("Failed to fully start up daemon: %s", strerror(-r));
|
|
|
99043cc |
|
|
|
99043cc |
+ /* This will close all file descriptors that were opened, but
|
|
|
99043cc |
+ * not claimed by any unit. */
|
|
|
99043cc |
if (fds) {
|
|
|
99043cc |
- /* This will close all file descriptors that were opened, but
|
|
|
99043cc |
- * not claimed by any unit. */
|
|
|
99043cc |
-
|
|
|
99043cc |
fdset_free(fds);
|
|
|
99043cc |
fds = NULL;
|
|
|
99043cc |
}
|
|
|
99043cc |
@@ -1520,7 +1534,9 @@ int main(int argc, char *argv[]) {
|
|
|
99043cc |
if (serialization) {
|
|
|
99043cc |
fclose(serialization);
|
|
|
99043cc |
serialization = NULL;
|
|
|
99043cc |
- } else {
|
|
|
99043cc |
+ }
|
|
|
99043cc |
+
|
|
|
99043cc |
+ if (queue_default_job) {
|
|
|
99043cc |
DBusError error;
|
|
|
99043cc |
Unit *target = NULL;
|
|
|
99043cc |
Job *default_unit_job;
|