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

6b3c76
From 82366b73d1430f2ff2086401e09c88be1f170bd5 Mon Sep 17 00:00:00 2001
a85e8e
From: Colin Watson <cjwatson@ubuntu.com>
a85e8e
Date: Fri, 17 Jan 2014 02:28:46 +0000
6b3c76
Subject: [PATCH 035/261] 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
---
d41074
 ChangeLog                          |  7 +++++++
6b3c76
 grub-core/osdep/freebsd/hostdisk.c | 12 ++++++++++--
a85e8e
 2 files changed, 17 insertions(+), 2 deletions(-)
a85e8e
6b3c76
diff --git a/ChangeLog b/ChangeLog
6b3c76
index 4688ff4e6..10abfe28f 100644
6b3c76
--- a/ChangeLog
6b3c76
+++ b/ChangeLog
6b3c76
@@ -1,3 +1,10 @@
6b3c76
+2014-01-19  Colin Watson  <cjwatson@ubuntu.com>
6b3c76
+
6b3c76
+	* grub-core/osdep/freebsd/hostdisk.c (grub_util_fd_open): Ignore
6b3c76
+	EPERM when modifying kern.geom.debugflags.  It is only a problem for
6b3c76
+	such things as installing GRUB to the MBR, in which case there'll be
6b3c76
+	an error later anyway, not for opening files during tests.
6b3c76
+
6b3c76
 2014-01-18  Andrey Borzenkov <arvidjaar@gmail.com>
6b3c76
 
6b3c76
 	* grub-core/Makefile.am: Build grub_emu_init.[ch] from MODULE_FILES
a85e8e
diff --git a/grub-core/osdep/freebsd/hostdisk.c b/grub-core/osdep/freebsd/hostdisk.c
6b3c76
index eb202dcc8..6145d0735 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);
6b3c76
-- 
6b3c76
2.13.5
6b3c76