[Libguestfs] [PATCH nbdkit 6/7] server: Allow -D debug flags to contain dots for namespacing.

Richard W.M. Jones rjones at redhat.com
Thu Dec 12 12:02:11 UTC 2019


This is just a convenience.  Either of:

 -D myplugin.foo_bar=1
 -D myplugin.foo.bar=1

correspond to the same plugin variable "myplugin_debug_foo_bar".
---
 docs/nbdkit-plugin.pod |  8 ++++++++
 server/debug-flags.c   | 10 +++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/docs/nbdkit-plugin.pod b/docs/nbdkit-plugin.pod
index e37fea0..0873cf6 100644
--- a/docs/nbdkit-plugin.pod
+++ b/docs/nbdkit-plugin.pod
@@ -1329,6 +1329,14 @@ You should only use this feature for debug settings.  For general
 settings use ordinary plugin parameters.  Debug Flags can only be C
 ints.  They are not supported by non-C language plugins.
 
+For convenience C<'.'> characters are replaced with C<'_'> characters
+in the variable name, so both of these parameters:
+
+ -D myplugin.foo_bar=1
+ -D myplugin.foo.bar=1
+
+correspond to the plugin variable C<myplugin_debug_foo_bar>.
+
 =head1 INSTALLING THE PLUGIN
 
 The plugin is a C<*.so> file and possibly a manual page.  You can of
diff --git a/server/debug-flags.c b/server/debug-flags.c
index 497c2b4..d878e96 100644
--- a/server/debug-flags.c
+++ b/server/debug-flags.c
@@ -47,12 +47,20 @@ static char *
 name_of_debug_flag (const char *name, const char *flag)
 {
   char *var;
+  size_t i;
+  int len;
 
-  if (asprintf (&var, "%s_debug_%s", name, flag) == -1) {
+  if ((len = asprintf (&var, "%s_debug_%s", name, flag)) == -1) {
     perror ("asprintf");
     exit (EXIT_FAILURE);
   }
 
+  /* If there are any '.'s remaining in the name, convert them to '_'. */
+  for (i = 0; i < (size_t) len; ++i) {
+    if (var[i] == '.')
+      var[i] = '_';
+  }
+
   return var;                   /* caller frees */
 }
 
-- 
2.23.0




More information about the Libguestfs mailing list