On Tue, Mar 1, 2011 at 12:32 AM, Lennart Poettering
<[email protected]> wrote:
> On Sun, 27.02.11 01:05, Andrey Borzenkov ([email protected]) wrote:
>
>> Currently it is possible to either output legacy initscripts on
>> console which often messes it up completely, or suppress output
>> alltogether which makes it hard to debug boot issues.
>>
>> While DefaultStandardOutput could be used to force syslog, it will
>> affect *all* services, also those that set stdin to tty and rely
>> on inheriting it. So make it possible for SysV to explicitly control
>> output.
>
> Hmm, how would you use this? Send SysV stdout to /dev/null, but SysV
> stderr to the console? Is this really advisable? i.e. are you sure that
> if current init scripts encounter an error they properly write warnings
> to stderr, instead of just echoing them to stdout?
>

I do not really need SysVStandardError, it was just monkey job, you
know :) copy'n'paste from DefaultStandardOutput/Error

> if we merge this, is SysVConsole still useful then? Shouldn't we kill
> that then?
>

Yes, I expected it :)

Revised patch attached. I removed handling of "quiet" for SysV
because, personally, the main point of this patch is to redirect
initscripts output to stable storage (syslog) and it is already quiet
enough for me.

This also corrects a DefaultStandardOutput/Error descriptions in a
couple of places.
From: Andrey Borzenkov <[email protected]>
Subject: [PATCH] allow explicit stdout/stderr configuration for SysV services
To: [email protected]

Currently it is possible to either output legacy initscripts on
console which often messes it up completely, or suppress output
alltogether which makes it hard to debug boot issues.

While DefaultStandardOutput could be used to force syslog, it will
affect *all* services, also those that set stdin to tty and rely
on inheriting it. So make it possible for SysV to explicitly control
output.

Signed-off-by: Andrey Borzenkov <[email protected]>

---
 man/systemd.conf.xml |    4 +-
 man/systemd.xml      |   48 +++++++++++++++++++-------------------------
 src/dbus-manager.c   |    4 +-
 src/main.c           |   53 ++++++++++++++++++++++---------------------------
 src/manager.h        |    2 +-
 src/service.c        |    4 +-
 src/system.conf      |    2 +-
 7 files changed, 53 insertions(+), 64 deletions(-)

diff --git a/man/systemd.conf.xml b/man/systemd.conf.xml
index 8faedda..45f0802 100644
--- a/man/systemd.conf.xml
+++ b/man/systemd.conf.xml
@@ -79,10 +79,10 @@
                                 <term><varname>DumpCore=yes</varname></term>
                                 <term><varname>CrashShell=no</varname></term>
                                 <term><varname>ShowStatus=yes</varname></term>
-                                <term><varname>SysVConsole=yes</varname></term>
                                 <term><varname>CrashChVT=1</varname></term>
-                                <term><varname>DefaultStandardOutput=null</varname></term>
+                                <term><varname>DefaultStandardOutput=inherit</varname></term>
                                 <term><varname>DefaultStandardError=inherit</varname></term>
+                                <term><varname>SysVStandardOutput=tty</varname></term>
 
                                 <listitem><para>Configures various
                                 parameters of basic manager
diff --git a/man/systemd.xml b/man/systemd.xml
index 2c42a02..a95d83f 100644
--- a/man/systemd.xml
+++ b/man/systemd.xml
@@ -192,18 +192,6 @@
                                 <option>true</option>.</para></listitem>
                         </varlistentry>
                         <varlistentry>
-                                <term><option>--sysv-console=</option></term>
-
-                                <listitem><para>Controls whether
-                                output of SysV init scripts will be
-                                directed to the console. This switch
-                                has no effect when run as user
-                                instance. Takes a boolean argument
-                                which may be omitted which is
-                                interpreted as
-                                <option>true</option>.</para></listitem>
-                        </varlistentry>
-                        <varlistentry>
                                 <term><option>--log-target=</option></term>
 
                                 <listitem><para>Set log
@@ -259,7 +247,7 @@
                                 services and sockets, i.e. controls
                                 the default for
                                 <option>StandardOutput=</option>
-                                resp. <option>StandardExecute=</option>
+                                resp. <option>StandardError=</option>
                                 (see
                                 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
                                 for details). Takes one of
