nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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