- Subject: [PATCH 2/3] str_to_val macro in tgtd.c
- From: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx>
- Date: Thu, 17 Nov 2011 18:32:54 +0200
- User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110920 SUSE/3.1.15 Thunderbird/3.1.15 ThunderBrowse/3.8
Uses new macro str_to val() in tgtd.c to check command line arguments
validity.
Signed-off-by: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx>
---
usr/tgtd.c | 32 +++++++++++++++++++++++++++++---
1 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/usr/tgtd.c b/usr/tgtd.c
index 0d6f11f..e79ac97 100644
--- a/usr/tgtd.c
+++ b/usr/tgtd.c
@@ -63,6 +63,23 @@ static struct option const long_options[] =
static char *short_options = "fC:d:t:Vh";
+static char *opt_long_name(int val)
+{
+ int i;
+ static char opt_name[64];
+
+ for (i = 0; i < ARRAY_SIZE(long_options); i++) {
+ if (long_options[i].val == val) {
+ snprintf(opt_name, sizeof(opt_name)-1,
+ "option --%s (-%c)",
+ long_options[i].name, val);
+ return opt_name;
+ }
+ }
+ sprintf(opt_name, "option -%c", val);
+ return opt_name;
+}
+
static void usage(int status)
{
if (status)
@@ -502,13 +519,22 @@ int main(int argc, char **argv)
is_daemon = 0;
break;
case 'C':
- control_port = atoi(optarg);
+ ret = str_to_val(optarg, opt_long_name(ch),
+ control_port, 0, USHRT_MAX);
+ if (ret)
+ exit(ret);
break;
case 't':
- nr_iothreads = atoi(optarg);
+ ret = str_to_val(optarg, opt_long_name(ch),
+ nr_iothreads, 0, USHRT_MAX);
+ if (ret)
+ exit(ret);
break;
case 'd':
- is_debug = atoi(optarg);
+ ret = str_to_val(optarg, opt_long_name(ch),
+ is_debug, 0, 1);
+ if (ret)
+ exit(ret);
break;
case 'V':
version();
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
[Linux SCSI]
[Linux RAID]
[Linux Clusters]
[Linux USB Devel]
[Video for Linux]
[Linux Audio Users]
[Photo]
[Yosemite News]
[Yosemite Photos]
[Free Online Dating]
[Linux Kernel]
[XFree86]
[Video Devices]