[systemd-commits] 2 commits - fixme Makefile.am man/systemctl.xml man/systemd.unit.xml src/auto-serial-getty.c src/bus-errors.h src/dbus-unit.c src/dbus-unit.h src/load-fragment.c src/main.c src/manager.c src/manager.h src/special.h src/target.c src/unit.c src/unit.h units/emergency.target units/graphical.target.m4 units/halt.target units/multi-user.target.m4 units/poweroff.target units/reboot.target units/rescue.target units/systemd-auto-serial-getty.service.in

Lennart Poettering lennart at kemper.freedesktop.org
Mon Aug 30 14:05:03 PDT 2010


 Makefile.am                                |   20 ---
 fixme                                      |    8 -
 man/systemctl.xml                          |    8 -
 man/systemd.unit.xml                       |   17 ++
 src/auto-serial-getty.c                    |  189 -----------------------------
 src/bus-errors.h                           |    1 
 src/dbus-unit.c                            |   18 ++
 src/dbus-unit.h                            |    4 
 src/load-fragment.c                        |    1 
 src/main.c                                 |   29 ++++
 src/manager.c                              |   24 +++
 src/manager.h                              |    4 
 src/special.h                              |    2 
 src/target.c                               |   45 ++++++
 src/unit.c                                 |    7 +
 src/unit.h                                 |    6 
 units/emergency.target                     |    1 
 units/graphical.target.m4                  |    1 
 units/halt.target                          |    1 
 units/multi-user.target.m4                 |    1 
 units/poweroff.target                      |    1 
 units/reboot.target                        |    1 
 units/rescue.target                        |    1 
 units/systemd-auto-serial-getty.service.in |   16 --
 24 files changed, 172 insertions(+), 234 deletions(-)

New commits:
commit 2528a7a62c4ad9b2f4773b608d208239299da50c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Aug 30 22:45:46 2010 +0200

    unit: introduce AllowIsolate= switch

diff --git a/fixme b/fixme
index d5bca0c..e5d17a0 100644
--- a/fixme
+++ b/fixme
@@ -72,10 +72,6 @@
 
 * auditd service files
 
-* auto-serial-getty vs. isolate
-
-* add RefuseManualIsolate= (default on?)
-
 * add systemctl switch to dump transaction without executing it
 
 * shell wenn fsck im arsch is
@@ -90,9 +86,9 @@
 
 * o_ndelay ausschalten für stdin/stderr/stdout auf socket
 
-External:
+* kexec, suspend, resume
 
-* make sure MountOnPlug und MountAuto und SwapOnPlug is off in Fedora
+External:
 
 * place /etc/inittab with explaining blurb.
 
diff --git a/man/systemctl.xml b/man/systemctl.xml
index 1c5c884..6af8e61 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -341,8 +341,12 @@
 
                                 <listitem><para>Start the unit
                                 specified on the command line and its
-                                dependencies and stop all
-                                others.</para></listitem>
+                                dependencies and stop all others. Note
+                                that this works only on units where
+                                <option>AllowIsolate=</option> is
+                                enabled. See
+                                <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+                                for details.</para></listitem>
                         </varlistentry>
                         <varlistentry>
                                 <term><command>is-active [NAME...]</command></term>
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
index bb11682..250989f 100644
--- a/man/systemd.unit.xml
+++ b/man/systemd.unit.xml
@@ -485,6 +485,23 @@
                         </varlistentry>
 
                         <varlistentry>
+                                <term><varname>AllowIsolate=</varname></term>
+
+                                <listitem><para>Takes a boolean
+                                argument. If <option>true</option>
+                                this unit may be used with the
+                                <command>systemctl isolate</command>
+                                command. Otherwise this will be
+                                refused. It probably is a good idea to
+                                leave this disabled except for target
+                                units that shall be used similar to
+                                runlevels in SysV init systems, just
+                                as a precaution to avoid unusable
+                                system states. This option defaults to
+                                <option>false</option>.</para></listitem>
+                        </varlistentry>
+
+                        <varlistentry>
                                 <term><varname>DefaultDependencies=</varname></term>
 
                                 <listitem><para>Takes a boolean
