bus: introduce --nopidfile switch to disable writing of PID files
authorLennart Poettering <lennart@poettering.net>
Thu, 2 Feb 2012 01:25:11 +0000 (02:25 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Fri, 10 Feb 2012 10:07:24 +0000 (10:07 +0000)
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=45520
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
bus/bus.c
bus/bus.h
bus/dbus.service.in
bus/main.c
bus/test.c
doc/dbus-daemon.1.in

index c7308b7..ae2a61a 100644 (file)
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -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;
index ebef17c..c476012 100644 (file)
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -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);
index 8ab067f..160947c 100644 (file)
@@ -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
index a0bf07c..1e3abae 100644 (file)
@@ -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)
index 9a0c196..19caa02 100644 (file)
@@ -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);
index 185441c..b063e64 100644 (file)
@@ -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