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