mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-01-06 14:10:15 +01:00
dbus-daemon: add --syslog, --nosyslog, --syslog-only
Like --fork and --nofork, these override what the configuration says. Use --syslog-only to force the systemd services to log to the Journal (via syslog, which means we see the severity metadata) instead of testing sd_booted() in the configuration implementation. Signed-off-by: Simon McVittie <smcv@debian.org>
This commit is contained in:
parent
2c472b8398
commit
1c807207bb
6 changed files with 77 additions and 22 deletions
35
bus/bus.c
35
bus/bus.c
|
|
@ -47,10 +47,6 @@
|
|||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
#include <systemd/sd-daemon.h>
|
||||
#endif
|
||||
|
||||
struct BusContext
|
||||
{
|
||||
int refcount;
|
||||
|
|
@ -285,6 +281,7 @@ process_config_first_time_only (BusContext *context,
|
|||
DBusList **auth_mechanisms_list;
|
||||
int len;
|
||||
dbus_bool_t retval;
|
||||
DBusLogFlags log_flags = DBUS_LOG_FLAGS_STDERR;
|
||||
|
||||
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
||||
|
||||
|
|
@ -292,26 +289,28 @@ process_config_first_time_only (BusContext *context,
|
|||
auth_mechanisms = NULL;
|
||||
pidfile = NULL;
|
||||
|
||||
context->syslog = bus_config_parser_get_syslog (parser);
|
||||
|
||||
if (context->syslog)
|
||||
if (flags & BUS_CONTEXT_FLAG_SYSLOG_ALWAYS)
|
||||
{
|
||||
#ifdef HAVE_SYSTEMD
|
||||
/* If running under systemd, we don't want to log to both stderr and
|
||||
* syslog, because our stderr is probably connected to journald too,
|
||||
* so we'd duplicate all our messages. */
|
||||
if (sd_booted () > 0)
|
||||
_dbus_init_system_log ("dbus-daemon", DBUS_LOG_FLAGS_SYSTEM_LOG);
|
||||
else
|
||||
#endif
|
||||
_dbus_init_system_log ("dbus-daemon",
|
||||
DBUS_LOG_FLAGS_SYSTEM_LOG | DBUS_LOG_FLAGS_STDERR);
|
||||
context->syslog = TRUE;
|
||||
log_flags |= DBUS_LOG_FLAGS_SYSTEM_LOG;
|
||||
|
||||
if (flags & BUS_CONTEXT_FLAG_SYSLOG_ONLY)
|
||||
log_flags &= ~DBUS_LOG_FLAGS_STDERR;
|
||||
}
|
||||
else if (flags & BUS_CONTEXT_FLAG_SYSLOG_NEVER)
|
||||
{
|
||||
context->syslog = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
_dbus_init_system_log ("dbus-daemon", DBUS_LOG_FLAGS_STDERR);
|
||||
context->syslog = bus_config_parser_get_syslog (parser);
|
||||
|
||||
if (context->syslog)
|
||||
log_flags |= DBUS_LOG_FLAGS_SYSTEM_LOG;
|
||||
}
|
||||
|
||||
_dbus_init_system_log ("dbus-daemon", log_flags);
|
||||
|
||||
if (flags & BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION)
|
||||
context->systemd_activation = TRUE;
|
||||
else
|
||||
|
|
|
|||
|
|
@ -72,7 +72,10 @@ typedef enum
|
|||
BUS_CONTEXT_FLAG_FORK_ALWAYS = (1 << 1),
|
||||
BUS_CONTEXT_FLAG_FORK_NEVER = (1 << 2),
|
||||
BUS_CONTEXT_FLAG_WRITE_PID_FILE = (1 << 3),
|
||||
BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION = (1 << 4)
|
||||
BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION = (1 << 4),
|
||||
BUS_CONTEXT_FLAG_SYSLOG_ALWAYS = (1 << 5),
|
||||
BUS_CONTEXT_FLAG_SYSLOG_NEVER = (1 << 6),
|
||||
BUS_CONTEXT_FLAG_SYSLOG_ONLY = (1 << 7)
|
||||
} BusContextFlags;
|
||||
|
||||
BusContext* bus_context_new (const DBusString *config_file,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ Documentation=man:dbus-daemon(1)
|
|||
Requires=dbus.socket
|
||||
|
||||
[Service]
|
||||
ExecStart=@EXPANDED_BINDIR@/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
|
||||
ExecStart=@EXPANDED_BINDIR@/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
|
||||
ExecReload=@EXPANDED_BINDIR@/dbus-send --print-reply --system --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig
|
||||
OOMScoreAdjust=-900
|
||||
|
|
|
|||
18
bus/main.c
18
bus/main.c
|
|
@ -146,6 +146,9 @@ usage (void)
|
|||
" [--introspect]"
|
||||
" [--address=ADDRESS]"
|
||||
" [--nopidfile]"
|
||||
" [--nosyslog]"
|
||||
" [--syslog]"
|
||||
" [--syslog-only]"
|
||||
" [--nofork]"
|
||||
#ifdef DBUS_UNIX
|
||||
" [--fork]"
|
||||
|
|
@ -441,6 +444,21 @@ main (int argc, char **argv)
|
|||
{
|
||||
introspect ();
|
||||
}
|
||||
else if (strcmp (arg, "--nosyslog") == 0)
|
||||
{
|
||||
flags &= ~BUS_CONTEXT_FLAG_SYSLOG_ALWAYS;
|
||||
flags |= BUS_CONTEXT_FLAG_SYSLOG_NEVER;
|
||||
}
|
||||
else if (strcmp (arg, "--syslog") == 0)
|
||||
{
|
||||
flags &= ~BUS_CONTEXT_FLAG_SYSLOG_NEVER;
|
||||
flags |= BUS_CONTEXT_FLAG_SYSLOG_ALWAYS;
|
||||
}
|
||||
else if (strcmp (arg, "--syslog-only") == 0)
|
||||
{
|
||||
flags &= ~BUS_CONTEXT_FLAG_SYSLOG_NEVER;
|
||||
flags |= (BUS_CONTEXT_FLAG_SYSLOG_ALWAYS|BUS_CONTEXT_FLAG_SYSLOG_ONLY);
|
||||
}
|
||||
else if (strcmp (arg, "--nofork") == 0)
|
||||
{
|
||||
flags &= ~BUS_CONTEXT_FLAG_FORK_ALWAYS;
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@ Documentation=man:dbus-daemon(1)
|
|||
Requires=dbus.socket
|
||||
|
||||
[Service]
|
||||
ExecStart=@EXPANDED_BINDIR@/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation
|
||||
ExecStart=@EXPANDED_BINDIR@/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
|
||||
ExecReload=@EXPANDED_BINDIR@/dbus-send --print-reply --session --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@
|
|||
<arg choice='opt'><arg choice='plain'>--print-address </arg><arg choice='opt'><replaceable>=DESCRIPTOR</replaceable></arg></arg>
|
||||
<arg choice='opt'><arg choice='plain'>--print-pid </arg><arg choice='opt'><replaceable>=DESCRIPTOR</replaceable></arg></arg>
|
||||
<arg choice='opt'>--fork </arg>
|
||||
<arg choice='opt'>--nosyslog </arg>
|
||||
<arg choice='opt'>--syslog </arg>
|
||||
<arg choice='opt'>--syslog-only </arg>
|
||||
<sbr/>
|
||||
</cmdsynopsis>
|
||||
</refsynopsisdiv>
|
||||
|
|
@ -164,6 +167,36 @@ files.</para>
|
|||
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--syslog</option></term>
|
||||
<listitem>
|
||||
<para>Force the message bus to use the system log for messages,
|
||||
in addition to writing to standard error, even if the configuration
|
||||
file does not specify that it should. On Unix, this uses
|
||||
the syslog; on Windows, this uses OutputDebugString().</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--syslog-only</option></term>
|
||||
<listitem>
|
||||
<para>Force the message bus to use the system log for messages,
|
||||
and <emphasis>not</emphasis> duplicate them to standard error.
|
||||
On Unix, this uses the syslog; on Windows, this uses
|
||||
OutputDebugString().</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--nosyslog</option></term>
|
||||
<listitem>
|
||||
<para>Force the message bus to use only standard error for messages,
|
||||
even if the configuration file specifies that it should use
|
||||
the system log.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
|
|
@ -325,7 +358,9 @@ This may be useful to avoid affecting the behavior of child processes.</para>
|
|||
|
||||
</itemizedlist>
|
||||
|
||||
<para>If present, the bus daemon will log to syslog.</para>
|
||||
<para>If present, the bus daemon will log to syslog. The
|
||||
--syslog, --syslog-only and --nosyslog command-line options take precedence
|
||||
over this setting.</para>
|
||||
|
||||
<itemizedlist remap='TP'>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue