ISCSI-READCAPACITY16 convert to getopt_long()

This commit is contained in:
Ronnie Sahlberg
2013-04-21 09:58:15 -07:00
parent c3886cf9c4
commit f5d25c0157

View File

@@ -22,7 +22,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
#include <poll.h> #include <poll.h>
#include <popt.h> #include <getopt.h>
#include "iscsi.h" #include "iscsi.h"
#include "scsi-lowlevel.h" #include "scsi-lowlevel.h"
@@ -56,40 +56,51 @@ void print_help(void)
fprintf(stderr, " \"ipv6-address\" [fce0::1]\n"); fprintf(stderr, " \"ipv6-address\" [fce0::1]\n");
} }
int main(int argc, const char *argv[]) int main(int argc, char *argv[])
{ {
poptContext pc;
struct iscsi_context *iscsi; struct iscsi_context *iscsi;
const char **extra_argv;
int extra_argc = 0;
const char *url = NULL; const char *url = NULL;
struct iscsi_url *iscsi_url = NULL; struct iscsi_url *iscsi_url = NULL;
int show_help = 0, show_usage = 0, debug = 0, size_only=0; int show_help = 0, show_usage = 0, debug = 0, size_only=0;
int res; int c;
struct scsi_task *task; struct scsi_task *task;
struct scsi_readcapacity16 *rc16; struct scsi_readcapacity16 *rc16;
struct poptOption popt_options[] = { static struct option long_options[] = {
{ "help", '?', POPT_ARG_NONE, &show_help, 0, "Show this help message", NULL }, {"help", no_argument, NULL, 'h'},
{ "usage", 0, POPT_ARG_NONE, &show_usage, 0, "Display brief usage message", NULL }, {"usage", no_argument, NULL, 'u'},
{ "initiator-name", 'i', POPT_ARG_STRING, &initiator, 0, "Initiatorname to use", "iqn-name" }, {"debug", no_argument, NULL, 'd'},
{ "size", 's', POPT_ARG_NONE, &size_only, 0, "Print target size only", NULL }, {"size", no_argument, NULL, 's'},
{ "debug", 'd', POPT_ARG_INT, &debug, 0, "Debugging level", "integer" }, {"initiator_name", required_argument, NULL, 'i'},
POPT_TABLEEND {"evpd", required_argument, NULL, 'e'},
{"pagecode", required_argument, NULL, 'c'},
{0, 0, 0, 0}
}; };
int option_index;
pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_POSIXMEHARDER); while ((c = getopt_long(argc, argv, "h?udi:s", long_options,
if ((res = poptGetNextOpt(pc)) < -1) { &option_index)) != -1) {
fprintf(stderr, "Failed to parse option : %s %s\n", switch (c) {
poptBadOption(pc, 0), poptStrerror(res)); case 'h':
exit(10); case '?':
} show_help = 1;
extra_argv = poptGetArgs(pc); break;
if (extra_argv) { case 'u':
url = strdup(*extra_argv); show_usage = 1;
extra_argv++; break;
while (extra_argv[extra_argc]) { case 's':
extra_argc++; size_only = 1;
break;
case 'd':
debug = 1;
break;
case 'i':
initiator = optarg;
break;
default:
fprintf(stderr, "Unrecognized option '%c'\n\n", c);
print_help();
exit(0);
} }
} }
@@ -103,8 +114,6 @@ int main(int argc, const char *argv[])
exit(0); exit(0);
} }
poptFreeContext(pc);
iscsi = iscsi_create_context(initiator); iscsi = iscsi_create_context(initiator);
if (iscsi == NULL) { if (iscsi == NULL) {
fprintf(stderr, "Failed to create context\n"); fprintf(stderr, "Failed to create context\n");
@@ -116,6 +125,7 @@ int main(int argc, const char *argv[])
iscsi_set_log_level(iscsi, debug); iscsi_set_log_level(iscsi, debug);
} }
url = strdup(argv[optind]);
if (url == NULL) { if (url == NULL) {
fprintf(stderr, "You must specify the URL\n"); fprintf(stderr, "You must specify the URL\n");
print_usage(); print_usage();