udisks: Also accept a --no-debug option and use it for activation
authorDavid Zeuthen <davidz@redhat.com>
Tue, 18 Oct 2011 17:51:47 +0000 (13:51 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Wed, 19 Oct 2011 14:57:19 +0000 (10:57 -0400)
Otherwise syslog gets spammed via D-Bus' system bus activation helper
via systemd (got it? got it!).

Signed-off-by: David Zeuthen <davidz@redhat.com>
data/org.freedesktop.UDisks2.service.in
doc/man/udisksd.xml
src/main.c

index 924059a..f127a69 100644 (file)
@@ -1,5 +1,5 @@
 [D-BUS Service]
 Name=org.freedesktop.UDisks2
-Exec=@privlibdir@/udisksd
+Exec=@privlibdir@/udisksd --no-debug
 User=root
 
index 40b0938..38a47fb 100644 (file)
@@ -21,6 +21,8 @@
       <command>udisksd</command>
       <arg><option>--help</option></arg>
       <arg><option>--replace</option></arg>
+      <arg><option>--no-debug</option></arg>
+      <arg><option>--no-sigint</option></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
 
           </para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><option>--no-debug</option></term>
+        <listitem>
+          <para>
+            Do not print debug or informational messages on stdout/stderr.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>--no-sigint</option></term>
+        <listitem>
+          <para>
+            Do not handle SIGINT for controlled shutdown.
+          </para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
 
index 5cba85e..a330a58 100644 (file)
 
 static GMainLoop *loop = NULL;
 static gboolean opt_replace = FALSE;
+static gboolean opt_no_debug = FALSE;
 static gboolean opt_no_sigint = FALSE;
 static GOptionEntry opt_entries[] =
 {
-  {"replace", 0, 0, G_OPTION_ARG_NONE, &opt_replace, "Replace existing daemon", NULL},
-  {"no-sigint", 0, 0, G_OPTION_ARG_NONE, &opt_no_sigint, "Do not handle SIGINT for controlled shutdown", NULL},
+  {"replace", 'r', 0, G_OPTION_ARG_NONE, &opt_replace, "Replace existing daemon", NULL},
+  {"no-debug", 'n', 0, G_OPTION_ARG_NONE, &opt_no_debug, "Don't print debug information on stdout/stderr", NULL},
+  {"no-sigint", 's', 0, G_OPTION_ARG_NONE, &opt_no_sigint, "Do not handle SIGINT for controlled shutdown", NULL},
   {NULL }
 };
 
@@ -118,6 +120,26 @@ main (int    argc,
       goto out;
     }
 
+  /* TODO: this hammer is too big - it would be a lot better to configure the
+   *       logging routines and avoid printf(3) overhead and so on
+   */
+  if (opt_no_debug)
+    {
+      gint dev_null_fd;
+      dev_null_fd = open ("/dev/null", O_RDWR);
+      if (dev_null_fd >= 0)
+        {
+          dup2 (dev_null_fd, STDIN_FILENO);
+          dup2 (dev_null_fd, STDOUT_FILENO);
+          dup2 (dev_null_fd, STDERR_FILENO);
+          close (dev_null_fd);
+        }
+      else
+        {
+          g_warning ("Error opening /dev/null: %m");
+        }
+    }
+
   udisks_notice ("udisks daemon version %s starting", PACKAGE_VERSION);
 
   loop = g_main_loop_new (NULL, FALSE);