Blame SOURCES/0033-efivar-rework-usage.patch

d5c737
From 5f0b2b3460dfa826d75b95450bdc2903fa59e32e Mon Sep 17 00:00:00 2001
d5c737
From: Peter Jones <pjones@redhat.com>
d5c737
Date: Mon, 17 Jun 2019 14:45:39 -0400
d5c737
Subject: [PATCH 33/63] efivar: rework usage()
d5c737
d5c737
Signed-off-by: Peter Jones <pjones@redhat.com>
d5c737
---
d5c737
 src/efivar.c | 74 ++++++++++++++++++++++++++++------------------------
d5c737
 1 file changed, 40 insertions(+), 34 deletions(-)
d5c737
d5c737
diff --git a/src/efivar.c b/src/efivar.c
d5c737
index df075809db5..7f16ab15bab 100644
d5c737
--- a/src/efivar.c
d5c737
+++ b/src/efivar.c
d5c737
@@ -39,10 +39,11 @@ extern int optind, opterr, optopt;
d5c737
 
d5c737
 #include "efivar.h"
d5c737
 
d5c737
-#define ACTION_LIST		0x1
d5c737
-#define ACTION_PRINT		0x2
d5c737
-#define ACTION_APPEND		0x4
d5c737
-#define ACTION_LIST_GUIDS	0x8
d5c737
+#define ACTION_USAGE		0x00
d5c737
+#define ACTION_LIST		0x01
d5c737
+#define ACTION_PRINT		0x02
d5c737
+#define ACTION_APPEND		0x04
d5c737
+#define ACTION_LIST_GUIDS	0x08
d5c737
 #define ACTION_WRITE		0x10
d5c737
 #define ACTION_PRINT_DEC	0x20
d5c737
 
d5c737
@@ -326,7 +327,7 @@ validate_name(const char *name)
d5c737
 }
d5c737
 
d5c737
 static void
d5c737
-prepare_data(const char *filename, void **data, size_t *data_size)
d5c737
+prepare_data(const char *filename, uint8_t **data, size_t *data_size)
d5c737
 {
d5c737
 	int fd = -1;
d5c737
 	void *buf;
d5c737
@@ -365,25 +366,29 @@ err:
d5c737
 	exit(1);
d5c737
 }
d5c737
 
d5c737
-static void
d5c737
-usage(const char *progname)
d5c737
+static void __attribute__((__noreturn__))
d5c737
+usage(int ret)
d5c737
 {
d5c737
-	printf("Usage: %s [OPTION...]\n", basename(progname));
d5c737
-	printf("  -l, --list                        list current variables\n");
d5c737
-	printf("  -p, --print                       print variable specified by --name\n");
d5c737
-	printf("  -d, --print-decimal               print variable in decimal values specified\n");
d5c737
-	printf("                                    by --name\n");
d5c737
-	printf("  -n, --name=<guid-name>            variable to manipulate, in the form\n");
d5c737
-	printf("                                    8be4df61-93ca-11d2-aa0d-00e098032b8c-Boot0000\n");
d5c737
-	printf("  -a, --append                      append to variable specified by --name\n");
d5c737
-	printf("  -f, --fromfile=<file>             use data from <file>\n");
d5c737
-	printf("  -t, --attributes=<attributes>     attributes to use on append\n");
d5c737
-	printf("  -L, --list-guids                  show internal guid list\n");
d5c737
-	printf("  -w, --write                       write to variable specified by --name\n\n");
d5c737
-	printf("Help options:\n");
d5c737
-	printf("  -?, --help                        Show this help message\n");
d5c737
-	printf("      --usage                       Display brief usage message\n");
d5c737
-	return;
d5c737
+	FILE *out = ret == 0 ? stdout : stderr;
d5c737
+	fprintf(out,
d5c737
+		"Usage: %s [OPTION...]\n"
d5c737
+		"  -l, --list                        list current variables\n"
d5c737
+		"  -p, --print                       print variable specified by --name\n"
d5c737
+		"  -d, --print-decimal               print variable in decimal values specified\n"
d5c737
+		"                                    by --name\n"
d5c737
+		"  -n, --name=<guid-name>            variable to manipulate, in the form\n"
d5c737
+		"                                    8be4df61-93ca-11d2-aa0d-00e098032b8c-Boot0000\n"
d5c737
+		"  -a, --append                      append to variable specified by --name\n"
d5c737
+		"  -e, --export=<file>               export variable to <file>\n"
d5c737
+		"  -f, --fromfile=<file>             use data from <file>\n"
d5c737
+		"  -t, --attributes=<attributes>     attributes to use on append\n"
d5c737
+		"  -L, --list-guids                  show internal guid list\n"
d5c737
+		"  -w, --write                       write to variable specified by --name\n\n"
d5c737
+		"Help options:\n"
d5c737
+		"  -?, --help                        Show this help message\n"
d5c737
+		"      --usage                       Display brief usage message\n",
d5c737
+		program_invocation_short_name);
d5c737
+	exit(ret);
d5c737
 }
d5c737
 
d5c737
 int main(int argc, char *argv[])
d5c737
@@ -391,7 +396,7 @@ int main(int argc, char *argv[])
d5c737
 	int c = 0;
d5c737
 	int i = 0;
d5c737
 	int action = 0;
d5c737
-	void *data = NULL;
d5c737
+	uint8_t *data = NULL;
d5c737
 	size_t data_size = 0;
d5c737
 	char *name = NULL;
d5c737
 	char *file = NULL;
d5c737
@@ -434,10 +439,10 @@ int main(int argc, char *argv[])
d5c737
 				break;
d5c737
 			case 't':
d5c737
 				attributes = strtoul(optarg, NULL, 10);
d5c737
-				if (errno == ERANGE || errno == EINVAL) {
d5c737
-					fprintf(stderr, "invalid argument for -t: %s: %s\n", optarg, strerror(errno));
d5c737
-					return EXIT_FAILURE;
d5c737
-				}
d5c737
+				if (errno == ERANGE || errno == EINVAL)
d5c737
+					err(1,
d5c737
+					    "invalid argument for -t: %s: %m\n",
d5c737
+					    optarg);
d5c737
 				break;
d5c737
 			case 'L':
d5c737
 				action |= ACTION_LIST_GUIDS;
d5c737
@@ -446,13 +451,11 @@ int main(int argc, char *argv[])
d5c737
 				action |= ACTION_WRITE;
d5c737
 				break;
d5c737
 			case '?':
d5c737
-				usage(argv[0]);
d5c737
-				return EXIT_SUCCESS;
d5c737
+				usage(EXIT_SUCCESS);
d5c737
+				break;
d5c737
 			case 0:
d5c737
-				if (strcmp(lopts[i].name, "usage")) {
d5c737
-					usage(argv[0]);
d5c737
-					return EXIT_SUCCESS;
d5c737
-				}
d5c737
+				if (strcmp(lopts[i].name, "usage"))
d5c737
+					usage(EXIT_SUCCESS);
d5c737
 				break;
d5c737
 		}
d5c737
 	}
d5c737
@@ -506,6 +509,9 @@ int main(int argc, char *argv[])
d5c737
 					guid[i].symbol + strlen("efi_guid_"),
d5c737
 					guid[i].symbol, guid[i].name);
d5c737
 			}
d5c737
+		case ACTION_USAGE:
d5c737
+		default:
d5c737
+			usage(EXIT_FAILURE);
d5c737
 		}
d5c737
 	};
d5c737
 
d5c737
-- 
d5c737
2.26.2
d5c737