@@ -273,6 +261,16 @@
                                 argument is omitted it defaults to
                                 <option>inherit</option>.</para></listitem>
                         </varlistentry>
+                        <varlistentry>
+                                <term><option>--sysv-standard-output=</option></term>
+
+                                <listitem><para>Sets the default
+                                output for SysV init scripts. 
+				Possible values are the same as for option
+                                <option>--default-standard-output=</option>
+                                If the argument is omitted it defaults to
+                                <option>tty</option>.</para></listitem>
+                        </varlistentry>
                 </variablelist>
         </refsect1>
 
@@ -979,20 +977,6 @@
                         </varlistentry>
 
                         <varlistentry>
-                                <term><varname>systemd.sysv_console=</varname></term>
-
-                                <listitem><para>Takes a boolean
-                                argument. If <option>true</option>
-                                output of SysV init scripts will be
-                                directed to the console. Defaults to
-                                <option>true</option>, unless
-                                <option>quiet</option> is passed as
-                                kernel command line option in which
-                                case it defaults to
-                                <option>false</option>.</para></listitem>
-                        </varlistentry>
-
-                        <varlistentry>
                                 <term><varname>systemd.log_target=</varname></term>
                                 <term><varname>systemd.log_level=</varname></term>
                                 <term><varname>systemd.log_color=</varname></term>
@@ -1016,6 +1000,16 @@
                                 above.</para></listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><varname>systemd.sysv_standard_output=</varname></term>
+                                <listitem><para>Controls default
+                                standard output for
+                                SysV init scripts, with the same effect as the
+                                <option>--sysv-standard-output=</option>
+                                command line argument described
+                                above.</para></listitem>
+                        </varlistentry>
+
                 </variablelist>
         </refsect1>
 
diff --git a/src/dbus-manager.c b/src/dbus-manager.c
index 1b3bddc..218851f 100644
--- a/src/dbus-manager.c
+++ b/src/dbus-manager.c
@@ -174,7 +174,7 @@
 
 #ifdef HAVE_SYSV_COMPAT
 #define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV                           \
-        "  <property name=\"SysVConsole\" type=\"b\" access=\"read\"/>\n" \
+        "  <property name=\"SysVStandardOutput\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"SysVInitPath\" type=\"as\" access=\"read\"/>\n" \
         "  <property name=\"SysVRcndPath\" type=\"as\" access=\"read\"/>\n"
 #else
@@ -328,7 +328,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
                 { "org.freedesktop.systemd1.Manager", "DefaultStandardOutput", bus_manager_append_exec_output, "s", &m->default_std_output },
                 { "org.freedesktop.systemd1.Manager", "DefaultStandardError",  bus_manager_append_exec_output, "s", &m->default_std_error  },
 #ifdef HAVE_SYSV_COMPAT
-                { "org.freedesktop.systemd1.Manager", "SysVConsole",   bus_property_append_bool,      "b",  &m->sysv_console   },
+                { "org.freedesktop.systemd1.Manager", "SysVStandardOutput", bus_manager_append_exec_output, "s", &m->sysv_std_output   },
                 { "org.freedesktop.systemd1.Manager", "SysVInitPath",  bus_property_append_strv,      "as", m->lookup_paths.sysvinit_path },
                 { "org.freedesktop.systemd1.Manager", "SysVRcndPath",  bus_property_append_strv,      "as", m->lookup_paths.sysvrcnd_path },
 #endif
diff --git a/src/main.c b/src/main.c
index 2c02217..87f6d40 100644
--- a/src/main.c
+++ b/src/main.c
@@ -68,7 +68,7 @@ static int arg_crash_chvt = -1;
 static bool arg_confirm_spawn = false;
 static bool arg_show_status = true;
 #ifdef HAVE_SYSV_COMPAT
-static bool arg_sysv_console = true;
+static ExecOutput arg_sysv_std_output = EXEC_OUTPUT_TTY;
 #endif
 static bool arg_mount_auto = true;
 static bool arg_swap_auto = true;
