git: c08ba4a588d5 - main - efibootmgr: provide explicit error message if run as non-root

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Sun, 15 Oct 2023 18:32:49 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=c08ba4a588d517e3c5fe00cee0927294d2490993

commit c08ba4a588d517e3c5fe00cee0927294d2490993
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2023-10-15 17:21:52 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-10-15 18:31:51 +0000

    efibootmgr: provide explicit error message if run as non-root
    
    This should be less confusing for new users.
    
    Reviewed by:    imp
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D42213
---
 usr.sbin/efibootmgr/efibootmgr.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/efibootmgr/efibootmgr.c b/usr.sbin/efibootmgr/efibootmgr.c
index b0d023e3539c..8dcf9876486d 100644
--- a/usr.sbin/efibootmgr/efibootmgr.c
+++ b/usr.sbin/efibootmgr/efibootmgr.c
@@ -1101,8 +1101,11 @@ main(int argc, char *argv[])
 	/*
 	 * find_dev can operate without any efi variables
 	 */
-	if (!efi_variables_supported() && !opts.find_dev)
-		errx(1, "efi variables not supported on this system. root? kldload efirt?");
+	if (!efi_variables_supported() && !opts.find_dev) {
+		if (errno == EACCES && geteuid() != 0)
+			errx(1, "must be run as root");
+		errx(1, "efi variables not supported on this system. kldload efirt?");
+	}
 
 	read_vars();