summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.c47
1 files changed, 41 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 36dea9b3c6..cddfc88454 100644
--- a/src/main.c
+++ b/src/main.c
@@ -55,6 +55,7 @@ static enum {
} arg_action = ACTION_RUN;
static char *arg_default_unit = NULL;
+static char *arg_console = NULL;
static ManagerRunningAs arg_running_as = _MANAGER_RUNNING_AS_INVALID;
static bool arg_dump_core = true;
@@ -326,7 +327,26 @@ static int parse_proc_cmdline_word(const char *word) {
} else if (streq(word, "nomodules"))
arg_nomodules = true;
- else if (streq(word, "quiet")) {
+ else if (startswith(word, "console=")) {
+ const char *k;
+ size_t l;
+ char *w = NULL;
+
+ k = word + 8;
+ l = strcspn(k, ",");
+
+ if (l < 4 ||
+ !startswith(k, "tty") ||
+ k[3+strspn(k+3, "0123456789")] != 0) {
+
+ if (!(w = strndup(k, l)))
+ return -ENOMEM;
+ }
+
+ free(arg_console);
+ arg_console = w;
+
+ } else if (streq(word, "quiet")) {
if (!ignore_quiet)
arg_show_status = false;
} else {
@@ -821,7 +841,6 @@ fail:
int main(int argc, char *argv[]) {
Manager *m = NULL;
Unit *target = NULL;
- Job *job = NULL;
int r, retval = 1;
FDSet *fds = NULL;
bool reexecute = false;
@@ -836,9 +855,6 @@ int main(int argc, char *argv[]) {
return 1;
}
- if (label_init() < 0)
- goto finish;
-
log_show_color(isatty(STDERR_FILENO) > 0);
log_show_location(false);
log_set_max_level(LOG_INFO);
@@ -846,6 +862,9 @@ int main(int argc, char *argv[]) {
if (getpid() == 1) {
arg_running_as = MANAGER_SYSTEM;
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
+
+ if (label_init() < 0)
+ goto finish;
} else {
arg_running_as = MANAGER_SESSION;
log_set_target(LOG_TARGET_CONSOLE);
@@ -1005,12 +1024,27 @@ int main(int argc, char *argv[]) {
manager_dump_units(m, stdout, "\t");
}
- if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &error, &job)) < 0) {
+ if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &error, NULL)) < 0) {
log_error("Failed to start default target: %s", bus_error(&error, r));
dbus_error_free(&error);
goto finish;
}
+ if (arg_console && arg_running_as == MANAGER_SYSTEM) {
+ char *name;
+
+ if (asprintf(&name, "getty@%s.service", arg_console) < 0)
+ log_error("Out of memory while generating console getty service name.");
+ else {
+ if ((r = manager_add_job_by_name(m, JOB_START, name, JOB_FAIL, false, &error, NULL)) < 0) {
+ log_error("Failed to start console getty target: %s", bus_error(&error, r));
+ dbus_error_free(&error);
+ }
+
+ free(name);
+ }
+ }
+
if (arg_action == ACTION_TEST) {
printf("-> By jobs:\n");
manager_dump_jobs(m, stdout, "\t");
@@ -1056,6 +1090,7 @@ finish:
manager_free(m);
free(arg_default_unit);
+ free(arg_console);
dbus_shutdown();