Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
server: Warn instead of error if a -D (debug) flag is not used.
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).
  • Loading branch information
rwmjones committed Dec 12, 2019
1 parent f5a1ff7 commit cb910a6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
16 changes: 7 additions & 9 deletions server/debug-flags.c
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
22 changes: 17 additions & 5 deletions tests/test-debug-flags.sh
Expand Up @@ -56,19 +56,31 @@ check_error ()
fi
}

check_warning ()
{
cat debug-flags.out
if ! grep -sq "warning.*$1" debug-flags.out; then
echo "$0: expected warning message not present in above output: '$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
Expand Down

0 comments on commit cb910a6

Please sign in to comment.