Blame SOURCES/0002-server-Allow-D-debug-flags-to-contain-dots-for-names.patch

538efe
From e5d2d44fff9214725506cbc84e7b3c035ec0eae9 Mon Sep 17 00:00:00 2001
538efe
From: "Richard W.M. Jones" <rjones@redhat.com>
538efe
Date: Thu, 12 Dec 2019 11:06:36 +0000
538efe
Subject: [PATCH 02/19] server: Allow -D debug flags to contain dots for
538efe
 namespacing.
538efe
538efe
This is just a convenience.  Either of:
538efe
538efe
 -D myplugin.foo_bar=1
538efe
 -D myplugin.foo.bar=1
538efe
538efe
correspond to the same plugin variable "myplugin_debug_foo_bar".
538efe
538efe
(cherry picked from commit a895fa84aaa50f52af68319523020046394c789f)
538efe
---
538efe
 docs/nbdkit-plugin.pod |  8 ++++++++
538efe
 server/debug-flags.c   | 10 +++++++++-
538efe
 2 files changed, 17 insertions(+), 1 deletion(-)
538efe
538efe
diff --git a/docs/nbdkit-plugin.pod b/docs/nbdkit-plugin.pod
538efe
index b69cb825..879ddf09 100644
538efe
--- a/docs/nbdkit-plugin.pod
538efe
+++ b/docs/nbdkit-plugin.pod
538efe
@@ -1298,6 +1298,14 @@ You should only use this feature for debug settings.  For general
538efe
 settings use ordinary plugin parameters.  Debug Flags can only be C
538efe
 ints.  They are not supported by non-C language plugins.
538efe
 
538efe
+For convenience C<'.'> characters are replaced with C<'_'> characters
538efe
+in the variable name, so both of these parameters:
538efe
+
538efe
+ -D myplugin.foo_bar=1
538efe
+ -D myplugin.foo.bar=1
538efe
+
538efe
+correspond to the plugin variable C<myplugin_debug_foo_bar>.
538efe
+
538efe
 =head1 INSTALLING THE PLUGIN
538efe
 
538efe
 The plugin is a C<*.so> file and possibly a manual page.  You can of
538efe
diff --git a/server/debug-flags.c b/server/debug-flags.c
538efe
index 9344d85c..5e06f5ed 100644
538efe
--- a/server/debug-flags.c
538efe
+++ b/server/debug-flags.c
538efe
@@ -56,12 +56,20 @@ static char *
538efe
 symbol_of_debug_flag (const char *name, const char *flag)
538efe
 {
538efe
   char *var;
538efe
+  size_t i;
538efe
+  int len;
538efe
 
538efe
-  if (asprintf (&var, "%s_debug_%s", name, flag) == -1) {
538efe
+  if ((len = asprintf (&var, "%s_debug_%s", name, flag)) == -1) {
538efe
     perror ("asprintf");
538efe
     exit (EXIT_FAILURE);
538efe
   }
538efe
 
538efe
+  /* If there are any '.'s remaining in the name, convert them to '_'. */
538efe
+  for (i = 0; i < (size_t) len; ++i) {
538efe
+    if (var[i] == '.')
538efe
+      var[i] = '_';
538efe
+  }
538efe
+
538efe
   return var;                   /* caller frees */
538efe
 }
538efe
 
538efe
-- 
538efe
2.18.2
538efe