diff --git a/src/bus-errors.h b/src/bus-errors.h
index 7bff750..a63350c 100644
--- a/src/bus-errors.h
+++ b/src/bus-errors.h
@@ -35,6 +35,7 @@
 #define BUS_ERROR_NOT_SUPPORTED "org.freedesktop.systemd1.NotSupported"
 #define BUS_ERROR_INVALID_JOB_MODE "org.freedesktop.systemd1.InvalidJobMode"
 #define BUS_ERROR_ONLY_BY_DEPENDENCY "org.freedesktop.systemd1.OnlyByDependency"
+#define BUS_ERROR_NO_ISOLATION "org.freedesktop.systemd1.NoIsolation"
 #define BUS_ERROR_LOAD_FAILED "org.freedesktop.systemd1.LoadFailed"
 #define BUS_ERROR_JOB_TYPE_NOT_APPLICABLE "org.freedesktop.systemd1.JobTypeNotApplicable"
 #define BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE "org.freedesktop.systemd1.TransactionIsDestructive"
diff --git a/src/dbus-unit.c b/src/dbus-unit.c
index 519aa5c..eab816a 100644
--- a/src/dbus-unit.c
+++ b/src/dbus-unit.c
@@ -205,6 +205,24 @@ int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char *prope
         return 0;
 }
 
+int bus_unit_append_can_isolate(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+        Unit *u = data;
+        dbus_bool_t b;
+
+        assert(m);
+        assert(i);
+        assert(property);
+        assert(u);
+
+        b = unit_can_isolate(u) &&
+                !u->meta.refuse_manual_start;
+
+        if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
+                return -ENOMEM;
+
+        return 0;
+}
+
 int bus_unit_append_job(Manager *m, DBusMessageIter *i, const char *property, void *data) {
         Unit *u = data;
         DBusMessageIter sub;
diff --git a/src/dbus-unit.h b/src/dbus-unit.h
index cc55ad7..6e3726d 100644
--- a/src/dbus-unit.h
+++ b/src/dbus-unit.h
@@ -85,6 +85,7 @@
         "  <property name=\"CanReload\" type=\"b\" access=\"read\"/>\n" \
         "  <property name=\"CanStart\" type=\"b\" access=\"read\"/>\n"  \
         "  <property name=\"CanStop\" type=\"b\" access=\"read\"/>\n"   \
+        "  <property name=\"CanIsolate\" type=\"b\" access=\"read\"/>\n" \
         "  <property name=\"Job\" type=\"(uo)\" access=\"read\"/>\n"    \
         "  <property name=\"RecursiveStop\" type=\"b\" access=\"read\"/>\n" \
         "  <property name=\"StopWhenUneeded\" type=\"b\" access=\"read\"/>\n" \
@@ -126,11 +127,13 @@
         { "org.freedesktop.systemd1.Unit", "CanStart",             bus_unit_append_can_start,      "b",    u                                 }, \
         { "org.freedesktop.systemd1.Unit", "CanStop",              bus_unit_append_can_stop,       "b",    u                                 }, \
         { "org.freedesktop.systemd1.Unit", "CanReload",            bus_unit_append_can_reload,     "b",    u                                 }, \
+        { "org.freedesktop.systemd1.Unit", "CanIsolate",           bus_unit_append_can_isolate,    "b",    u                                 }, \
         { "org.freedesktop.systemd1.Unit", "Job",                  bus_unit_append_job,            "(uo)", u                                 }, \
         { "org.freedesktop.systemd1.Unit", "RecursiveStop",        bus_property_append_bool,       "b",    &u->meta.recursive_stop           }, \
         { "org.freedesktop.systemd1.Unit", "StopWhenUneeded",      bus_property_append_bool,       "b",    &u->meta.stop_when_unneeded       }, \
         { "org.freedesktop.systemd1.Unit", "RefuseManualStart",    bus_property_append_bool,       "b",    &u->meta.refuse_manual_start      }, \
         { "org.freedesktop.systemd1.Unit", "RefuseManualStop",     bus_property_append_bool,       "b",    &u->meta.refuse_manual_stop       }, \
+        { "org.freedesktop.systemd1.Unit", "AllowIsolate",         bus_property_append_bool,       "b",    &u->meta.allow_isolate            }, \
         { "org.freedesktop.systemd1.Unit", "DefaultDependencies",  bus_property_append_bool,       "b",    &u->meta.default_dependencies     }, \
         { "org.freedesktop.systemd1.Unit", "DefaultControlGroup",  bus_unit_append_default_cgroup, "s",    u                                 }, \
         { "org.freedesktop.systemd1.Unit", "ControlGroups",        bus_unit_append_cgroups,        "as",   u                                 }, \
@@ -147,6 +150,7 @@ int bus_unit_append_sub_state(Manager *m, DBusMessageIter *i, const char *proper
 int bus_unit_append_can_start(Manager *m, DBusMessageIter *i, const char *property, void *data);
 int bus_unit_append_can_stop(Manager *m, DBusMessageIter *i, const char *property, void *data);
 int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_can_isolate(Manager *m, DBusMessageIter *i, const char *property, void *data);
 int bus_unit_append_job(Manager *m, DBusMessageIter *i, const char *property, void *data);
 int bus_unit_append_default_cgroup(Manager *m, DBusMessageIter *i, const char *property, void *data);
 int bus_unit_append_cgroups(Manager *m, DBusMessageIter *i, const char *property, void *data);
diff --git a/src/load-fragment.c b/src/load-fragment.c
index 103e056..c9ed679 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -1580,6 +1580,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "StopWhenUnneeded",       config_parse_bool,            &u->meta.stop_when_unneeded,                     "Unit"    },
                 { "RefuseManualStart",      config_parse_bool,            &u->meta.refuse_manual_start,                    "Unit"    },
                 { "RefuseManualStop",       config_parse_bool,            &u->meta.refuse_manual_stop,                     "Unit"    },
+                { "AllowIsolate",           config_parse_bool,            &u->meta.allow_isolate,                          "Unit"    },
                 { "DefaultDependencies",    config_parse_bool,            &u->meta.default_dependencies,                   "Unit"    },
                 { "IgnoreDependencyFailure",config_parse_bool,            &u->meta.ignore_dependency_failure,              "Unit"    },
                 { "JobTimeoutSec",          config_parse_usec,            &u->meta.job_timeout,                            "Unit"    },
diff --git a/src/manager.c b/src/manager.c
index 0afc992..f542883 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -1523,6 +1523,11 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
                 return -EINVAL;
         }
 
