From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1W3zaY-0000Wa-Js for mharc-grub-devel@gnu.org; Thu, 16 Jan 2014 21:55:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3zaW-0000VV-8s for grub-devel@gnu.org; Thu, 16 Jan 2014 21:55:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W3zaT-0001iu-Ts for grub-devel@gnu.org; Thu, 16 Jan 2014 21:55:16 -0500 Received: from v6.chiark.greenend.org.uk ([2001:ba8:1e3::]:53317 helo=chiark.greenend.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3zaT-0001io-NX for grub-devel@gnu.org; Thu, 16 Jan 2014 21:55:13 -0500 Received: from [172.20.153.9] (helo=riva.pelham.vpn.ucam.org) by chiark.greenend.org.uk (Debian Exim 4.72 #1) with esmtps (return-path cjwatson@ubuntu.com) id 1W3zaR-0007GU-H5 for grub-devel@gnu.org; Fri, 17 Jan 2014 02:55:12 +0000 Received: from ns1.pelham.vpn.ucam.org ([172.20.153.2] helo=riva.ucam.org) by riva.pelham.vpn.ucam.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1W3zaN-0003Dj-4U for grub-devel@gnu.org; Fri, 17 Jan 2014 02:55:07 +0000 Date: Fri, 17 Jan 2014 02:55:05 +0000 From: Colin Watson To: grub-devel@gnu.org Subject: [PATCH] Ignore EPERM when modifying kern.geom.debugflags Message-ID: <20140117025505.GQ5883@riva.ucam.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:ba8:1e3:: X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jan 2014 02:55:17 -0000 Many tests fail when run as a non-root user on FreeBSD. The failures all amount to an inability to open files using grub_util_fd_open, because we cannot set the kern.geom.debugflags sysctl. This sysctl is indeed important to allow us to do such things as installing GRUB to the MBR, but if we need to do that and can't then we will get an error later. Enforcing it here is unnecessary and prevents otherwise perfectly reasonable operations. --- grub-core/osdep/freebsd/hostdisk.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/grub-core/osdep/freebsd/hostdisk.c b/grub-core/osdep/freebsd/hostdisk.c index eb202dc..6145d07 100644 --- a/grub-core/osdep/freebsd/hostdisk.c +++ b/grub-core/osdep/freebsd/hostdisk.c @@ -102,8 +102,16 @@ grub_util_fd_open (const char *os_dev, int flags) if (! (sysctl_oldflags & 0x10) && sysctlbyname ("kern.geom.debugflags", NULL , 0, &sysctl_flags, sysctl_size)) { - grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags of sysctl kern.geom.debugflags"); - return GRUB_UTIL_FD_INVALID; + if (errno == EPERM) + /* Running as an unprivileged user; don't worry about restoring + flags, although if we try to write to anything interesting such + as the MBR then we may fail later. */ + sysctl_oldflags = 0x10; + else + { + grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags of sysctl kern.geom.debugflags"); + return GRUB_UTIL_FD_INVALID; + } } ret = open (os_dev, flags, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR); -- 1.8.5.2