Commit a8423067 authored by Lennart Poettering's avatar Lennart Poettering Committed by Simon McVittie

bus: introduce --nopidfile switch to disable writing of PID files

When used with init systems such as systemd (where PID files are
redundant) this allows us to disable PID files even if a path is
configured for them in the normal bus configuration files.

Make use of this new switch in the systemd unit file.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=45520Reviewed-by: default avatarSimon McVittie <simon.mcvittie@collabora.co.uk>
parent dd403815
......@@ -270,6 +270,7 @@ process_config_first_time_only (BusContext *context,
BusConfigParser *parser,
const DBusString *address,
dbus_bool_t systemd_activation,
dbus_bool_t write_pidfile,
DBusError *error)
{
DBusString log_prefix;
......@@ -285,6 +286,7 @@ process_config_first_time_only (BusContext *context,
retval = FALSE;
auth_mechanisms = NULL;
pidfile = NULL;
_dbus_init_system_log ();
......@@ -295,7 +297,10 @@ process_config_first_time_only (BusContext *context,
* avoid that. But we want to check for the pid file
* before overwriting any existing sockets, etc.
*/
pidfile = bus_config_parser_get_pidfile (parser);
if (write_pidfile)
pidfile = bus_config_parser_get_pidfile (parser);
if (pidfile != NULL)
{
DBusString u;
......@@ -698,6 +703,7 @@ bus_context_new (const DBusString *config_file,
DBusPipe *print_pid_pipe,
const DBusString *address,
dbus_bool_t systemd_activation,
dbus_bool_t write_pidfile,
DBusError *error)
{
BusContext *context;
......@@ -751,7 +757,7 @@ bus_context_new (const DBusString *config_file,
goto failed;
}
if (!process_config_first_time_only (context, parser, address, systemd_activation, error))
if (!process_config_first_time_only (context, parser, address, systemd_activation, write_pidfile, error))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
goto failed;
......
......@@ -77,6 +77,7 @@ BusContext* bus_context_new (const DBusStri
DBusPipe *print_pid_pipe,
const DBusString *address,
dbus_bool_t systemd_activation,
dbus_bool_t write_pidfile,
DBusError *error);
dbus_bool_t bus_context_reload_config (BusContext *context,
DBusError *error);
......
......@@ -4,7 +4,6 @@ Requires=dbus.socket
After=syslog.target
[Service]
ExecStartPre=-/bin/rm -f @DBUS_SYSTEM_PID_FILE@
ExecStart=@EXPANDED_BINDIR@/dbus-daemon --system --address=systemd: --nofork --systemd-activation
ExecStart=@EXPANDED_BINDIR@/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
ExecReload=@EXPANDED_BINDIR@/dbus-send --print-reply --system --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig
OOMScoreAdjust=-900
......@@ -125,7 +125,7 @@ signal_handler (int sig)
static void
usage (void)
{
fprintf (stderr, DBUS_DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork] [--introspect] [--address=ADDRESS] [--systemd-activation]\n");
fprintf (stderr, DBUS_DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork] [--introspect] [--address=ADDRESS] [--systemd-activation] [--nopidfile]\n");
exit (1);
}
......@@ -357,6 +357,7 @@ main (int argc, char **argv)
dbus_bool_t print_pid;
int force_fork;
dbus_bool_t systemd_activation;
dbus_bool_t write_pidfile;
if (!_dbus_string_init (&config_file))
return 1;
......@@ -374,6 +375,7 @@ main (int argc, char **argv)
print_pid = FALSE;
force_fork = FORK_FOLLOW_CONFIG_FILE;
systemd_activation = FALSE;
write_pidfile = TRUE;
prev_arg = NULL;
i = 1;
......@@ -393,6 +395,8 @@ main (int argc, char **argv)
force_fork = FORK_NEVER;
else if (strcmp (arg, "--fork") == 0)
force_fork = FORK_ALWAYS;
else if (strcmp (arg, "--nopidfile") == 0)
write_pidfile = FALSE;
else if (strcmp (arg, "--systemd-activation") == 0)
systemd_activation = TRUE;
else if (strcmp (arg, "--system") == 0)
......@@ -574,6 +578,7 @@ main (int argc, char **argv)
&print_addr_pipe, &print_pid_pipe,
_dbus_string_get_length(&address) > 0 ? &address : NULL,
systemd_activation,
write_pidfile,
&error);
_dbus_string_free (&config_file);
if (context == NULL)
......
......@@ -292,7 +292,7 @@ bus_context_new_test (const DBusString *test_data_dir,
}
dbus_error_init (&error);
context = bus_context_new (&config_file, FALSE, NULL, NULL, NULL, FALSE, &error);
context = bus_context_new (&config_file, FALSE, NULL, NULL, NULL, FALSE, FALSE, &error);
if (context == NULL)
{
_DBUS_ASSERT_ERROR_IS_SET (&error);
......
......@@ -94,6 +94,10 @@ configured in the configuration file.
.I "\-\-systemd\-activation"
Enable systemd\-style service activation. Only useful in conjunction
with the systemd system and session manager on Linux.
.TP
.I "\-\-nopidfile"
Don't write a PID file even if one is configured in the configuration
files.
.SH CONFIGURATION FILE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment