Pino Toscano
2018-Feb-06 16:33 UTC
[Libguestfs] [PATCH v2] daemon: build also without Hivex.OPEN_UNSAFE (RHBZ#1493048)
Do a configure check for the OPEN_UNSAFE flag in the OCaml binding of Hivex, using it only when available. This makes it possible to use hivex < 1.3.14 to build libguestfs (the daemon, actually). Amend the building documentation accordingly, bringing the minimum version of hivex back as it was before commit 64f49df747c0937d9433eb11d4191d92a4af748c. --- .gitignore | 1 + configure.ac | 1 + daemon/Makefile.am | 2 ++ daemon/daemon_config.ml.in | 20 ++++++++++++++++++++ daemon/daemon_config.mli | 19 +++++++++++++++++++ daemon/inspect_utils.ml | 6 +++++- docs/guestfs-building.pod | 2 +- m4/guestfs-ocaml.m4 | 19 +++++++++++++++++++ 8 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 daemon/daemon_config.ml.in create mode 100644 daemon/daemon_config.mli diff --git a/.gitignore b/.gitignore index 8276afb26..233a8c536 100644 --- a/.gitignore +++ b/.gitignore @@ -186,6 +186,7 @@ Makefile.in /daemon/actions.h /daemon/callbacks.ml /daemon/caml-stubs.c +/daemon/daemon_config.ml /daemon/daemon_utils_tests /daemon/dispatch.c /daemon/guestfsd diff --git a/configure.ac b/configure.ac index e293ece65..e3df97fce 100644 --- a/configure.ac +++ b/configure.ac @@ -247,6 +247,7 @@ AC_CONFIG_FILES([Makefile common/windows/Makefile csharp/Makefile customize/Makefile + daemon/daemon_config.ml daemon/Makefile df/Makefile dib/Makefile diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 994bcd61a..c534baab0 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -251,6 +251,7 @@ SOURCES_MLI = \ callbacks.mli \ chroot.mli \ daemon.mli \ + daemon_config.mli \ devsparts.mli \ file.mli \ filearch.mli \ @@ -279,6 +280,7 @@ SOURCES_MLI = \ utils.mli SOURCES_ML = \ + daemon_config.ml \ utils.ml \ structs.ml \ optgroups.ml \ diff --git a/daemon/daemon_config.ml.in b/daemon/daemon_config.ml.in new file mode 100644 index 000000000..bb810a171 --- /dev/null +++ b/daemon/daemon_config.ml.in @@ -0,0 +1,20 @@ +(* guestfsd + * @configure_input@ + * Copyright (C) 2018 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + *) + +let hivex_flag_unsafe = @HIVEX_OPEN_UNSAFE_FLAG@ diff --git a/daemon/daemon_config.mli b/daemon/daemon_config.mli new file mode 100644 index 000000000..53024225f --- /dev/null +++ b/daemon/daemon_config.mli @@ -0,0 +1,19 @@ +(* guestfsd + * Copyright (C) 2018 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + *) + +val hivex_flag_unsafe : Hivex.open_flag option diff --git a/daemon/inspect_utils.ml b/daemon/inspect_utils.ml index 5127bf30f..b94c98cd1 100644 --- a/daemon/inspect_utils.ml +++ b/daemon/inspect_utils.ml @@ -176,7 +176,11 @@ let parse_version_from_major_minor str data ) let with_hive hive_filename f - let flags = [ Hivex.OPEN_UNSAFE ] in + let flags = [] in + let flags + match Daemon_config.hivex_flag_unsafe with + | None -> flags + | Some f -> f :: flags in let flags = if verbose () then Hivex.OPEN_VERBOSE :: flags else flags in let h = Hivex.open_file hive_filename flags in protect ~f:(fun () -> f h (Hivex.root h)) ~finally:(fun () -> Hivex.close h) diff --git a/docs/guestfs-building.pod b/docs/guestfs-building.pod index e77e47454..e846a9a1d 100644 --- a/docs/guestfs-building.pod +++ b/docs/guestfs-building.pod @@ -178,7 +178,7 @@ I<Required>. I<Required> if compiling from git. Optional if compiling from tarball. -=item hivex E<ge> 1.3.14 +=item hivex E<ge> 1.2.7 =item ocaml-hivex diff --git a/m4/guestfs-ocaml.m4 b/m4/guestfs-ocaml.m4 index e72b5ad39..94c24bc04 100644 --- a/m4/guestfs-ocaml.m4 +++ b/m4/guestfs-ocaml.m4 @@ -79,6 +79,7 @@ else fi AC_SUBST([OCAMLDEP_ONE_LINE]) +have_Hivex_OPEN_UNSAFE=no if test "x$enable_daemon" = "xyes"; then OCAML_PKG_hivex=no AC_CHECK_OCAML_PKG(hivex) @@ -86,6 +87,18 @@ if test "x$enable_daemon" = "xyes"; then AC_MSG_ERROR([the OCaml module 'hivex' is required]) fi + # Check if Hivex has 'OPEN_UNSAFE' flag. + AC_MSG_CHECKING([for Hivex.OPEN_UNSAFE]) + rm -f conftest.ml + echo 'let s = Hivex.OPEN_UNSAFE' > conftest.ml + if $OCAMLFIND ocamlc -package hivex -c conftest.ml >&5 2>&5 ; then + AC_MSG_RESULT([yes]) + have_Hivex_OPEN_UNSAFE=yes + else + AC_MSG_RESULT([no]) + have_Hivex_OPEN_UNSAFE=no + fi + dnl Check which OCaml runtime to link the daemon again. dnl We can't use AC_CHECK_LIB here unfortunately because dnl the other symbols are resolved by OCaml itself. @@ -182,6 +195,12 @@ AC_SUBST([OCAML_BYTES_COMPAT_CMO]) AC_SUBST([OCAML_BYTES_COMPAT_ML]) AM_CONDITIONAL([HAVE_BYTES_COMPAT_ML], [test "x$OCAML_BYTES_COMPAT_ML" != "x"]) +AS_IF([test "x$have_Hivex_OPEN_UNSAFE" = "xno"],[ + HIVEX_OPEN_UNSAFE_FLAG="None" +],[ + HIVEX_OPEN_UNSAFE_FLAG="Some Hivex.OPEN_UNSAFE" +]) +AC_SUBST([HIVEX_OPEN_UNSAFE_FLAG]) dnl Flags we want to pass to every OCaml compiler call. OCAML_WARN_ERROR="-warn-error CDEFLMPSUVYZX+52-3" -- 2.14.3
Richard W.M. Jones
2018-Feb-07 11:06 UTC
Re: [Libguestfs] [PATCH v2] daemon: build also without Hivex.OPEN_UNSAFE (RHBZ#1493048)
ACK Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Apparently Analagous Threads
- [PATCH] daemon: build also without Hivex.OPEN_UNSAFE (RHBZ#1493048)
- Re: [PATCH] daemon: build also without Hivex.OPEN_UNSAFE (RHBZ#1493048)
- [PATCH v12 08/11] daemon: Implement inspection types and utility functions.
- [PATCH v11 09/10] daemon: Implement inspection of Windows.
- [Hivex] [PATCH] lib: Promote byte_conversions.h #include to hivex-internal.h