convert iscsi-dd to use getopt_long()

This commit is contained in:
Ronnie Sahlberg
2013-04-21 10:02:05 -07:00
parent f5d25c0157
commit 1c5d132ed0
+25 -23
View File
@@ -20,7 +20,7 @@
#include <stdint.h> #include <stdint.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"
@@ -142,40 +142,42 @@ void fill_read_queue(struct client *client)
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
poptContext pc;
const char **extra_argv;
char *src_url = NULL; char *src_url = NULL;
char *dst_url = NULL; char *dst_url = NULL;
struct iscsi_url *iscsi_url; struct iscsi_url *iscsi_url;
struct scsi_task *task; struct scsi_task *task;
struct scsi_readcapacity10 *rc10; struct scsi_readcapacity10 *rc10;
int extra_argc = 0; int c;
int res;
struct pollfd pfd[2]; struct pollfd pfd[2];
struct client client; struct client client;
struct poptOption popt_options[] = { static struct option long_options[] = {
POPT_AUTOHELP {"dst", required_argument, NULL, 'd'},
{ "initiator-name", 'i', POPT_ARG_STRING, &initiator, 0, "Initiatorname to use", "iqn-name" }, {"src", required_argument, NULL, 's'},
{ "src", 0, POPT_ARG_STRING, &src_url, 0, "SRC lun", "iscsi url" }, {"initiator_name", required_argument, NULL, 'i'},
{ "dst", 0, POPT_ARG_STRING, &dst_url, 0, "DST lun", "iscsi url" }, {0, 0, 0, 0}
POPT_TABLEEND
}; };
int option_index;
pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_POSIXMEHARDER); while ((c = getopt_long(argc, argv, "d:s:i:", 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 'd':
exit(10); dst = optarg;
} break;
extra_argv = poptGetArgs(pc); case 's':
if (extra_argv) { src = optarg;
extra_argv++; break;
while (extra_argv[extra_argc]) { case 'i':
extra_argc++; initiator = optarg;
break;
default:
fprintf(stderr, "Unrecognized option '%c'\n\n", c);
print_help();
exit(0);
} }
} }
poptFreeContext(pc);
if (src_url == NULL) { if (src_url == NULL) {
fprintf(stderr, "You must specify source url\n"); fprintf(stderr, "You must specify source url\n");