From a0568eca2bbdcc26f2137cdecf4ace3bd0763e63 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 21 Jan 2003 21:25:51 +0000 Subject: [PATCH] Allow optional verbose logging. --- tools/dmsetup.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/dmsetup.c b/tools/dmsetup.c index d938117cd..8c1199aed 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -30,6 +30,7 @@ enum { READ_ONLY = 0, MINOR_ARG, + VERBOSE_ARG, NUM_SWITCHES }; @@ -375,8 +376,8 @@ static int _deps(int argc, char **argv) typedef int (*command_fn) (int argc, char **argv); struct command { - char *name; - char *help; + const char *name; + const char *help; int min_args; int max_args; command_fn fn; @@ -422,12 +423,13 @@ static struct command *_find_command(const char *name) static int _process_switches(int *argc, char ***argv) { - int index; + int ind; int c; static struct option long_options[] = { {"read-only", 0, NULL, READ_ONLY}, {"minor", 1, NULL, MINOR_ARG}, + {"verbose", 1, NULL, VERBOSE_ARG}, {"", 0, NULL, 0} }; @@ -437,16 +439,20 @@ static int _process_switches(int *argc, char ***argv) memset(&_switches, 0, sizeof(_switches)); memset(&_values, 0, sizeof(_values)); - while ((c = getopt_long(*argc, *argv, "m:r", - long_options, &index)) != -1) { - if (c == 'r' || index == READ_ONLY) + while ((c = getopt_long(*argc, *argv, "m:rv", + long_options, &ind)) != -1) { + if (c == 'r' || ind == READ_ONLY) _switches[READ_ONLY]++; - if (c == 'm' || index == MINOR_ARG) { + if (c == 'm' || ind == MINOR_ARG) { _switches[MINOR_ARG]++; _values[MINOR_ARG] = atoi(optarg); } + if (c == 'v' || ind == VERBOSE_ARG) + _switches[VERBOSE_ARG]++; } + dm_log_init_verbose(_switches[VERBOSE_ARG]); + *argv += optind; *argc -= optind; return 1;