[Libguestfs] [PATCH] lib: Require libmagic.

Richard W.M. Jones rjones at redhat.com
Mon Feb 27 12:19:28 UTC 2017


If libmagic isn't installed then the guestfs_file_architecture API
doesn't work.  This means that inspection will always return
<arch>unknown</arch> for every guest.  This subtly breaks a few
features.  In particular it was reported that the
virt-builder/virt-customize --install option did not work because the
"unknown" architecture of the guest was not compatible with the host.

libmagic is a small, widely available C library, so the easiest fix is
just to make it mandatory.

Reported by: Solarix on IRC
---
 docs/guestfs-building.pod |  2 +-
 lib/filearch.c            | 20 --------------------
 m4/guestfs_libraries.m4   |  7 ++++---
 3 files changed, 5 insertions(+), 24 deletions(-)

diff --git a/docs/guestfs-building.pod b/docs/guestfs-building.pod
index eba5ec8..53a4d94 100644
--- a/docs/guestfs-building.pod
+++ b/docs/guestfs-building.pod
@@ -177,7 +177,7 @@ Various core features will be disabled if hivex is not available.
 
 =item libmagic
 
-Optional.  This is the library used by the L<file(1)> command.
+I<Required>.  This is the library used by the L<file(1)> command.
 
 =item libvirt E<ge> 0.10.2
 
diff --git a/lib/filearch.c b/lib/filearch.c
index 2c75425..e1d3dae 100644
--- a/lib/filearch.c
+++ b/lib/filearch.c
@@ -27,9 +27,7 @@
 #include <sys/wait.h>
 #include <libintl.h>
 
-#ifdef HAVE_LIBMAGIC
 #include <magic.h>
-#endif
 
 #include "ignore-value.h"
 
@@ -37,8 +35,6 @@
 #include "guestfs-internal.h"
 #include "guestfs-internal-actions.h"
 
-#if defined(HAVE_LIBMAGIC)
-
 # ifdef HAVE_ATTRIBUTE_CLEANUP
 # define CLEANUP_MAGIC_T_FREE __attribute__((cleanup(cleanup_magic_t_free)))
 
@@ -364,19 +360,3 @@ guestfs_impl_file_architecture (guestfs_h *g, const char *path)
 
   return ret;                   /* caller frees */
 }
-
-#else /* no libmagic at compile time */
-
-/* XXX Should be an optgroup. */
-
-#define NOT_IMPL(r)                                                     \
-  error (g, _("file-architecture API not available since this version of libguestfs was compiled without the libmagic library")); \
-  return r
-
-char *
-guestfs_impl_file_architecture (guestfs_h *g, const char *path)
-{
-  NOT_IMPL(NULL);
-}
-
-#endif /* no libmagic at compile time */
diff --git a/m4/guestfs_libraries.m4 b/m4/guestfs_libraries.m4
index ac71b39..0882d27 100644
--- a/m4/guestfs_libraries.m4
+++ b/m4/guestfs_libraries.m4
@@ -230,13 +230,14 @@ PKG_CHECK_MODULES([PCRE], [libpcre])
 dnl Check for Augeas >= 1.0.0 (required).
 PKG_CHECK_MODULES([AUGEAS],[augeas >= 1.0.0])
 
-dnl libmagic (highly recommended)
+dnl libmagic (required)
 AC_CHECK_LIB([magic],[magic_file],[
     AC_CHECK_HEADER([magic.h],[
         AC_SUBST([MAGIC_LIBS], ["-lmagic"])
-        AC_DEFINE([HAVE_LIBMAGIC],[1],[libmagic found at compile time.])
     ], [])
-],[AC_MSG_WARN([libmagic not found, some core features will be disabled])])
+],[])
+AS_IF([test -z "$MAGIC_LIBS"],
+    [AC_MSG_ERROR([libmagic (part of the "file" command) is required])])
 
 dnl libvirt (highly recommended)
 AC_ARG_WITH([libvirt],[
-- 
2.9.3




More information about the Libguestfs mailing list