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

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