2004-09-12 David Zeuthen <david@fubar.dk>
authorDavid Zeuthen <davidz@redhat.com>
Sun, 12 Sep 2004 10:23:42 +0000 (10:23 +0000)
committerDavid Zeuthen <davidz@redhat.com>
Sun, 12 Sep 2004 10:23:42 +0000 (10:23 +0000)
Patch from Kay Sievers <kay.sievers@vrfy.org>

* bus/bus.c (bus_context_new):
* bus/bus.h:
* bus/main.c (usage)
(main):
Add commandline option --nofork to override configuration file
setting.

ChangeLog
bus/bus.c
bus/bus.h
bus/main.c

index 2b35fdd..d6ff8be 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-09-12  David Zeuthen  <david@fubar.dk>
+
+       Patch from Kay Sievers <kay.sievers@vrfy.org>
+
+       * bus/bus.c (bus_context_new):
+       * bus/bus.h:
+       * bus/main.c (usage)
+       (main):
+       Add commandline option --nofork to override configuration file
+       setting.
+
 2004-09-09  Olivier Andrieu  <oliv__a@users.sourceforge.net>
 
        * dbus/dbus-*.h: remove the ; after DBUS_(BEGIN|END)_DECLS. Some C
index c66b7b3..043f2e1 100644 (file)
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -537,7 +537,7 @@ load_config (BusContext *context,
 
 BusContext*
 bus_context_new (const DBusString *config_file,
-                 dbus_bool_t       force_fork,
+                 ForceForkSetting  force_fork,
                  int               print_addr_fd,
                  int               print_pid_fd,
                  DBusError        *error)
@@ -656,7 +656,7 @@ bus_context_new (const DBusString *config_file,
     }
   
   /* Now become a daemon if appropriate */
-  if (force_fork || context->fork)
+  if ((force_fork != FORK_NEVER && context->fork) || force_fork == FORK_ALWAYS)
     {
       DBusString u;
 
index 79adf83..1a900ea 100644 (file)
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -61,8 +61,15 @@ typedef struct
   int reply_timeout;                  /**< How long to wait before timing out a reply */
 } BusLimits;
 
+typedef enum
+{
+  FORK_FOLLOW_CONFIG_FILE,
+  FORK_ALWAYS,
+  FORK_NEVER
+} ForceForkSetting;
+
 BusContext*       bus_context_new                                (const DBusString *config_file,
-                                                                  dbus_bool_t       force_fork,
+                                                                  ForceForkSetting  force_fork,
                                                                   int               print_addr_fd,
                                                                   int               print_pid_fd,
                                                                   DBusError        *error);
index 01a6dd4..9572769 100644 (file)
@@ -62,7 +62,7 @@ signal_handler (int sig)
 static void
 usage (void)
 {
-  fprintf (stderr, "dbus-daemon-1 [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork]\n");
+  fprintf (stderr, "dbus-daemon-1 [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork]\n");
   exit (1);
 }
 
@@ -200,8 +200,8 @@ main (int argc, char **argv)
   int i;
   dbus_bool_t print_address;
   dbus_bool_t print_pid;
-  dbus_bool_t force_fork;
-  
+  int force_fork;
+
   if (!_dbus_string_init (&config_file))
     return 1;
 
@@ -210,25 +210,27 @@ main (int argc, char **argv)
 
   if (!_dbus_string_init (&pid_fd))
     return 1;
-  
+
   print_address = FALSE;
   print_pid = FALSE;
-  force_fork = FALSE;
-  
+  force_fork = FORK_FOLLOW_CONFIG_FILE;
+
   prev_arg = NULL;
   i = 1;
   while (i < argc)
     {
       const char *arg = argv[i];
-      
+
       if (strcmp (arg, "--help") == 0 ||
           strcmp (arg, "-h") == 0 ||
           strcmp (arg, "-?") == 0)
         usage ();
       else if (strcmp (arg, "--version") == 0)
         version ();
+      else if (strcmp (arg, "--nofork") == 0)
+        force_fork = FORK_NEVER;
       else if (strcmp (arg, "--fork") == 0)
-        force_fork = TRUE;
+        force_fork = FORK_ALWAYS;
       else if (strcmp (arg, "--system") == 0)
         {
           check_two_config_files (&config_file, "system");