[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sanlock-devel
Subject:    [PATCH] reset: Improve error message when command is missing
From:       Nir Soffer <nsoffer () redhat ! com>
Date:       2014-08-18 22:56:28
Message-ID: 1408402588-19332-1-git-send-email-nsoffer () redhat ! com
[Download RAW message or body]

If some options were specified without any positional arguments, this
confusing error message was displayed:

    $ sanlk-reset -i 42
    lockspace_name is required

Now more correct message is displayed:

    command is required

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
---
 reset/sanlk_reset.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/reset/sanlk_reset.c b/reset/sanlk_reset.c
index 56cada3..267fe8e 100644
--- a/reset/sanlk_reset.c
+++ b/reset/sanlk_reset.c
@@ -553,12 +553,18 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	if (optind >= argc) {
+		fprintf(stderr, "command is required\n");
+		exit(2);
+	}
+
+	cmd = argv[optind];
+	optind++;
+
 	ls_count = 0;
 
 	for (i = optind; i < argc; i++) {
-		if (i == optind) {
-			cmd = argv[i];
-		} else if (ls_count == MAX_LS) {
+		if (ls_count == MAX_LS) {
 			fprintf(stderr, "ignore lockspace_name %s\n", argv[i]);
 		} else {
 			ls_names[ls_count] = argv[i];
-- 
1.8.3.1

_______________________________________________
sanlock-devel mailing list
sanlock-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/sanlock-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic