From 653e35bca873414964c9cde0bd98bca3e0bf6692 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Tue, 6 Jul 2010 05:57:20 +0200 Subject: debug: properly parse debug levels Signed-off-by: Patrick McHardy --- src/main.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 21606ee7..8c970b52 100644 --- a/src/main.c +++ b/src/main.c @@ -102,12 +102,40 @@ static void show_help(const char *name) " Internet services, user IDs and group IDs numerically.\n" " -i/--includepath Add to the paths searched for include files.\n" #ifdef DEBUG -" --debug Specify debugging level\n" +" --debug Specify debugging level (scanner, parser, eval, netlink, all)\n" #endif "\n", name); } +#ifdef DEBUG +static const struct { + const char *name; + enum debug_level level; +} debug_param[] = { + { + .name = "scanner", + .level = DEBUG_SCANNER, + }, + { + .name = "parser", + .level = DEBUG_PARSER, + }, + { + .name = "eval", + .level = DEBUG_EVALUATION, + }, + { + .name = "netlink", + .level = DEBUG_NETLINK, + }, + { + .name = "all", + .level = ~0, + }, +}; +#endif + static const struct input_descriptor indesc_cmdline = { .type = INDESC_BUFFER, .name = "", @@ -158,7 +186,31 @@ int main(int argc, char * const *argv) break; #ifdef DEBUG case OPT_DEBUG: - debug_level |= DEBUG_NETLINK; + for (;;) { + unsigned int i; + char *end; + + end = strchr(optarg, ','); + if (end) + *end = '\0'; + + for (i = 0; i < array_size(debug_param); i++) { + if (strcmp(debug_param[i].name, optarg)) + continue; + debug_level |= debug_param[i].level; + break; + } + + if (i == array_size(debug_param)) { + fprintf(stderr, "invalid debug parameter `%s'\n", + optarg); + exit(NFT_EXIT_FAILURE); + } + + if (end == NULL) + break; + optarg = end + 1; + } break; #endif case OPT_INVALID: -- cgit v1.2.3