Blame SOURCES/0035-Ignore-EPERM-when-modifying-kern.geom.debugflags.patch

d41074
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
a85e8e
From: Colin Watson <cjwatson@ubuntu.com>
a85e8e
Date: Fri, 17 Jan 2014 02:28:46 +0000
d41074
Subject: [PATCH] Ignore EPERM when modifying kern.geom.debugflags
a85e8e
a85e8e
Many tests fail when run as a non-root user on FreeBSD.  The failures
a85e8e
all amount to an inability to open files using grub_util_fd_open,
a85e8e
because we cannot set the kern.geom.debugflags sysctl.  This sysctl is
a85e8e
indeed important to allow us to do such things as installing GRUB to the
a85e8e
MBR, but if we need to do that and can't then we will get an error
a85e8e
later.  Enforcing it here is unnecessary and prevents otherwise
a85e8e
perfectly reasonable operations.
a85e8e
---
a85e8e
 grub-core/osdep/freebsd/hostdisk.c | 12 ++++++++++--
d41074
 ChangeLog                          |  7 +++++++
a85e8e
 2 files changed, 17 insertions(+), 2 deletions(-)
a85e8e
a85e8e
diff --git a/grub-core/osdep/freebsd/hostdisk.c b/grub-core/osdep/freebsd/hostdisk.c
d41074
index eb202dcc831..6145d073555 100644
a85e8e
--- a/grub-core/osdep/freebsd/hostdisk.c
a85e8e
+++ b/grub-core/osdep/freebsd/hostdisk.c
a85e8e
@@ -102,8 +102,16 @@ grub_util_fd_open (const char *os_dev, int flags)
a85e8e
   if (! (sysctl_oldflags & 0x10)
a85e8e
       && sysctlbyname ("kern.geom.debugflags", NULL , 0, &sysctl_flags, sysctl_size))
a85e8e
     {
a85e8e
-      grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags of sysctl kern.geom.debugflags");
a85e8e
-      return GRUB_UTIL_FD_INVALID;
a85e8e
+      if (errno == EPERM)
a85e8e
+	/* Running as an unprivileged user; don't worry about restoring
a85e8e
+	   flags, although if we try to write to anything interesting such
a85e8e
+	   as the MBR then we may fail later.  */
a85e8e
+	sysctl_oldflags = 0x10;
a85e8e
+      else
a85e8e
+	{
a85e8e
+	  grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags of sysctl kern.geom.debugflags");
a85e8e
+	  return GRUB_UTIL_FD_INVALID;
a85e8e
+	}
a85e8e
     }
a85e8e
 
a85e8e
   ret = open (os_dev, flags, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR);
d41074
diff --git a/ChangeLog b/ChangeLog
d41074
index 4688ff4e6d3..10abfe28f20 100644
d41074
--- a/ChangeLog
d41074
+++ b/ChangeLog
d41074
@@ -1,3 +1,10 @@
d41074
+2014-01-19  Colin Watson  <cjwatson@ubuntu.com>
d41074
+
d41074
+	* grub-core/osdep/freebsd/hostdisk.c (grub_util_fd_open): Ignore
d41074
+	EPERM when modifying kern.geom.debugflags.  It is only a problem for
d41074
+	such things as installing GRUB to the MBR, in which case there'll be
d41074
+	an error later anyway, not for opening files during tests.
d41074
+
d41074
 2014-01-18  Andrey Borzenkov <arvidjaar@gmail.com>
d41074
 
d41074
 	* grub-core/Makefile.am: Build grub_emu_init.[ch] from MODULE_FILES