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

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