exec: introduce global defaults for the standard output of services

This commit is contained in:
Lennart Poettering 2011-02-15 11:52:29 +01:00
parent b7cf1b68a7
commit 0a494f1ff3
13 changed files with 127 additions and 22 deletions

4
TODO
View File

@ -7,6 +7,8 @@ Bugs:
* systemctl default is started when we type "reboot" at rescue mode prompt
* mkswap/mke2fs aus cryptsetup unit muss vor dem mounten ausgeführt werden.
Features:
* look up crypto partition mount points via fstab to show to the user when prompting for a password
@ -124,8 +126,6 @@ Features:
* allow runtime changing of log level and target
* global defaults for StandardOuput=xxx
Fedora:
* chkconfig → systemd enable/daemon-reload glue

View File

@ -81,6 +81,8 @@
<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>DefaultStandardError=inherit</varname></term>
<listitem><para>Configures various
parameters of basic manager

View File

@ -250,6 +250,30 @@
it defaults to
<option>true</option>.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--default-standard-output=</option></term>
<term><option>--default-standard-error=</option></term>
<listitem><para>Sets the default
output resp. error output for all
services and sockets, i.e. controls
the default for
<option>StandardOutput=</option>
resp. <option>StandardExecute=</option>
(see
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details). Takes one of
<option>inherit</option>,
<option>null</option>,
<option>tty</option>,
<option>syslog</option>,
<option>syslog+console</option>,
<option>kmsg</option>,
<option>kmsg-console</option>. If the
argument is omitted it defaults to
<option>null</option>
resp. <option>inherit</option>.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
@ -981,6 +1005,18 @@
environment variables described above.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>systemd.default_standard_output=</varname></term>
<term><varname>systemd.default_standard_error=</varname></term>
<listitem><para>Controls default
standard output/error output for
services, with the same effect as the
<option>--default-standard-output=</option>
resp. <option>--default-standard-error=</option>
command line arguments described
above.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@ -168,8 +168,9 @@
" <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"MountAuto\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"SwapAuto\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"DefaultControllers\" type=\"as\" access=\"read\"/>\n"
\
" <property name=\"DefaultControllers\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"DefaultStandardOutput\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"DefaultStandardError\" type=\"s\" access=\"read\"/>\n"
#ifdef HAVE_SYSV_COMPAT
#define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV \
@ -205,6 +206,7 @@
const char bus_manager_interface[] _introspect_("Manager") = BUS_MANAGER_INTERFACE;
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as, manager_running_as, ManagerRunningAs);
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_exec_output, exec_output, ExecOutput);
static int bus_manager_append_log_target(Manager *m, DBusMessageIter *i, const char *property, void *data) {
const char *t;
@ -323,6 +325,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
{ "org.freedesktop.systemd1.Manager", "MountAuto", bus_property_append_bool, "b", &m->mount_auto },
{ "org.freedesktop.systemd1.Manager", "SwapAuto", bus_property_append_bool, "b", &m->swap_auto },
{ "org.freedesktop.systemd1.Manager", "DefaultControllers", bus_property_append_strv, "as", m->default_controllers },
{ "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", "SysVInitPath", bus_property_append_strv, "as", m->lookup_paths.sysvinit_path },

View File

@ -73,6 +73,8 @@ static bool arg_sysv_console = true;
static bool arg_mount_auto = true;
static bool arg_swap_auto = true;
static char **arg_default_controllers = NULL;
static ExecOutput arg_default_std_output = EXEC_OUTPUT_NULL;
static ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT;
static FILE* serialization = NULL;
@ -298,6 +300,20 @@ static int parse_proc_cmdline_word(const char *word) {
log_warning("Failed to parse show status switch %s, Ignoring.", word + 20);
else
arg_show_status = r;
} else if (startswith(word, "systemd.default_standard_output=")) {
int r;
if ((r = exec_output_from_string(word + 32)) < 0)
log_warning("Failed to parse default standard output switch %s, Ignoring.", word + 32);
else
arg_default_std_output = r;
} else if (startswith(word, "systemd.default_standard_error=")) {
int r;
if ((r = exec_output_from_string(word + 31)) < 0)
log_warning("Failed to parse default standard error switch %s, Ignoring.", word + 31);
else
arg_default_std_error = r;
#ifdef HAVE_SYSV_COMPAT
} else if (startswith(word, "systemd.sysv_console=")) {
int r;
@ -326,7 +342,11 @@ static int parse_proc_cmdline_word(const char *word) {
" Log target\n"
"systemd.log_level=LEVEL Log level\n"
"systemd.log_color=0|1 Highlight important log messages\n"
"systemd.log_location=0|1 Include code location in log messages\n");
"systemd.log_location=0|1 Include code location in log messages\n"
"systemd.default_standard_output=null|tty|syslog|syslog+console|kmsg|kmsg+console\n"
" Set default log output for services\n"
"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")) {
arg_show_status = false;
@ -466,24 +486,28 @@ static int config_parse_cpu_affinity(
return 0;
}
static DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier");
static int parse_config_file(void) {
const ConfigItem items[] = {
{ "LogLevel", config_parse_level, NULL, "Manager" },
{ "LogTarget", config_parse_target, NULL, "Manager" },
{ "LogColor", config_parse_color, NULL, "Manager" },
{ "LogLocation", config_parse_location, NULL, "Manager" },
{ "DumpCore", config_parse_bool, &arg_dump_core, "Manager" },
{ "CrashShell", config_parse_bool, &arg_crash_shell, "Manager" },
{ "ShowStatus", config_parse_bool, &arg_show_status, "Manager" },
{ "LogLevel", config_parse_level, NULL, "Manager" },
{ "LogTarget", config_parse_target, NULL, "Manager" },
{ "LogColor", config_parse_color, NULL, "Manager" },
{ "LogLocation", config_parse_location, NULL, "Manager" },
{ "DumpCore", config_parse_bool, &arg_dump_core, "Manager" },
{ "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" },
{ "SysVConsole", config_parse_bool, &arg_sysv_console, "Manager" },
#endif
{ "CrashChVT", config_parse_int, &arg_crash_chvt, "Manager" },
{ "CPUAffinity", config_parse_cpu_affinity, NULL, "Manager" },
{ "MountAuto", config_parse_bool, &arg_mount_auto, "Manager" },
{ "SwapAuto", config_parse_bool, &arg_swap_auto, "Manager" },
{ "DefaultControllers", config_parse_strv, &arg_default_controllers, "Manager" },
{ "CrashChVT", config_parse_int, &arg_crash_chvt, "Manager" },
{ "CPUAffinity", config_parse_cpu_affinity, NULL, "Manager" },
{ "MountAuto", config_parse_bool, &arg_mount_auto, "Manager" },
{ "SwapAuto", config_parse_bool, &arg_swap_auto, "Manager" },
{ "DefaultControllers", config_parse_strv, &arg_default_controllers, "Manager" },
{ "DefaultStandardOutput", config_parse_output, &arg_default_std_output, "Manager" },
{ "DefaultStandardError", config_parse_output, &arg_default_std_error, "Manager" },
{ NULL, NULL, NULL, NULL }
};
@ -564,7 +588,9 @@ static int parse_argv(int argc, char *argv[]) {
ARG_SHOW_STATUS,
ARG_SYSV_CONSOLE,
ARG_DESERIALIZE,
ARG_INTROSPECT
ARG_INTROSPECT,
ARG_DEFAULT_STD_OUTPUT,
ARG_DEFAULT_STD_ERROR
};
static const struct option options[] = {
@ -587,6 +613,8 @@ static int parse_argv(int argc, char *argv[]) {
#endif
{ "deserialize", required_argument, NULL, ARG_DESERIALIZE },
{ "introspect", optional_argument, NULL, ARG_INTROSPECT },
{ "default-standard-output", required_argument, NULL, ARG_DEFAULT_STD_OUTPUT, },
{ "default-standard-error", required_argument, NULL, ARG_DEFAULT_STD_ERROR, },
{ NULL, 0, NULL, 0 }
};
@ -640,6 +668,24 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_DEFAULT_STD_OUTPUT:
if ((r = exec_output_from_string(optarg)) < 0) {
log_error("Failed to parse default standard output setting %s.", optarg);
return r;
} else
arg_default_std_output = r;
break;
case ARG_DEFAULT_STD_ERROR:
if ((r = exec_output_from_string(optarg)) < 0) {
log_error("Failed to parse default standard error output setting %s.", optarg);
return r;
} else
arg_default_std_error = r;
break;
case ARG_UNIT:
if ((r = set_default_unit(optarg)) < 0) {
@ -794,7 +840,9 @@ static int help(void) {
" --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"
" --log-color[=0|1] Highlight important log messages\n"
" --log-location[=0|1] Include code location in log messages\n",
" --log-location[=0|1] Include code location in log messages\n"
" --default-standard-output= Set default standard output for services\n"
" --default-standard-error= Set default standard error output for services\n",
program_invocation_short_name);
return 0;
@ -1069,6 +1117,8 @@ int main(int argc, char *argv[]) {
#endif
m->mount_auto = arg_mount_auto;
m->swap_auto = arg_swap_auto;
m->default_std_output = arg_default_std_output;
m->default_std_error = arg_default_std_error;
if (dual_timestamp_is_set(&initrd_timestamp))
m->initrd_timestamp = initrd_timestamp;

View File

@ -214,6 +214,8 @@ int manager_new(ManagerRunningAs running_as, Manager **_m) {
m->exit_code = _MANAGER_EXIT_CODE_INVALID;
m->pin_cgroupfs_fd = -1;
m->default_std_output = EXEC_OUTPUT_NULL;
#ifdef HAVE_AUDIT
m->audit_fd = -1;
#endif

View File

@ -219,6 +219,8 @@ struct Manager {
bool mount_auto;
bool swap_auto;
ExecOutput default_std_output, default_std_error;
int n_deserializing;
unsigned n_installed_jobs;

View File

@ -64,6 +64,7 @@ static void mount_init(Unit *u) {
m->directory_mode = 0755;
exec_context_init(&m->exec_context);
m->exec_context.std_output = EXEC_OUTPUT_KMSG;
/* We need to make sure that /bin/mount is always called in
* the same process group as us, so that the autofs kernel

View File

@ -121,6 +121,8 @@ static void service_init(Unit *u) {
s->guess_main_pid = true;
exec_context_init(&s->exec_context);
s->exec_context.std_output = u->meta.manager->default_std_output;
s->exec_context.std_error = u->meta.manager->default_std_error;
RATELIMIT_INIT(s->ratelimit, 10*USEC_PER_SEC, 5);
@ -817,7 +819,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
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 : EXEC_OUTPUT_NULL;
? EXEC_OUTPUT_TTY : s->meta.manager->default_std_output;
s->exec_context.kill_mode = KILL_PROCESS_GROUP;
/* We use the long description only if

View File

@ -77,6 +77,8 @@ static void socket_init(Unit *u) {
s->mark = -1;
exec_context_init(&s->exec_context);
s->exec_context.std_output = u->meta.manager->default_std_output;
s->exec_context.std_error = u->meta.manager->default_std_error;
s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
}

View File

@ -82,6 +82,7 @@ static void swap_unset_proc_swaps(Swap *s) {
s->timeout_usec = DEFAULT_TIMEOUT_USEC;
exec_context_init(&s->exec_context);
s->exec_context.std_output = EXEC_OUTPUT_KMSG;
s->parameters_etc_fstab.priority = s->parameters_proc_swaps.priority = s->parameters_fragment.priority = -1;

View File

@ -5,7 +5,7 @@
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# See systemd(1) for details
# See systemd.conf(5) for details
[Manager]
#LogLevel=info
@ -21,3 +21,5 @@
#MountAuto=yes
#SwapAuto=yes
#DefaultControllers=cpu
#DefaultStandardOutput=null
#DefaultStandardError=inherit

View File

@ -15,3 +15,4 @@ After=syslog.socket
[Service]
ExecStart=@rootlibexecdir@/systemd-logger
NotifyAccess=all
StandardOutput=null