diff options
author | Patrick McHardy <kaber@trash.net> | 2010-07-06 05:57:20 +0200 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2010-07-06 05:57:20 +0200 |
commit | 653e35bca873414964c9cde0bd98bca3e0bf6692 (patch) | |
tree | ff6e17befb8f45d817a67329742339301c1ce65a /src/main.c | |
parent | 3a3cd6215d49cb02841b2b20cf8fa9b91de3a831 (diff) |
debug: properly parse debug levels
Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 56 |
1 files changed, 54 insertions, 2 deletions
@@ -102,12 +102,40 @@ static void show_help(const char *name) " Internet services, user IDs and group IDs numerically.\n" " -i/--includepath <directory> Add <directory> to the paths searched for include files.\n" #ifdef DEBUG -" --debug <level> Specify debugging level\n" +" --debug <level [,level...]> 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 = "<cmdline>", @@ -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: |