Blame SOURCES/0015-getcifsacl-Improve-help-usage-and-add-h-option.patch

5eee7b
From efff67c46ffeb0de69259e6c5cb9c4f6b82a860a Mon Sep 17 00:00:00 2001
5eee7b
From: Kenneth D'souza <kdsouza@redhat.com>
5eee7b
Date: Thu, 21 Feb 2019 10:39:25 +0530
5eee7b
Subject: [PATCH 15/36] getcifsacl: Improve help usage and add -h option.
5eee7b
5eee7b
Call getcifsacl_usage only for -h and default case.
5eee7b
For others error out with appropriate message.
5eee7b
5eee7b
Signed-off-by: Kenneth D'souza <kdsouza@redhat.com>
5eee7b
(cherry picked from commit ea9b99cf17a949edbe368301881a353d27018847)
5eee7b
Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
5eee7b
---
5eee7b
 getcifsacl.c | 27 ++++++++++++++++++---------
5eee7b
 1 file changed, 18 insertions(+), 9 deletions(-)
5eee7b
5eee7b
diff --git a/getcifsacl.c b/getcifsacl.c
5eee7b
index aaf15fa..fc78881 100644
5eee7b
--- a/getcifsacl.c
5eee7b
+++ b/getcifsacl.c
5eee7b
@@ -40,6 +40,7 @@
5eee7b
 
5eee7b
 static void *plugin_handle;
5eee7b
 static bool plugin_loaded;
5eee7b
+static char *execname;
5eee7b
 
5eee7b
 static void
5eee7b
 print_each_ace_mask(uint32_t mask)
5eee7b
@@ -331,6 +332,8 @@ getcifsacl_usage(const char *prog)
5eee7b
 		prog);
5eee7b
 	fprintf(stderr, "Usage: %s [option] <file_name>\n", prog);
5eee7b
 	fprintf(stderr, "Valid options:\n");
5eee7b
+	fprintf(stderr, "\t-h	Display this help text\n");
5eee7b
+	fprintf(stderr, "\n");
5eee7b
 	fprintf(stderr, "\t-v	Version of the program\n");
5eee7b
 	fprintf(stderr, "\n");
5eee7b
 	fprintf(stderr, "\t-r	Display raw values of the ACE fields\n");
5eee7b
@@ -345,8 +348,15 @@ main(const int argc, char *const argv[])
5eee7b
 	ssize_t attrlen;
5eee7b
 	size_t bufsize = BUFSIZE;
5eee7b
 	char *filename, *attrval;
5eee7b
+	execname = basename(argv[0]);
5eee7b
+
5eee7b
+	if (argc < 2) {
5eee7b
+		fprintf(stderr, "%s: you must specify a filename.\n", execname);
5eee7b
+		printf("Try `getcifsacl -h' for more information.\n");
5eee7b
+		goto out;
5eee7b
+	}
5eee7b
 
5eee7b
-	while ((c = getopt_long(argc, argv, "r:v", NULL, NULL)) != -1) {
5eee7b
+	while ((c = getopt_long(argc, argv, "rhv", NULL, NULL)) != -1) {
5eee7b
 		switch (c) {
5eee7b
 		case 'v':
5eee7b
 			printf("Version: %s\n", VERSION);
5eee7b
@@ -355,18 +365,17 @@ main(const int argc, char *const argv[])
5eee7b
 			raw = true;
5eee7b
 			break;
5eee7b
 		default:
5eee7b
-			break;
5eee7b
+			getcifsacl_usage(execname);
5eee7b
+			goto out;
5eee7b
 		}
5eee7b
 	}
5eee7b
 
5eee7b
-	if (raw && argc == 3)
5eee7b
-		filename = argv[2];
5eee7b
-	else if (argc == 2)
5eee7b
-		filename = argv[1];
5eee7b
-	else {
5eee7b
-		getcifsacl_usage(basename(argv[0]));
5eee7b
+	if (optind >= argc) {
5eee7b
+		printf("you must specify a filename after options.\n");
5eee7b
+		printf("Usage: getcifsacl [option] <file_name>\n");
5eee7b
 		goto out;
5eee7b
-	}
5eee7b
+	} else
5eee7b
+		filename = argv[optind];
5eee7b
 
5eee7b
 	if (!raw && !plugin_loaded) {
5eee7b
 		ret = init_plugin(&plugin_handle);
5eee7b
-- 
5eee7b
1.8.3.1
5eee7b