Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144770624
D29619.id87087.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D29619.id87087.diff
View Options
Index: usr.sbin/efivar/efivar.8
===================================================================
--- usr.sbin/efivar/efivar.8
+++ usr.sbin/efivar/efivar.8
@@ -1,5 +1,5 @@
.\"
-.\" Copyright (c) 2017-2019 Netflix, Inc.
+.\" Copyright (c) 2017-2021 Netflix, Inc.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd June 18, 2020
+.Dd April 7, 2021
.Dt EFIVAR 8
.Os
.Sh NAME
@@ -32,7 +32,7 @@
.Nd UEFI environment variable interaction
.Sh SYNOPSIS
.Nm
-.Op Fl abdDHlLNpRtuw
+.Op Fl abdDHlLNpqRtuw
.Op Fl n Ar name
.Op Fl f Ar file
.Op Fl -append
@@ -51,6 +51,7 @@
.Op Fl -no-name
.Op Fl -print
.Op Fl -print-decimal
+.Op Fl -quiet
.Op Fl -raw-guid
.Op Fl -utf8
.Op Fl -write
@@ -155,6 +156,9 @@
Do not display the variable name.
.It Fl p Fl -print
Print the value of the variable.
+.It Fl q Fl -quiet
+When an error occurs, exit with a non-zero value without outputting any error messages.
+Otherwise, produce the normal output and exit with a zero status.
.It Fl R Fl -raw-guid
Do not substitute well known names for GUID numeric values in output.
.It Fl u Fl -utf8
Index: usr.sbin/efivar/efivar.c
===================================================================
--- usr.sbin/efivar/efivar.c
+++ usr.sbin/efivar/efivar.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2016 Netflix, Inc.
+ * Copyright (c) 2016-2021 Netflix, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -33,6 +33,8 @@
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
+#include <stdarg.h>
+#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -60,6 +62,7 @@
{ "no-name", no_argument, NULL, 'N' },
{ "print", no_argument, NULL, 'p' },
// { "print-decimal", no_argument, NULL, 'd' }, /* unimplemnted clash with linux version */
+ { "quiet", no_argument, NULL, 'q' },
{ "raw-guid", no_argument, NULL, 'R' },
{ "utf8", no_argument, NULL, 'u' },
{ "write", no_argument, NULL, 'w' },
@@ -69,6 +72,7 @@
static int aflag, Aflag, bflag, dflag, Dflag, gflag, Hflag, Nflag,
lflag, Lflag, Rflag, wflag, pflag, uflag, load_opt_flag;
+static bool quiet;
static char *varname;
static char *fromfile;
static u_long attrib = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
@@ -77,13 +81,40 @@
usage(void)
{
- errx(1, "efivar [-abdDHlLNpRtuw] [-n name] [-f file] [--append] [--ascii]\n"
+ errx(1, "efivar [-abdDHlLNpqRtuw] [-n name] [-f file] [--append] [--ascii]\n"
"\t[--attributes] [--binary] [--delete] [--fromfile file] [--hex]\n"
"\t[--list-guids] [--list] [--load-option] [--name name] [--no-name]\n"
"\t[--print] [--print-decimal] [--raw-guid] [--utf8] [--write]\n"
+ "\t[--quiet]\n"
"\tname[=value]");
}
+static void
+rep_err(int eval, const char *fmt, ...)
+{
+ va_list ap;
+
+ if (quiet)
+ exit(eval);
+
+ va_start(ap, fmt);
+ verr(eval, fmt, ap);
+ va_end(ap);
+}
+
+static void
+rep_errx(int eval, const char *fmt, ...)
+{
+ va_list ap;
+
+ if (quiet)
+ exit(eval);
+
+ va_start(ap, fmt);
+ verrx(eval, fmt, ap);
+ va_end(ap);
+}
+
static void
breakdown_name(char *name, efi_guid_t *guid, char **vname)
{
@@ -91,11 +122,11 @@
cp = strrchr(name, '-');
if (cp == NULL)
- errx(1, "Invalid name: %s", name);
+ rep_errx(1, "Invalid name: %s", name);
*vname = cp + 1;
*cp = '\0';
if (efi_name_to_guid(name, guid) < 0)
- errx(1, "Invalid guid %s", name);
+ rep_errx(1, "Invalid guid %s", name);
}
static uint8_t *
@@ -124,7 +155,7 @@
breakdown_name(name, &guid, &vname);
data = get_value(val, &datalen);
if (efi_append_variable(guid, vname, data, datalen, attrib) < 0)
- err(1, "efi_append_variable");
+ rep_err(1, "efi_append_variable");
}
static void
@@ -135,7 +166,7 @@
breakdown_name(name, &guid, &vname);
if (efi_del_variable(guid, vname) < 0)
- err(1, "efi_del_variable");
+ rep_err(1, "efi_del_variable");
}
static void
@@ -149,7 +180,7 @@
breakdown_name(name, &guid, &vname);
data = get_value(val, &datalen);
if (efi_set_variable(guid, vname, data, datalen, attrib) < 0)
- err(1, "efi_set_variable");
+ rep_err(1, "efi_set_variable");
}
static void
@@ -195,18 +226,18 @@
fd = open(fromfile, O_RDONLY);
if (fd < 0)
- err(1, "open %s", fromfile);
+ rep_err(1, "open %s", fromfile);
data = malloc(64 * 1024);
if (data == NULL)
- err(1, "malloc");
+ rep_err(1, "malloc");
datalen = read(fd, data, 64 * 1024);
if (datalen <= 0)
- err(1, "read");
+ rep_err(1, "read");
close(fd);
} else {
rv = efi_get_variable(*guid, name, &data, &datalen, &att);
if (rv < 0)
- err(1, "fetching %s-%s", gname, name);
+ rep_err(1, "fetching %s-%s", gname, name);
}
@@ -253,7 +284,7 @@
print_var(guid, name);
if (rv < 0)
- err(1, "Error listing names");
+ rep_err(1, "Error listing names");
}
static void
@@ -272,7 +303,7 @@
{
int ch, i;
- while ((ch = getopt_long(argc, argv, "aAbdDf:gHlLNn:OpRt:uw",
+ while ((ch = getopt_long(argc, argv, "aAbdDf:gHlLNn:OpqRt:uw",
longopts, NULL)) != -1) {
switch (ch) {
case 'a':
@@ -314,6 +345,9 @@
case 'p':
pflag++;
break;
+ case 'q':
+ quiet = true;
+ break;
case 'R':
Rflag++;
break;
@@ -331,7 +365,7 @@
fromfile = strdup(optarg);
break;
case 0:
- errx(1, "unknown or unimplemented option\n");
+ rep_errx(1, "unknown or unimplemented option\n");
break;
default:
usage();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Feb 13, 9:00 AM (14 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28675702
Default Alt Text
D29619.id87087.diff (5 KB)
Attached To
Mode
D29619: efivar: Add --quiet to not report errors
Attached
Detach File
Event Timeline
Log In to Comment