+        if (mode == JOB_ISOLATE && !unit->meta.allow_isolate) {
+                dbus_set_error(e, BUS_ERROR_NO_ISOLATION, "Operation refused, unit may not be isolated.");
+                return -EPERM;
+        }
+
         log_debug("Trying to enqueue job %s/%s", unit->meta.id, job_type_to_string(type));
 
         if ((r = transaction_add_job_and_dependencies(m, type, unit, NULL, true, override, false, e, &ret)) < 0) {
diff --git a/src/unit.c b/src/unit.c
index 34bfd3f..3369647 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -812,6 +812,13 @@ bool unit_can_start(Unit *u) {
         return !!UNIT_VTABLE(u)->start;
 }
 
+bool unit_can_isolate(Unit *u) {
+        assert(u);
+
+        return unit_can_start(u) &&
+                u->meta.allow_isolate;
+}
+
 /* Errors:
  *         -EBADR:    This unit type does not support stopping.
  *         -EALREADY: Unit is already stopped.
diff --git a/src/unit.h b/src/unit.h
index 0362602..e3c0c0f 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -205,6 +205,9 @@ struct Meta {
         /* Don't allow the user to stop this unit manually, allow stopping only indirectly via dependency. */
         bool refuse_manual_stop;
 
+        /* Allow isolation requests */
+        bool allow_isolate;
+
         bool in_load_queue:1;
         bool in_dbus_queue:1;
         bool in_cleanup_queue:1;
@@ -359,7 +362,7 @@ struct UnitVTable {
         /* Exclude from automatic gc */
         bool no_gc:1;
 
-        /* Exclude from isolation requests */
+        /* Exclude from stopping on isolation requests */
         bool no_isolate:1;
 
         /* Show status updates on the console */
@@ -445,6 +448,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix);
 
 bool unit_can_reload(Unit *u);
 bool unit_can_start(Unit *u);
+bool unit_can_isolate(Unit *u);
 
 int unit_start(Unit *u);
 int unit_stop(Unit *u);
diff --git a/units/emergency.target b/units/emergency.target
index 5bf2ae2..6a99e05 100644
--- a/units/emergency.target
+++ b/units/emergency.target
@@ -11,3 +11,4 @@
 Description=Emergency Mode
 Requires=emergency.service
 After=emergency.service
+AllowIsolate=yes
diff --git a/units/graphical.target.m4 b/units/graphical.target.m4
index a80fecf..97c01ce 100644
--- a/units/graphical.target.m4
+++ b/units/graphical.target.m4
@@ -20,6 +20,7 @@ Names=runlevel5.target
 m4_ifdef(`TARGET_SUSE',
 Names=runlevel5.target
 )m4_dnl
+AllowIsolate=yes
 
 [Install]
 Alias=default.target
diff --git a/units/halt.target b/units/halt.target
index 77b4044..70e90fe 100644
--- a/units/halt.target
+++ b/units/halt.target
@@ -11,6 +11,7 @@
 Description=Halt
 Requires=halt.service
 After=halt.service
+AllowIsolate=yes
 
 [Install]
 Alias=ctrl-alt-del.target
diff --git a/units/multi-user.target.m4 b/units/multi-user.target.m4
index 6f384fe..48c21d2 100644
--- a/units/multi-user.target.m4
+++ b/units/multi-user.target.m4
@@ -20,6 +20,7 @@ Names=runlevel3.target
 m4_ifdef(`TARGET_SUSE',
 Names=runlevel3.target
 )m4_dnl
+AllowIsolate=yes
 
 [Install]
 Alias=default.target
diff --git a/units/poweroff.target b/units/poweroff.target
index b2b56b2..cb94606 100644
--- a/units/poweroff.target
+++ b/units/poweroff.target
@@ -12,6 +12,7 @@ Description=Power-Off
 Names=runlevel0.target
 Requires=poweroff.service
 After=poweroff.service
+AllowIsolate=yes
 
 [Install]
 Alias=ctrl-alt-del.target
diff --git a/units/reboot.target b/units/reboot.target
index b3be52f..8557513 100644
--- a/units/reboot.target
+++ b/units/reboot.target
@@ -12,6 +12,7 @@ Description=Reboot
 Names=runlevel6.target
 Requires=reboot.service
 After=reboot.service
+AllowIsolate=yes
 
 [Install]
 Alias=ctrl-alt-del.target
diff --git a/units/rescue.target b/units/rescue.target
index 2694856..810fa14 100644
--- a/units/rescue.target
+++ b/units/rescue.target
@@ -12,6 +12,7 @@ Description=Rescue Mode
 Requires=sysinit.target local-fs.target swap.target
 After=sysinit.target local-fs.target swap.target
 Names=runlevel1.target
+AllowIsolate=yes
 
 [Install]
 Alias=kbrequest.target
commit b2bb3dbed9607c440b1a9ccacc515e28136d39ae
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Aug 30 21:31:40 2010 +0200

    console: rework automatic getty on kernel console logic again
    
    It is essential that the gettys are proper dependencies from
    getty.target so that they aren't killed and immediately restarted on
    runlevel changes. Hence rework the logic to implicitly add console
    gettys to getty.target as dependencies.
    
    This also adds an automatic hvc console for virtualizers.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=501720

diff --git a/Makefile.am b/Makefile.am
index 725685d..ed37278 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -73,7 +73,6 @@ rootlibexec_PROGRAMS = \
 	systemd-update-utmp \
 	systemd-random-seed \
 	systemd-shutdownd \
-	systemd-auto-serial-getty \
 	systemd-modules-load \
 	systemd-remount-api-vfs \
 	systemd-kmsg-syslogd
@@ -179,7 +178,6 @@ nodist_systemunit_DATA = \
 	units/systemd-logger.service \
 	units/systemd-shutdownd.service \
 	units/systemd-kmsg-syslogd.service \
-	units/systemd-auto-serial-getty.service \
 	units/systemd-modules-load.service \
 	units/systemd-remount-api-vfs.service \
 	units/systemd-update-utmp-runlevel.service \
@@ -206,7 +204,6 @@ EXTRA_DIST = \
 	units/systemd-logger.service.in \
 	units/systemd-shutdownd.service.in \
 	units/systemd-kmsg-syslogd.service.in \
-	units/systemd-auto-serial-getty.service.in \
 	units/systemd-modules-load.service.in \
 	units/systemd-remount-api-vfs.service.in \
 	units/systemd-update-utmp-runlevel.service.in \
@@ -575,18 +572,6 @@ systemd_shutdownd_CFLAGS = \
 systemd_shutdownd_LDADD = \
 	libsystemd-basic.la
 
-systemd_auto_serial_getty_SOURCES = \
-	src/auto-serial-getty.c \
-	src/dbus-common.c
-
-systemd_auto_serial_getty_CFLAGS = \
-	$(AM_CFLAGS) \
-	$(DBUS_CFLAGS)
-
-systemd_auto_serial_getty_LDADD = \
-	libsystemd-basic.la \
-	$(DBUS_LIBS)
-
 systemd_modules_load_SOURCES = \
 	src/modules-load.c
 
@@ -896,14 +881,13 @@ install-data-hook:
 		$(LN_S) $(systemunitdir)/reboot.target ctrl-alt-del.target && \
 		$(LN_S) $(systemunitdir)/rescue.target kbrequest.target )
 	( cd $(DESTDIR)$(pkgsysconfdir)/system/getty.target.wants && \
-		rm -f getty at tty1.service getty at tty2.service getty at tty3.service getty at tty4.service getty at tty5.service getty at tty6.service systemd-auto-serial-getty.service && \
+		rm -f getty at tty1.service getty at tty2.service getty at tty3.service getty at tty4.service getty at tty5.service getty at tty6.service && \
 		$(LN_S) $(systemunitdir)/getty at .service getty at tty1.service && \
 		$(LN_S) $(systemunitdir)/getty at .service getty at tty2.service && \
 		$(LN_S) $(systemunitdir)/getty at .service getty at tty3.service && \
 		$(LN_S) $(systemunitdir)/getty at .service getty at tty4.service && \
 		$(LN_S) $(systemunitdir)/getty at .service getty at tty5.service && \
-		$(LN_S) $(systemunitdir)/getty at .service getty at tty6.service && \
-		$(LN_S) $(systemunitdir)/systemd-auto-serial-getty.service systemd-auto-serial-getty.service )
+		$(LN_S) $(systemunitdir)/getty at .service getty at tty6.service )
 	( cd $(DESTDIR)$(pkgsysconfdir)/system/multi-user.target.wants && \
 		rm -f getty.target remote-fs.target && \
 		$(LN_S) $(systemunitdir)/getty.target getty.target && \
diff --git a/src/auto-serial-getty.c b/src/auto-serial-getty.c
deleted file mode 100644
index 355cdfd..0000000
--- a/src/auto-serial-getty.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
-  This file is part of systemd.
-
-  Copyright 2010 Lennart Poettering
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 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
-  General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <dbus/dbus.h>
-
-#include "util.h"
-#include "log.h"
-#include "dbus-common.h"
-
-static int spawn_getty(DBusConnection *bus, const char *console) {
-        DBusMessage *m = NULL, *reply = NULL;
-        DBusError error;
-        const char *fail = "fail";
-        char *name;
-        int r = -EIO;
-
-        dbus_error_init(&error);
-
-        assert(bus);
-        assert(console);
-
-        /* FIXME: we probably should escape the tty name properly here */
-        if (asprintf(&name, "serial-getty@%s.service", console) < 0)
-                return -ENOMEM;
-
-        if (!(m = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartUnit"))) {
-                log_error("Could not allocate message.");
-                goto finish;
-        }
-
-        if (!dbus_message_append_args(m,
-                                      DBUS_TYPE_STRING, &name,
-                                      DBUS_TYPE_STRING, &fail,
-                                      DBUS_TYPE_INVALID)) {
-                log_error("Could not attach target and flag information to message.");
-                goto finish;
-        }
-
-        if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) {
-                log_error("Failed to start unit: %s", bus_error_message(&error));
-                goto finish;
-        }
-
-        r = 0;
-
-finish:
-        if (m)
-                dbus_message_unref(m);
-
-        if (reply)
-                dbus_message_unref(reply);
-
-        dbus_error_free(&error);
-
-        free(name);
-
-        return r;
-}
-
-static int parse_proc_cmdline_word(const char *word, char **console) {
-        assert(word);
-
-        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(*console);
-                *console = w;
-        }
-
-        return 0;
-}
-
-static int parse_proc_cmdline(char **console) {
-        char *line;
-        int r;
-        char *w;
-        size_t l;
-        char *state;
-
-        assert(console);
-
-        if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) {
-                log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
-                return 0;
-        }
-
-        FOREACH_WORD_QUOTED(w, l, line, state) {
-                char *word;
-
-                if (!(word = strndup(w, l))) {
-                        r = -ENOMEM;
-                        goto finish;
-                }
-
-                r = parse_proc_cmdline_word(word, console);
-                free(word);
-
-                if (r < 0)
-                        goto finish;
-        }
-
-        r = 0;
-
-finish:
-        free(line);
-        return r;
-}
-
-int main(int argc, char *argv[]) {
-        DBusError error;
-        int r = 1;
-        char *console = NULL;
-        DBusConnection *bus = NULL;
-
-        dbus_error_init(&error);
-
-        if (argc > 1) {
-                log_error("This program does not take arguments.");
-                return 1;
-        }
-
-        log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
-        log_parse_environment();
-        log_open();
-
-        if (bus_connect(DBUS_BUS_SYSTEM, &bus, NULL, &error) < 0) {
-                log_error("Failed to get D-Bus connection: %s", bus_error_message(&error));
-                goto finish;
-        }
-
-        if (parse_proc_cmdline(&console) < 0)
-                goto finish;
-
-        if (console)
-                if (spawn_getty(bus, console) < 0)
-                        goto finish;
-
-        r = 0;
-
-finish:
-        free(console);
-
-        if (bus) {
-               dbus_connection_close(bus);
-               dbus_connection_unref(bus);
-        }
-
-        dbus_error_free(&error);
-
-        dbus_shutdown();
-
-        return r;
-}
diff --git a/src/main.c b/src/main.c
index f1fa569..53a455b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -66,6 +66,7 @@ static bool arg_show_status = true;
 static bool arg_sysv_console = true;
 static bool arg_mount_auto = true;
 static bool arg_swap_auto = true;
