[Libguestfs] [PATCH nbdkit 1/2] server: Add --log=null option.

Richard W.M. Jones
2019-11-02T21:23:33Z

This option discards error messages.
---
 docs/nbdkit-service.pod | 5 +++--
 docs/nbdkit.pod         | 7 +++++--
 server/internal.h       | 1 +
 server/log.c            | 3 +++
 server/main.c           | 5 ++++-
 5 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/docs/nbdkit-service.pod b/docs/nbdkit-service.pod
index e743628..145a652 100644
--- a/docs/nbdkit-service.pod
+++ b/docs/nbdkit-service.pod
@@ -52,8 +52,9 @@
L<http://0pointer.de/blog/projects/socket-activation.html>

 =head1 LOGGING

-Error messages from nbdkit can be sent to either standard error
-(I<--log=stderr>) or to the system log (I<--log=syslog>).
+Error messages from nbdkit can be sent to standard error
+(I<--log=stderr>), or to the system log (I<--log=syslog>), or can
be
+discarded completely (I<--log=null>, not recommended for normal use).

 The default, if I<--log> is not specified on the command line, is to
 send error messages to stderr, unless nbdkit forks into the background
diff --git a/docs/nbdkit.pod b/docs/nbdkit.pod
index 094cfca..f262fa0 100644
--- a/docs/nbdkit.pod
+++ b/docs/nbdkit.pod
@@ -250,8 +250,11 @@ interfaces.  See also I<-p>.

 =item B<--log=syslog>

-Send error messages to either standard error (I<--log=stderr>) or to
-the system log (I<--log=syslog>).
+=item B<--log=null>
+
+Send error messages to standard error (I<--log=stderr>), or to the
+system log (I<--log=syslog>), or discard them completely
+(I<--log=null>, not recommended for normal use).

 The default is to send error messages to stderr, unless nbdkit
 forks into the background in which case they are sent to syslog.
diff --git a/server/internal.h b/server/internal.h
index 5e11e1a..eb46d9e 100644
--- a/server/internal.h
+++ b/server/internal.h
@@ -84,6 +84,7 @@ enum log_to {
                             case log to syslog */
   LOG_TO_STDERR,         /* --log=stderr forced on the command line */
   LOG_TO_SYSLOG,         /* --log=syslog forced on the command line */
+  LOG_TO_NULL,           /* --log=null forced on the command line */
 };

 extern struct debug_flag *debug_flags;
diff --git a/server/log.c b/server/log.c
index d909b8f..a801aa2 100644
--- a/server/log.c
+++ b/server/log.c
@@ -59,6 +59,9 @@ nbdkit_verror (const char *fs, va_list args)
   case LOG_TO_STDERR:
     log_stderr_verror (fs, args);
     break;
+  case LOG_TO_NULL:
+    /* nothing */
+    break;
   }
 }

diff --git a/server/main.c b/server/main.c
index 115fa98..3e2ac2f 100644
--- a/server/main.c
+++ b/server/main.c
@@ -274,8 +274,11 @@ main (int argc, char *argv[])
         log_to = LOG_TO_STDERR;
       else if (strcmp (optarg, "syslog") == 0)
         log_to = LOG_TO_SYSLOG;
+      else if (strcmp (optarg, "null") == 0)
+        log_to = LOG_TO_NULL;
       else {
-        fprintf (stderr, "%s: --log must be \"stderr\" or
\"syslog\"\n",
+        fprintf (stderr, "%s: "
+                 "--log must be \"stderr\", \"syslog\"
or \"null\"\n",
                  program_name);
         exit (EXIT_FAILURE);
       }
--
2.23.0