a5bd9f6
From b37a32bb89c476b0ead4c40900de29fe8d73d27e Mon Sep 17 00:00:00 2001
a5bd9f6
From: Colin Watson <cjwatson@ubuntu.com>
a5bd9f6
Date: Sat, 22 Sep 2012 21:19:58 +0100
a5bd9f6
Subject: [PATCH 045/364] Fix grub-emu build on FreeBSD.
a5bd9f6
a5bd9f6
* Makefile.util.def (grub-mount): Add LIBGEOM to ldadd.
a5bd9f6
* grub-core/net/drivers/emu/emunet.c: Only include Linux-specific
a5bd9f6
headers on Linux.
a5bd9f6
(GRUB_MOD_INIT): Return immediately on non-Linux platforms; this
a5bd9f6
implementation is currently Linux-specific.
a5bd9f6
* util/getroot.c (exec_pipe): Define only on Linux or when either
a5bd9f6
libzfs or libnvpair is unavailable.
a5bd9f6
(find_root_devices_from_poolname): Remove unused path variable.
a5bd9f6
---
a5bd9f6
 ChangeLog                          | 13 +++++++++++++
a5bd9f6
 Makefile.util.def                  |  2 +-
a5bd9f6
 grub-core/net/drivers/emu/emunet.c | 11 +++++++++--
a5bd9f6
 util/getroot.c                     |  7 ++++++-
a5bd9f6
 4 files changed, 29 insertions(+), 4 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 5db804e..3eda38f 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,3 +1,16 @@
a5bd9f6
+2012-09-22  Colin Watson  <cjwatson@ubuntu.com>
a5bd9f6
+
a5bd9f6
+	Fix grub-emu build on FreeBSD.
a5bd9f6
+
a5bd9f6
+	* Makefile.util.def (grub-mount): Add LIBGEOM to ldadd.
a5bd9f6
+	* grub-core/net/drivers/emu/emunet.c: Only include Linux-specific
a5bd9f6
+	headers on Linux.
a5bd9f6
+	(GRUB_MOD_INIT): Return immediately on non-Linux platforms; this
a5bd9f6
+	implementation is currently Linux-specific.
a5bd9f6
+	* util/getroot.c (exec_pipe): Define only on Linux or when either
a5bd9f6
+	libzfs or libnvpair is unavailable.
a5bd9f6
+	(find_root_devices_from_poolname): Remove unused path variable.
a5bd9f6
+
a5bd9f6
 2012-09-19  Colin Watson  <cjwatson@ubuntu.com>
a5bd9f6
 
a5bd9f6
 	* grub-core/partmap/msdos.c (pc_partition_map_embed): Revert
a5bd9f6
diff --git a/Makefile.util.def b/Makefile.util.def
a5bd9f6
index b80187c..72057cf 100644
a5bd9f6
--- a/Makefile.util.def
a5bd9f6
+++ b/Makefile.util.def
a5bd9f6
@@ -266,7 +266,7 @@ program = {
a5bd9f6
   ldadd = libgrubgcry.a;
a5bd9f6
   ldadd = libgrubkern.a;
a5bd9f6
   ldadd = grub-core/gnulib/libgnu.a;
a5bd9f6
-  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) -lfuse';
a5bd9f6
+  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) -lfuse';
a5bd9f6
   condition = COND_GRUB_MOUNT;
a5bd9f6
 };
a5bd9f6
 
a5bd9f6
diff --git a/grub-core/net/drivers/emu/emunet.c b/grub-core/net/drivers/emu/emunet.c
a5bd9f6
index 7a7aeaf..6b533dd 100644
a5bd9f6
--- a/grub-core/net/drivers/emu/emunet.c
a5bd9f6
+++ b/grub-core/net/drivers/emu/emunet.c
a5bd9f6
@@ -21,8 +21,10 @@
a5bd9f6
 #include <sys/socket.h>
a5bd9f6
 #include <grub/net.h>
a5bd9f6
 #include <sys/types.h>
a5bd9f6
-#include <linux/if.h>
a5bd9f6
-#include <linux/if_tun.h>
a5bd9f6
+#ifdef __linux__
a5bd9f6
+# include <linux/if.h>
a5bd9f6
+# include <linux/if_tun.h>
a5bd9f6
+#endif /* __linux__ */
a5bd9f6
 #include <sys/ioctl.h>
a5bd9f6
 #include <fcntl.h>
a5bd9f6
 #include <unistd.h>
a5bd9f6
@@ -97,6 +99,7 @@ static struct grub_net_card emucard =
a5bd9f6
 
a5bd9f6
 GRUB_MOD_INIT(emunet)
a5bd9f6
 {
a5bd9f6
+#ifdef __linux__
a5bd9f6
   struct ifreq ifr;
a5bd9f6
   fd = open ("/dev/net/tun", O_RDWR | O_NONBLOCK);
a5bd9f6
   if (fd < 0)
a5bd9f6
@@ -110,6 +113,10 @@ GRUB_MOD_INIT(emunet)
a5bd9f6
       return;
a5bd9f6
     }
a5bd9f6
   grub_net_card_register (&emucard);
a5bd9f6
+#else /* !__linux__ */
a5bd9f6
+  fd = -1;
a5bd9f6
+  return;
a5bd9f6
+#endif /* __linux__ */
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 GRUB_MOD_FINI(emunet)
a5bd9f6
diff --git a/util/getroot.c b/util/getroot.c
a5bd9f6
index b97bea6..c2a25c9 100644
a5bd9f6
--- a/util/getroot.c
a5bd9f6
+++ b/util/getroot.c
a5bd9f6
@@ -220,6 +220,9 @@ xgetcwd (void)
a5bd9f6
 
a5bd9f6
 #if !defined (__MINGW32__) && !defined (__CYGWIN__) && !defined (__GNU__)
a5bd9f6
 
a5bd9f6
+#if (defined (__linux__) || \
a5bd9f6
+     !defined (HAVE_LIBZFS) || !defined (HAVE_LIBNVPAIR))
a5bd9f6
+
a5bd9f6
 static pid_t
a5bd9f6
 exec_pipe (char **argv, int *fd)
a5bd9f6
 {
a5bd9f6
@@ -258,6 +261,8 @@ exec_pipe (char **argv, int *fd)
a5bd9f6
     }
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
+#endif
a5bd9f6
+
a5bd9f6
 static char **
a5bd9f6
 find_root_devices_from_poolname (char *poolname)
a5bd9f6
 {
a5bd9f6
@@ -269,7 +274,7 @@ find_root_devices_from_poolname (char *poolname)
a5bd9f6
   zpool_handle_t *zpool;
a5bd9f6
   libzfs_handle_t *libzfs;
a5bd9f6
   nvlist_t *config, *vdev_tree;
a5bd9f6
-  nvlist_t **children, **path;
a5bd9f6
+  nvlist_t **children;
a5bd9f6
   unsigned int nvlist_count;
a5bd9f6
   unsigned int i;
a5bd9f6
   char *device = 0;
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6