From d87d7a826f352daafcb64d96d79f6a0592e70839 Mon Sep 17 00:00:00 2001 From: Alex Young Date: Fri, 1 Jun 2012 16:58:32 +0100 Subject: [PATCH] Rename the 'debug' cli option 'verbose' and switch default-deny from 'D' to 'd' --- src/flexnbd.c | 10 ++++---- src/options.h | 70 ++++++++++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/flexnbd.c b/src/flexnbd.c index 8580fde..3c51a8d 100644 --- a/src/flexnbd.c +++ b/src/flexnbd.c @@ -186,9 +186,9 @@ void read_serve_param( int c, char **ip_addr, char **ip_port, char **file, char case 's': *sock = optarg; break; - case 'd': + case 'v': set_debug(1); - case 'D': + case 'd': *default_deny = 1; break; default: @@ -217,7 +217,7 @@ void read_readwrite_param( int c, char **ip_addr, char **ip_port, char **from, c case 'S': *size = optarg; break; - case 'd': + case 'v': set_debug(1); break; default: @@ -236,7 +236,7 @@ void read_sock_param( int c, char **sock, char *help_text ) case 's': *sock = optarg; break; - case 'd': + case 'v': set_debug(1); break; default: @@ -266,7 +266,7 @@ void read_mirror_param( int c, char **sock, char **ip_addr, char **ip_port ) case 'p': *ip_port = optarg; break; - case 'd': + case 'v': set_debug(1); break; default: diff --git a/src/options.h b/src/options.h index df3df26..5637fea 100644 --- a/src/options.h +++ b/src/options.h @@ -1,3 +1,5 @@ +#define OPTIONS_H + #define GETOPT_ARG(x,s) {(x), 1, 0, (s)} #define GETOPT_FLAG(x,v) {(x), 0, 0, (v)} @@ -26,7 +28,7 @@ #define IS_CMD(x,c) (strncmp((x),(c),(LEN_CMD_MAX)) == 0) #define GETOPT_HELP GETOPT_FLAG( OPT_HELP, 'h' ) -#define GETOPT_DENY GETOPT_FLAG( OPT_DENY, 'D' ) +#define GETOPT_DENY GETOPT_FLAG( OPT_DENY, 'd' ) #define GETOPT_ADDR GETOPT_ARG( OPT_ADDR, 'l' ) #define GETOPT_PORT GETOPT_ARG( OPT_PORT, 'p' ) @@ -35,40 +37,44 @@ #define GETOPT_FROM GETOPT_ARG( OPT_FROM, 'F' ) #define GETOPT_SIZE GETOPT_ARG( OPT_SIZE, 'S' ) +#define HELP_LINE "\t--" OPT_HELP ",-h\t\tThis text.\n" + + #ifdef DEBUG -# define OPT_DEBUG "debug" -# define GETOPT_DEBUG GETOPT_FLAG( OPT_DEBUG, 'd' ) -# define SOPT_DEBUG "d" -# define DEBUG_LINE \ - "\t--" OPT_DEBUG ",-d\tOutput debug information.\n" +# define OPT_VERBOSE "verbose" +# define SOPT_VERBOSE "v" +# define GETOPT_VERBOSE GETOPT_FLAG( OPT_VERBOSE, 'v' ) +# define VERBOSE_LINE \ + "\t--" OPT_VERBOSE ",-" SOPT_VERBOSE "\t\tOutput debug information.\n" #else -# define GETOPT_DEBUG {0} -# define DEBUG_LINE "" -# define SOPT_DEBUG "" +# define GETOPT_VERBOSE {0} +# define VERBOSE_LINE "" +# define SOPT_VERBOSE "" #endif + static struct option serve_options[] = { GETOPT_HELP, GETOPT_ADDR, GETOPT_PORT, GETOPT_FILE, GETOPT_SOCK, - GETOPT_DEBUG, GETOPT_DENY, + GETOPT_VERBOSE, {0} }; -static char serve_short_options[] = "Dhl:p:f:s:" SOPT_DEBUG; +static char serve_short_options[] = "hl:p:f:s:d" SOPT_VERBOSE; static char serve_help_text[] = "Usage: flexnbd " CMD_SERVE " [*]\n\n" "Serve FILE from ADDR:PORT, with an optional control socket at SOCK.\n\n" - "\t--" OPT_HELP ",-h\tThis text.\n" + HELP_LINE "\t--" OPT_ADDR ",-l \tThe address to serve on.\n" "\t--" OPT_PORT ",-p \tThe port to serve on.\n" "\t--" OPT_FILE ",-f \tThe file to serve.\n" - "\t--" OPT_DENY ",-D\tDeny connections by default unless in ACL\n" + "\t--" OPT_DENY ",-d\tDeny connections by default unless in ACL\n" "\t--" OPT_SOCK ",-s \tPath to the control socket to open.\n" - DEBUG_LINE; + VERBOSE_LINE; static struct option read_options[] = { GETOPT_HELP, @@ -76,19 +82,19 @@ static struct option read_options[] = { GETOPT_PORT, GETOPT_FROM, GETOPT_SIZE, - GETOPT_DEBUG, + GETOPT_VERBOSE, {0} }; -static char read_short_options[] = "hl:p:F:S:" SOPT_DEBUG; +static char read_short_options[] = "hl:p:F:S:" SOPT_VERBOSE; static char read_help_text[] = "Usage: flexnbd " CMD_READ " \n\n" "Read SIZE bytes from a server at ADDR:PORT to stdout, starting at OFFSET.\n\n" - "\t--" OPT_HELP ",-h\tThis text.\n" + HELP_LINE "\t--" OPT_ADDR ",-l \tThe address to read from.\n" "\t--" OPT_PORT ",-p \tThe port to read from.\n" "\t--" OPT_FROM ",-F \tByte offset to read from.\n" "\t--" OPT_SIZE ",-S \tBytes to read.\n" - DEBUG_LINE; + VERBOSE_LINE; static struct option *write_options = read_options; @@ -96,59 +102,59 @@ static char *write_short_options = read_short_options; static char write_help_text[] = "Usage: flexnbd " CMD_WRITE" \n\n" "Write SIZE bytes from stdin to a server at ADDR:PORT, starting at OFFSET.\n\n" - "\t--" OPT_HELP ",-h\tThis text.\n" + HELP_LINE "\t--" OPT_ADDR ",-l \tThe address to write to.\n" "\t--" OPT_PORT ",-p \tThe port to write to.\n" "\t--" OPT_FROM ",-F \tByte offset to write from.\n" "\t--" OPT_SIZE ",-S \tBytes to write.\n" - DEBUG_LINE; + VERBOSE_LINE; struct option acl_options[] = { GETOPT_HELP, GETOPT_SOCK, - GETOPT_DEBUG, + GETOPT_VERBOSE, {0} }; -static char acl_short_options[] = "hs:" SOPT_DEBUG; +static char acl_short_options[] = "hs:" SOPT_VERBOSE; static char acl_help_text[] = "Usage: flexnbd " CMD_ACL " [+]\n\n" "Set the access control list for a server with control socket SOCK.\n\n" - "\t--" OPT_HELP ",-h\tThis text.\n" + HELP_LINE "\t--" OPT_SOCK ",-s \tPath to the control socket.\n" - DEBUG_LINE; + VERBOSE_LINE; struct option mirror_options[] = { GETOPT_HELP, GETOPT_SOCK, GETOPT_ADDR, GETOPT_PORT, - GETOPT_DEBUG, + GETOPT_VERBOSE, {0} }; -static char mirror_short_options[] = "hs:l:p:" SOPT_DEBUG; +static char mirror_short_options[] = "hs:l:p:" SOPT_VERBOSE; static char mirror_help_text[] = "Usage: flexnbd " CMD_MIRROR " \n\n" "Start mirroring from the server with control socket SOCK to one at ADDR:PORT.\n\n" - "\t--" OPT_HELP ",-h\tThis text.\n" + HELP_LINE "\t--" OPT_SOCK ",-s \tPath to the control socket.\n" "\t--" OPT_ADDR ",-l \tThe address to mirror to.\n" "\t--" OPT_PORT ",-p \tThe port to mirror to.\n" - DEBUG_LINE; + VERBOSE_LINE; struct option status_options[] = { GETOPT_HELP, GETOPT_SOCK, - GETOPT_DEBUG, + GETOPT_VERBOSE, {0} }; -static char status_short_options[] = "hs:" SOPT_DEBUG; +static char status_short_options[] = "hs:" SOPT_VERBOSE; static char status_help_text[] = "Usage: flexnbd " CMD_STATUS " \n\n" "Get the status for a server with control socket SOCK.\n\n" - "\t--" OPT_HELP ",-h\tThis text.\n" + HELP_LINE "\t--" OPT_SOCK ",-s \tPath to the control socket.\n" - DEBUG_LINE; + VERBOSE_LINE; static char help_help_text[] = "Usage: flexnbd [cmd options]\n\n"