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 64f49df747.
This commit is contained in:
Pino Toscano
2018-02-06 17:27:23 +01:00
parent 382b544731
commit 82fbf294fd
8 changed files with 68 additions and 2 deletions

1
.gitignore vendored
View File

@@ -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

View File

@@ -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

View File

@@ -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 \

View File

@@ -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@

19
daemon/daemon_config.mli Normal file
View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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"