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

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