All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Ignore EPERM when modifying kern.geom.debugflags
@ 2014-01-17  2:55 Colin Watson
  2014-01-18 15:20 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 2+ messages in thread
From: Colin Watson @ 2014-01-17  2:55 UTC (permalink / raw)
  To: grub-devel

Many tests fail when run as a non-root user on FreeBSD.  The failures
all amount to an inability to open files using grub_util_fd_open,
because we cannot set the kern.geom.debugflags sysctl.  This sysctl is
indeed important to allow us to do such things as installing GRUB to the
MBR, but if we need to do that and can't then we will get an error
later.  Enforcing it here is unnecessary and prevents otherwise
perfectly reasonable operations.
---
 grub-core/osdep/freebsd/hostdisk.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/grub-core/osdep/freebsd/hostdisk.c b/grub-core/osdep/freebsd/hostdisk.c
index eb202dc..6145d07 100644
--- a/grub-core/osdep/freebsd/hostdisk.c
+++ b/grub-core/osdep/freebsd/hostdisk.c
@@ -102,8 +102,16 @@ grub_util_fd_open (const char *os_dev, int flags)
   if (! (sysctl_oldflags & 0x10)
       && sysctlbyname ("kern.geom.debugflags", NULL , 0, &sysctl_flags, sysctl_size))
     {
-      grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags of sysctl kern.geom.debugflags");
-      return GRUB_UTIL_FD_INVALID;
+      if (errno == EPERM)
+	/* Running as an unprivileged user; don't worry about restoring
+	   flags, although if we try to write to anything interesting such
+	   as the MBR then we may fail later.  */
+	sysctl_oldflags = 0x10;
+      else
+	{
+	  grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags of sysctl kern.geom.debugflags");
+	  return GRUB_UTIL_FD_INVALID;
+	}
     }
 
   ret = open (os_dev, flags, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR);
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Ignore EPERM when modifying kern.geom.debugflags
  2014-01-17  2:55 [PATCH] Ignore EPERM when modifying kern.geom.debugflags Colin Watson
@ 2014-01-18 15:20 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 2+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2014-01-18 15:20 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 1692 bytes --]

go ahead
On 17.01.2014 03:55, Colin Watson wrote:
> Many tests fail when run as a non-root user on FreeBSD.  The failures
> all amount to an inability to open files using grub_util_fd_open,
> because we cannot set the kern.geom.debugflags sysctl.  This sysctl is
> indeed important to allow us to do such things as installing GRUB to the
> MBR, but if we need to do that and can't then we will get an error
> later.  Enforcing it here is unnecessary and prevents otherwise
> perfectly reasonable operations.
> ---
>  grub-core/osdep/freebsd/hostdisk.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/grub-core/osdep/freebsd/hostdisk.c b/grub-core/osdep/freebsd/hostdisk.c
> index eb202dc..6145d07 100644
> --- a/grub-core/osdep/freebsd/hostdisk.c
> +++ b/grub-core/osdep/freebsd/hostdisk.c
> @@ -102,8 +102,16 @@ grub_util_fd_open (const char *os_dev, int flags)
>    if (! (sysctl_oldflags & 0x10)
>        && sysctlbyname ("kern.geom.debugflags", NULL , 0, &sysctl_flags, sysctl_size))
>      {
> -      grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags of sysctl kern.geom.debugflags");
> -      return GRUB_UTIL_FD_INVALID;
> +      if (errno == EPERM)
> +	/* Running as an unprivileged user; don't worry about restoring
> +	   flags, although if we try to write to anything interesting such
> +	   as the MBR then we may fail later.  */
> +	sysctl_oldflags = 0x10;
> +      else
> +	{
> +	  grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags of sysctl kern.geom.debugflags");
> +	  return GRUB_UTIL_FD_INVALID;
> +	}
>      }
>  
>    ret = open (os_dev, flags, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR);
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 274 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-01-18 15:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-17  2:55 [PATCH] Ignore EPERM when modifying kern.geom.debugflags Colin Watson
2014-01-18 15:20 ` Vladimir 'φ-coder/phcoder' Serbinenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.