This was a hard error before, but that's not very useful. It's best
to ignore -D options that we don't understand (but we still warn about
them).
---
server/debug-flags.c | 16 +++++++---------
tests/test-debug-flags.sh | 22 +++++++++++++++++-----
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/server/debug-flags.c b/server/debug-flags.c
index c73e1b9..53adc21 100644
--- a/server/debug-flags.c
+++ b/server/debug-flags.c
@@ -59,17 +59,17 @@ apply_debug_flags (void *dl, const char *name)
/* Find the symbol. */
sym = dlsym (dl, var);
- if (sym == NULL) {
+ if (sym) {
+ /* Set the flag. */
+ *sym = flag->value;
+ }
+ else {
fprintf (stderr,
- "%s: -D %s.%s: %s does not contain a "
+ "%s: warning: -D %s.%s: %s does not contain a "
"global variable called %s\n",
program_name, name, flag->flag, name, var);
- exit (EXIT_FAILURE);
}
- /* Set the flag. */
- *sym = flag->value;
-
/* Mark this flag as used. */
flag->used = true;
}
@@ -82,11 +82,9 @@ free_debug_flags (void)
while (debug_flags != NULL) {
struct debug_flag *next = debug_flags->next;
- if (!debug_flags->used) {
+ if (!debug_flags->used)
fprintf (stderr, "%s: warning: debug flag -D %s.%s was not used\n",
program_name, debug_flags->name, debug_flags->flag);
- exit (EXIT_FAILURE);
- }
free (debug_flags->name);
free (debug_flags->flag);
free (debug_flags);
diff --git a/tests/test-debug-flags.sh b/tests/test-debug-flags.sh
index 88f5a22..9dc0a94 100755
--- a/tests/test-debug-flags.sh
+++ b/tests/test-debug-flags.sh
@@ -56,19 +56,31 @@ check_error ()
fi
}
+check_warning ()
+{
+ cat debug-flags.out
+ if ! grep -sq "warning.*$1" debug-flags.out; then
+ echo "expected warning message containing: $1"
+ exit 1
+ fi
+}
+
# This is expected to fail because we didn't set the file= parameter,
# but it should not fail because of the debug flag.
nbdkit -f -D example2.extra=1 example2 2>debug-flags.out && expected_failure
check_error "you must supply the file="
-# This should fail because the -D flag refers to an unknown global in
-# a known plugin.
+# This should fail because we didn't set the file= parameter, but it
+# should also print a warning about the unknown -D flag.
nbdkit -f -D example2.unknown=1 example2 2>debug-flags.out &&
expected_failure
-check_error "does not contain a global variable called example2_debug_unknown"
+check_error "you must supply the file="
+check_warning "does not contain a global variable called
example2_debug_unknown"
-# This should fail because the -D flag is unused.
+# This should fail because we didn't set the file= parameter, but it
+# should also print a warning because the -D flag is unused.
nbdkit -f -D example1.foo=1 example2 2>debug-flags.out && expected_failure
-check_error "was not used"
+check_error "you must supply the file="
+check_warning "was not used"
# These should fail because the -D flag has a bad format.
nbdkit -f -D = example2 2>debug-flags.out && expected_failure
--
2.23.0