[PATCH 2/3] str_to_val macro in tgtd.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/usr/tgtd.c b/usr/tgtd.c
index 0d6f11f..8bfc555 100644
--- a/usr/tgtd.c
+++ b/usr/tgtd.c
@@ -82,6 +82,15 @@ Target framework daemon, version %s\n\
 	exit(status);
 }
 
+static void bad_optarg(int ret, int ch, char *optarg)
+{
+	if (ret == ERANGE)
+		fprintf(stderr, "-%c argument value '%s' out of range\n", ch, optarg);
+	else
+		fprintf(stderr, "-%c argument value '%s' invalid\n", ch, optarg);
+	usage(ret);
+}
+
 static void version(void)
 {
 	printf("%s\n", TGT_VERSION);
@@ -502,13 +511,19 @@ int main(int argc, char **argv)
 			is_daemon = 0;
 			break;
 		case 'C':
-			control_port = atoi(optarg);
+			ret = str_to_val(optarg, control_port, 0, USHRT_MAX);
+			if (ret)
+				bad_optarg(ret, ch, optarg);
 			break;
 		case 't':
-			nr_iothreads = atoi(optarg);
+			ret = str_to_val(optarg, nr_iothreads, 0, USHRT_MAX);
+			if (ret)
+				bad_optarg(ret, ch, optarg);
 			break;
 		case 'd':
-			is_debug = atoi(optarg);
+			ret = str_to_val(optarg, is_debug, 0, 1);
+			if (ret)
+				bad_optarg(ret, ch, optarg);
 			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


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux