From ab517513435f19e63826cad073eb079705251b84 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Wed, 2 Dec 2020 07:28:47 +0100 Subject: [CLIENT] print help and version number correctly This change prevents the dnbd3-client to print the help text twice if the help parameter is submitted. In addition to that, correct exit codes are set after the help text is printed and the program terminates. --- src/client/client.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/client/client.c b/src/client/client.c index 261edb7..cb13682 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -44,9 +44,8 @@ #define TMP_STR_LEN 100 static int openDevices[MAX_DEVS]; -static const char *optString = "f:h:i:r:d:a:cs:SA:R:HV?k"; +static const char *optString = "h:i:r:d:a:cs:SA:R:HV?k"; static const struct option longOpts[] = { - { "file", required_argument, NULL, 'f' }, { "host", required_argument, NULL, 'h' }, { "image", required_argument, NULL, 'i' }, { "rid", required_argument, NULL, 'r' }, @@ -253,8 +252,6 @@ int main(int argc, char *argv[]) while ( opt != -1 ) { switch ( opt ) { - case 'f': - break; case 'h': msg.hosts_num = dnbd3_get_resolved_hosts(optarg, msg.hosts, MAX_HOSTS_PER_IOCTL); if (!msg.hosts_num) @@ -297,12 +294,15 @@ int main(int argc, char *argv[]) break; case 'H': dnbd3_print_help( argv[0] ); + exit( EXIT_SUCCESS ); break; case 'V': - dnbd3_print_version(); + dnbd3_print_version( argv[0] ); + exit( EXIT_SUCCESS ); break; case '?': dnbd3_print_help( argv[0] ); + exit( EXIT_SUCCESS ); break; case 'D': dnbd3_client_daemon(); @@ -706,11 +706,9 @@ static int dnbd3_daemon_send(int argc, char **argv) static void dnbd3_print_help(char *argv_0) { - printf( "Version: %s\n\n", DNBD3_VERSION ); printf( "Usage: %s\n", argv_0 ); printf( " -h -i [-r ] -d [-a ] || -c -d \n\n" ); printf( "Start the DNBD3 client.\n\n" ); - //printf("-f or --file \t\t Configuration file (default /etc/dnbd3-client.conf)\n"); printf( "-h or --host \t\t List of space separated hosts to use.\n" ); printf( "-i or --image \t\t Image name of exported image.\n" ); printf( "-r or --rid \t\t Release-ID of exported image (default 0, latest).\n" ); @@ -732,5 +730,4 @@ static void dnbd3_print_help(char *argv_0) void dnbd3_print_version() { printf( "dnbd3-client version: %s\n", DNBD3_VERSION ); - exit( EXIT_SUCCESS ); } -- cgit v1.2.3-55-g7522