Commit 7df09064a4 ("server: Explain what to do if plugin/filter
loading fails") added a useful tip for how to install the plugin or
filter package from common Linux distros. However it was not very
selective and might suggest impossible package names. Fix this by
only printing the tip if it's a plausible package name.
Added { ... } for clarity in the code.
Updates: commit 7df09064a4e993a74d2d4421b70b272e7121c929
---
server/main.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/server/main.c b/server/main.c
index 7c9dc27626..f3cb604cbd 100644
--- a/server/main.c
+++ b/server/main.c
@@ -63,6 +63,7 @@
#include <dlfcn.h>
+#include "ascii-ctype.h"
#include "ascii-string.h"
#include "exit-with-parent.h"
#include "nbd-protocol.h"
@@ -982,6 +983,27 @@ make_uri (void)
return r;
}
+/* Is it the name of a possible nbdkit-<name>-plugin or
+ * nbdkit-<name>-filter that might be a Fedora or Debian package?
+ * This matches more than all possible names, but it's just a guide
+ * for help output.
+ */
+static int
+is_possible_package_name (const char *name)
+{
+ size_t i, n = strlen (name);
+
+ for (i = 0; i < n; ++i) {
+ char c = name[i];
+ if (ascii_isalnum (c))
+ continue;
+ if (c == '-' || c == '_' || c == '.')
+ continue;
+ return 0;
+ }
+ return 1;
+}
+
/* Common error handling for dlopen failures in open_plugin_so or
* open_filter_so.
*
@@ -1001,13 +1023,14 @@ failed_to_load_error (const char *what,
{
fprintf (stderr, "%s: error: cannot open %s '%s': %s\n",
program_name, what, filename, dlerror ());
- if (short_name)
+ if (short_name && is_possible_package_name (short_name)) {
fprintf (stderr,
"\n"
"To add this functionality you might need to install a
separate\n"
"%s package such as nbdkit-%s-%s (Fedora) or\n"
"nbdkit-%s-%s (Debian).\n",
what, short_name, what, what, short_name);
+ }
fprintf (stderr,
"\n"
"Use '%s --help' or "
--
2.44.0