@@ -315,13 +315,13 @@ static int parse_proc_cmdline_word(const char *word) {
                 else
                         arg_default_std_error = r;
 #ifdef HAVE_SYSV_COMPAT
-        } else if (startswith(word, "systemd.sysv_console=")) {
+        } else if (startswith(word, "systemd.sysv_std_output=")) {
                 int r;
 
-                if ((r = parse_boolean(word + 21)) < 0)
-                        log_warning("Failed to parse SysV console switch %s, Ignoring.", word + 20);
+                if ((r = exec_output_from_string(word + 24)) < 0)
+                        log_warning("Failed to parse SysV standard output switch %s, Ignoring.", word + 24);
                 else
-                        arg_sysv_console = r;
+                        arg_sysv_std_output = r;
 #endif
 
         } else if (startswith(word, "systemd.")) {
@@ -336,7 +336,8 @@ static int parse_proc_cmdline_word(const char *word) {
                          "systemd.confirm_spawn=0|1                Confirm every process spawn\n"
                          "systemd.show_status=0|1                  Show status updates on the console during bootup\n"
 #ifdef HAVE_SYSV_COMPAT
-                         "systemd.sysv_console=0|1                 Connect output of SysV scripts to console\n"
+                         "systemd.sysv_standard_output=null|tty|syslog|syslog+console|kmsg|kmsg+console\n"
+                         "                                         Set default output of SysV scripts\n"
 #endif
                          "systemd.log_target=console|kmsg|syslog|syslog-or-kmsg|null\n"
                          "                                         Log target\n"
@@ -348,12 +349,9 @@ static int parse_proc_cmdline_word(const char *word) {
                          "systemd.default_standard_error=null|tty|syslog|syslog+console|kmsg|kmsg+console\n"
                          "                                         Set default log error output for services\n");
 
-        } else if (streq(word, "quiet")) {
+        } else if (streq(word, "quiet"))
                 arg_show_status = false;
-#ifdef HAVE_SYSV_COMPAT
-                arg_sysv_console = false;
-#endif
-        } else {
+        else {
                 unsigned i;
 
                 /* SysV compatibility */
@@ -499,7 +497,7 @@ static int parse_config_file(void) {
                 { "CrashShell",            config_parse_bool,         &arg_crash_shell,         "Manager" },
                 { "ShowStatus",            config_parse_bool,         &arg_show_status,         "Manager" },
 #ifdef HAVE_SYSV_COMPAT
-                { "SysVConsole",           config_parse_bool,         &arg_sysv_console,        "Manager" },
+                { "SysVStandardOutput",    config_parse_output,       &arg_sysv_std_output,     "Manager" },
 #endif
                 { "CrashChVT",             config_parse_int,          &arg_crash_chvt,          "Manager" },
                 { "CPUAffinity",           config_parse_cpu_affinity, NULL,                     "Manager" },
@@ -586,7 +584,9 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_CRASH_SHELL,
                 ARG_CONFIRM_SPAWN,
                 ARG_SHOW_STATUS,
-                ARG_SYSV_CONSOLE,
+#ifdef HAVE_SYSV_COMPAT
+                ARG_SYSV_STD_OUTPUT,
+#endif
                 ARG_DESERIALIZE,
                 ARG_INTROSPECT,
                 ARG_DEFAULT_STD_OUTPUT,
@@ -609,7 +609,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "confirm-spawn",            no_argument,       NULL, ARG_CONFIRM_SPAWN            },
                 { "show-status",              optional_argument, NULL, ARG_SHOW_STATUS              },
 #ifdef HAVE_SYSV_COMPAT
-                { "sysv-console",             optional_argument, NULL, ARG_SYSV_CONSOLE             },
+                { "sysv-std-output",          required_argument, NULL, ARG_SYSV_STD_OUTPUT          },
 #endif
                 { "deserialize",              required_argument, NULL, ARG_DESERIALIZE              },
                 { "introspect",               optional_argument, NULL, ARG_INTROSPECT               },
@@ -735,16 +735,13 @@ static int parse_argv(int argc, char *argv[]) {
                                 arg_show_status = true;
                         break;
 #ifdef HAVE_SYSV_COMPAT
-                case ARG_SYSV_CONSOLE:
+                case ARG_SYSV_STD_OUTPUT:
 
-                        if (optarg) {
-                                if ((r = parse_boolean(optarg)) < 0) {
-                                        log_error("Failed to SysV console boolean %s.", optarg);
-                                        return r;
-                                }
-                                arg_sysv_console = r;
+                        if ((r = exec_output_from_string(optarg)) < 0) {
+                                log_error("Failed to parse SysV standard output setting %s.", optarg);
+                                return r;
                         } else
-                                arg_sysv_console = true;
+                                arg_sysv_std_output = r;
                         break;
 #endif
 
@@ -835,7 +832,7 @@ static int help(void) {
                "     --confirm-spawn             Ask for confirmation when spawning processes\n"
                "     --show-status[=0|1]         Show status updates on the console during bootup\n"
 #ifdef HAVE_SYSV_COMPAT
-               "     --sysv-console[=0|1]        Connect output of SysV scripts to console\n"
+               "     --sysv-std-output=          Set default standard output of SysV scripts\n"
 #endif
                "     --log-target=TARGET         Set log target (console, syslog, kmsg, syslog-or-kmsg, null)\n"
                "     --log-level=LEVEL           Set log level (debug, info, notice, warning, err, crit, alert, emerg)\n"
@@ -1145,7 +1142,7 @@ int main(int argc, char *argv[]) {
         m->confirm_spawn = arg_confirm_spawn;
         m->show_status = arg_show_status;
 #ifdef HAVE_SYSV_COMPAT
-        m->sysv_console = arg_sysv_console;
+        m->sysv_std_output = arg_sysv_std_output;
 #endif
         m->mount_auto = arg_mount_auto;
         m->swap_auto = arg_swap_auto;
@@ -1286,7 +1283,7 @@ finish:
         label_finish();
 
         if (reexecute) {
-                const char *args[15];
+                const char *args[19];
                 unsigned i = 0;
                 char sfd[16];
 
@@ -1321,10 +1318,8 @@ finish:
                         args[i++] = "--show-status=0";
 
 #ifdef HAVE_SYSV_COMPAT
-                if (arg_sysv_console)
-                        args[i++] = "--sysv-console=1";
-                else
-                        args[i++] = "--sysv-console=0";
+                args[i++] = "--sysv-std-output";
+                args[i++] = exec_output_to_string(arg_sysv_std_output);
 #endif
 
                 snprintf(sfd, sizeof(sfd), "%i", fileno(serialization));
diff --git a/src/manager.h b/src/manager.h
index efca4ff..047144c 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -214,7 +214,7 @@ struct Manager {
         bool show_status;
         bool confirm_spawn;
 #ifdef HAVE_SYSV_COMPAT
-        bool sysv_console;
+        ExecOutput sysv_std_output;
 #endif
         bool mount_auto;
         bool swap_auto;
diff --git a/src/service.c b/src/service.c
index 39a46d6..5790c4f 100644
--- a/src/service.c
+++ b/src/service.c
@@ -818,8 +818,8 @@ static int service_load_sysv_path(Service *s, const char *path) {
         s->remain_after_exit = true;
         s->restart = SERVICE_RESTART_NO;
         s->exec_context.std_output =
-                (s->meta.manager->sysv_console || s->exec_context.std_input == EXEC_INPUT_TTY)
-                ? EXEC_OUTPUT_TTY : s->meta.manager->default_std_output;
+                s->exec_context.std_input == EXEC_INPUT_TTY
+                ? EXEC_OUTPUT_TTY : s->meta.manager->sysv_std_output;
         s->exec_context.kill_mode = KILL_PROCESS_GROUP;
 
         /* We use the long description only if
diff --git a/src/system.conf b/src/system.conf
index 4e06319..e77f33a 100644
--- a/src/system.conf
+++ b/src/system.conf
@@ -15,7 +15,6 @@
 #DumpCore=yes
 #CrashShell=no
 #ShowStatus=yes
-#SysVConsole=yes
 #CrashChVT=1
 #CPUAffinity=1 2
 #MountAuto=yes
@@ -23,3 +22,4 @@
 #DefaultControllers=cpu
 #DefaultStandardOutput=inherit
 #DefaultStandardError=inherit
+#SysVStandardOutput=tty
-- 
tg: (020501d..) upstream/sysv-stdout (depends on: origin/master)
_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to