+static char *arg_console = NULL;
 
 static FILE* serialization = NULL;
 
@@ -335,6 +336,26 @@ static int parse_proc_cmdline_word(const char *word) {
                          "systemd.log_color=0|1                    Highlight important log messages\n"
                          "systemd.log_location=0|1                 Include code location in log messages\n");
 
+        } else if (startswith(word, "console=")) {
+                const char *k;
+                size_t l;
+                char *w = NULL;
+
+                k = word + 8;
+                l = strcspn(k, ",");
+
+                /* Ignore the console setting if set to a VT */
+                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")) {
                 arg_show_status = false;
                 arg_sysv_console = false;
@@ -993,6 +1014,9 @@ int main(int argc, char *argv[]) {
         m->mount_auto = arg_mount_auto;
         m->swap_auto = arg_swap_auto;
 
+        if (arg_console)
+                manager_set_console(m, arg_console);
+
         if ((r = manager_startup(m, serialization, fds)) < 0)
                 log_error("Failed to fully start up daemon: %s", strerror(-r));
 
@@ -1090,9 +1114,12 @@ finish:
                 manager_free(m);
 
         free(arg_default_unit);
+        free(arg_console);
 
         dbus_shutdown();
 
+        label_finish();
+
         if (reexecute) {
                 const char *args[15];
                 unsigned i = 0;
@@ -1157,7 +1184,5 @@ finish:
         if (getpid() == 1)
                 freeze();
 
-        label_finish();
-
         return retval;
 }
diff --git a/src/manager.c b/src/manager.c
index 09b2c78..0afc992 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -112,6 +112,8 @@ static int manager_setup_notify(Manager *m) {
         if (!(m->notify_socket = strdup(sa.un.sun_path+1)))
                 return -ENOMEM;
 
+        log_debug("Using notification socket %s", m->notify_socket);
+
         return 0;
 }
 
@@ -447,6 +449,7 @@ void manager_free(Manager *m) {
 #endif
 
         free(m->notify_socket);
+        free(m->console);
 
         lookup_paths_free(&m->lookup_paths);
         strv_free(m->environment);
@@ -2553,6 +2556,22 @@ void manager_reset_maintenance(Manager *m) {
                 unit_reset_maintenance(u);
 }
 
+int manager_set_console(Manager *m, const char *console) {
+        char *c;
+
+        assert(m);
+
+        if (!(c = strdup(console)))
+                return -ENOMEM;
+
+        free(m->console);
+        m->console = c;
+
+        log_debug("Using kernel console %s", c);
+
+        return 0;
+}
+
 static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = {
         [MANAGER_SYSTEM] = "system",
         [MANAGER_SESSION] = "session"
diff --git a/src/manager.h b/src/manager.h
index e3c6db2..6186cb2 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -140,6 +140,8 @@ struct Manager {
 
         dual_timestamp startup_timestamp;
 
+        char *console;
+
         /* Data specific to the device subsystem */
         struct udev* udev;
         struct udev_monitor* udev_monitor;
@@ -237,6 +239,8 @@ unsigned manager_dispatch_load_queue(Manager *m);
 unsigned manager_dispatch_run_queue(Manager *m);
 unsigned manager_dispatch_dbus_queue(Manager *m);
 
+int manager_set_console(Manager *m, const char *console);
+
 int manager_loop(Manager *m);
 
 void manager_dispatch_bus_name_owner_changed(Manager *m, const char *name, const char* old_owner, const char *new_owner);
diff --git a/src/special.h b/src/special.h
index 7bf2070..0cc5cc6 100644
--- a/src/special.h
+++ b/src/special.h
@@ -59,6 +59,8 @@
 #define SPECIAL_POWEROFF_TARGET "poweroff.target"
 #define SPECIAL_REBOOT_TARGET "reboot.target"
 #define SPECIAL_DBUS_SERVICE "dbus.service"
+#define SPECIAL_GETTY_TARGET "getty.target"
+#define SPECIAL_SERIAL_GETTY_SERVICE "serial-getty at .service"
 
 #ifndef SPECIAL_SYSLOG_SERVICE
 #define SPECIAL_SYSLOG_SERVICE "syslog.service"
diff --git a/src/target.c b/src/target.c
index c7285fa..c350d8f 100644
--- a/src/target.c
+++ b/src/target.c
@@ -21,6 +21,7 @@
 
 #include <errno.h>
 #include <signal.h>
+#include <unistd.h>
 
 #include "unit.h"
 #include "target.h"
@@ -28,6 +29,7 @@
 #include "log.h"
 #include "dbus-target.h"
 #include "special.h"
+#include "unit-name.h"
 
 static const UnitActiveState state_translation_table[_TARGET_STATE_MAX] = {
         [TARGET_DEAD] = UNIT_INACTIVE,
@@ -76,6 +78,46 @@ static int target_add_default_dependencies(Target *t) {
         return 0;
 }
 
+static int target_add_getty_dependencies(Target *t) {
+        char *n;
+        int r;
+
+        assert(t);
+
+        if (!unit_has_name(UNIT(t), SPECIAL_GETTY_TARGET))
+                return 0;
+
+        /* Automatically add in a serial getty on the kernel
+         * console */
+        if (t->meta.manager->console) {
+                log_debug("Automatically adding serial getty for %s", t->meta.manager->console);
+                if (!(n = unit_name_replace_instance(SPECIAL_SERIAL_GETTY_SERVICE, t->meta.manager->console)))
+                        return -ENOMEM;
+
+                r = unit_add_two_dependencies_by_name(UNIT(t), UNIT_AFTER, UNIT_WANTS, n, NULL, true);
+                free(n);
+
+                if (r < 0)
+                        return r;
+        }
+
+        /* Automatically add in a serial getty on the first
+         * virtualizer console */
+        if (access("/sys/class/tty/hvc0", F_OK) == 0) {
+                log_debug("Automatic adding serial getty for hvc0");
+                if (!(n = unit_name_replace_instance(SPECIAL_SERIAL_GETTY_SERVICE, "hvc0")))
+                        return -ENOMEM;
+
+                r = unit_add_two_dependencies_by_name(UNIT(t), UNIT_AFTER, UNIT_WANTS, n, NULL, true);
+                free(n);
+
+                if (r < 0)
+                        return r;
+        }
+
+        return 0;
+}
+
 static int target_load(Unit *u) {
         Target *t = TARGET(u);
         int r;
@@ -90,6 +132,9 @@ static int target_load(Unit *u) {
                 if (u->meta.default_dependencies)
                         if ((r = target_add_default_dependencies(t)) < 0)
                                 return r;
+
+                if ((r = target_add_getty_dependencies(t)) < 0)
+                        return r;
         }
 
         return 0;
diff --git a/units/systemd-auto-serial-getty.service.in b/units/systemd-auto-serial-getty.service.in
deleted file mode 100644
index 8051c74..0000000
--- a/units/systemd-auto-serial-getty.service.in
+++ /dev/null
@@ -1,16 +0,0 @@
-#  This file is part of systemd.
-#
-#  systemd is free software; you can redistribute it and/or modify it
-#  under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-
-[Unit]
-Description=Automatically Spawn getty on Serial Kernel Console
-
-[Service]
-Type=oneshot
-ExecStart=@rootlibexecdir@/systemd-auto-serial-getty
-
-[Install]
-WantedBy=getty.target


More information about the systemd-commits mailing list