[PATCH] v2v: do not hide the error, rather report it
by Tomáš Golembiovský
The Invalid_argument exception is there to catch unexpected situation
when rpm returns no output. Such situation should be reported rather
then hidden.
Signed-off-by: Tomáš Golembiovský <tgolembi(a)redhat.com>
---
v2v/linux.ml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/v2v/linux.ml b/v2v/linux.ml
index e57dad6..46cb3ba 100644
--- a/v2v/linux.ml
+++ b/v2v/linux.ml
@@ -109,8 +109,8 @@ let rec file_owner (g : G.guestfs) inspect path =
raise Not_found
else
raise exn
- | Invalid_argument msg ->
- raise Not_found
+ | Invalid_argument "index out of bounds" ->
+ error (f_"internal error: file_owner: rpm command returned no output")
)
| format ->
--
2.9.2
8 years, 4 months
Plan for libguestfs 1.34
by Richard W.M. Jones
Libguestfs 1.32 was released on 2016-01-06, which is over 6 months
ago. In fact the previous stable version of libguestfs (1.30) was
released on 2015-07-21, almost exactly 12 months ago. Are we heading
for a 6 month release cycle? Not officially. Anyway, I would like
you to think about what needs work for the next stable 1.34 release.
Any new APIs added in the 1.33 cycle will become supported and
guaranteed when we release 1.34, so we need to check those. See:
git diff 1.32.0 -- generator/actions.ml
Please follow-up also if there are features / blockers / bugs that
need to be addressed for 1.34.
As usual, bugs which have "1.34" (without quotes) in the "Devel
Whiteboard" field in Bugzilla are nominated as blockers for the
release. You can see a list of those here (currently empty):
https://bugzilla.redhat.com/buglist.cgi?bug_status=NEW&bug_status=ASSIGNE...
For a list of all bugs, go to:
https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virt...
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
8 years, 4 months
[PATCH] build: Add silent rules for podwrapper.
by Richard W.M. Jones
Also quietens the podwrapper script itself, as there is no reason to
print 'wrote <output>' for each output file.
---
m4/guestfs_perl.m4 | 2 +-
podwrapper.pl.in | 6 +++---
subdir-rules.mk | 3 +++
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/m4/guestfs_perl.m4 b/m4/guestfs_perl.m4
index 249772c..be688b4 100644
--- a/m4/guestfs_perl.m4
+++ b/m4/guestfs_perl.m4
@@ -35,7 +35,7 @@ else
fi
dnl Define the path to the podwrapper program.
-PODWRAPPER="$PERL $(pwd)/podwrapper.pl"
+PODWRAPPER="\$(guestfs_am_v_podwrapper)$PERL $(pwd)/podwrapper.pl"
AC_SUBST([PODWRAPPER])
dnl Check for Perl for Perl bindings and Perl tools.
diff --git a/podwrapper.pl.in b/podwrapper.pl.in
index 7322a30..e9cafed 100755
--- a/podwrapper.pl.in
+++ b/podwrapper.pl.in
@@ -520,7 +520,7 @@ if ($man) {
unlink $man;
die "$input: errors or warnings in this POD file, see messages above\n"
}
- print "$progname: wrote $man\n";
+ #print "$progname: wrote $man\n";
}
# Output HTML.
@@ -618,7 +618,7 @@ if ($html) {
unlink $html;
die "$input: errors or warnings in this POD file, see messages above\n"
}
- print "$progname: wrote $html\n";
+ #print "$progname: wrote $html\n";
}
# Output text.
@@ -637,7 +637,7 @@ if ($text) {
unlink $text;
die "$input: errors or warnings in this POD file, see messages above\n"
}
- print "$progname: wrote $text\n";
+ #print "$progname: wrote $text\n";
}
sub read_whole_file
diff --git a/subdir-rules.mk b/subdir-rules.mk
index d6aaba7..2432939 100644
--- a/subdir-rules.mk
+++ b/subdir-rules.mk
@@ -69,6 +69,9 @@ guestfs_am_v_javac_0 = @echo " JAVAC " $@;
guestfs_am_v_erlc = $(guestfs_am_v_erlc_@AM_V@)
guestfs_am_v_erlc_ = $(guestfs_am_v_erlc_@AM_DEFAULT_V@)
guestfs_am_v_erlc_0 = @echo " ERLC " $@;
+guestfs_am_v_podwrapper = $(guestfs_am_v_podwrapper_@AM_V@)
+guestfs_am_v_podwrapper_ = $(guestfs_am_v_podwrapper_@AM_DEFAULT_V@)
+guestfs_am_v_podwrapper_0 = @echo " POD " $@;
.mli.cmi:
$(guestfs_am_v_ocamlc)$(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
--
2.7.4
8 years, 4 months
[PATCH] build: add simple custom silent rules for automake
by Pino Toscano
Add makefile variables to enable silent rules for simple command
invocations, such as ocamlc, ocamlopt, javac, and erlc.
This reduces the log output when building with silent rules, still
showing the full command lines otherwise.
---
erlang/Makefile.am | 2 +-
java/Makefile.am | 6 +++---
ocaml/Makefile.am | 14 +++++++-------
subdir-rules.mk | 20 +++++++++++++++++---
4 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/erlang/Makefile.am b/erlang/Makefile.am
index a9825f6..7dc0906 100644
--- a/erlang/Makefile.am
+++ b/erlang/Makefile.am
@@ -52,7 +52,7 @@ erlang_bin_DATA = guestfs.beam
# The ./run script will set $ERL_LIBS to point to $(builddir)/erlang.
# (See: http://www.erlang.org/doc/man/code.html)
guestfs.beam: guestfs.erl
- $(ERLC) +debug_info $^
+ $(guestfs_am_v_erlc)$(ERLC) +debug_info $^
mkdir -p $(PACKAGE)-$(VERSION)/ebin
cp $@ $(PACKAGE)-$(VERSION)/ebin
diff --git a/java/Makefile.am b/java/Makefile.am
index 0651fd3..8b6944d 100644
--- a/java/Makefile.am
+++ b/java/Makefile.am
@@ -79,7 +79,7 @@ libguestfs_jardir = $(JAR_INSTALL_DIR)
libguestfs_jar_DATA = libguestfs-${VERSION}.jar
libguestfs_jar_class_files = $(java_sources:.java=.class)
$(libguestfs_jar_class_files): %.class: %.java
- $(JAVAC) $(JAVAC_FLAGS) -d . -classpath $(srcdir):. $<
+ $(guestfs_am_v_javac)$(JAVAC) $(JAVAC_FLAGS) -d . -classpath $(srcdir):. $<
libguestfs-${VERSION}.jar: $(libguestfs_jar_class_files)
$(JAR) cf $@ $^
@@ -140,9 +140,9 @@ TESTS_ENVIRONMENT = $(top_builddir)/run --test
check_DATA = Bindtests.class $(java_tests:.java=.class)
t/%.class: t/%.java libguestfs-$(VERSION).jar
- $(JAVAC) $(JAVAC_FLAGS) -classpath libguestfs-$(VERSION).jar -d t $<
+ $(guestfs_am_v_javac)$(JAVAC) $(JAVAC_FLAGS) -classpath libguestfs-$(VERSION).jar -d t $<
Bindtests.class: Bindtests.java libguestfs-$(VERSION).jar
- $(JAVAC) $(JAVAC_FLAGS) -classpath libguestfs-$(VERSION).jar -d . $<
+ $(guestfs_am_v_javac)$(JAVAC) $(JAVAC_FLAGS) -classpath libguestfs-$(VERSION).jar -d . $<
endif
diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
index acbfad1..501ac69 100644
--- a/ocaml/Makefile.am
+++ b/ocaml/Makefile.am
@@ -158,12 +158,12 @@ check_DATA += bindtests.opt
endif
%.bc: %.cmo mlguestfs.cma
- $(top_builddir)/libtool -dlopen $(top_builddir)/src/.libs/libguestfs.la --mode=execute \
+ $(guestfs_am_v_ocamlc)$(top_builddir)/libtool -dlopen $(top_builddir)/src/.libs/libguestfs.la --mode=execute \
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -I . -package unix -linkpkg mlguestfs.cma $< -o $@
if HAVE_OCAMLOPT
%.opt: %.cmx mlguestfs.cmxa
- $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -cclib -L$(top_builddir)/src/.libs -I . -package unix -linkpkg mlguestfs.cmxa $< -o $@
+ $(guestfs_am_v_ocamlopt)$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -cclib -L$(top_builddir)/src/.libs -I . -package unix -linkpkg mlguestfs.cmxa $< -o $@
endif
check-valgrind:
@@ -173,16 +173,16 @@ CLEANFILES += bindtests.tmp
# Dependencies.
%.cmi: %.mli
- $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -package unix -c $< -o $@
+ $(guestfs_am_v_ocamlc)$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -package unix -c $< -o $@
guestfs.cmo: guestfs.ml
- $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -package unix -c $< -o $@
+ $(guestfs_am_v_ocamlc)$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -package unix -c $< -o $@
%.cmo: %.ml mlguestfs.cma
- $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -package unix -c $< -o $@
+ $(guestfs_am_v_ocamlc)$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -package unix -c $< -o $@
if HAVE_OCAMLOPT
guestfs.cmx: guestfs.ml
- $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -package unix -c $< -o $@
+ $(guestfs_am_v_ocamlopt)$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -package unix -c $< -o $@
%.cmx: %.ml mlguestfs.cmxa
- $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -package unix -c $< -o $@
+ $(guestfs_am_v_ocamlopt)$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -package unix -c $< -o $@
endif
depend: .depend
diff --git a/subdir-rules.mk b/subdir-rules.mk
index 39c2f50..d6aaba7 100644
--- a/subdir-rules.mk
+++ b/subdir-rules.mk
@@ -56,11 +56,25 @@ MLARCHIVE = cmxa
BEST = opt
endif
+# custom silent rules
+guestfs_am_v_ocamlc = $(guestfs_am_v_ocamlc_@AM_V@)
+guestfs_am_v_ocamlc_ = $(guestfs_am_v_ocamlc_@AM_DEFAULT_V@)
+guestfs_am_v_ocamlc_0 = @echo " OCAMLC " $@;
+guestfs_am_v_ocamlopt = $(guestfs_am_v_ocamlopt_@AM_V@)
+guestfs_am_v_ocamlopt_ = $(guestfs_am_v_ocamlopt_@AM_DEFAULT_V@)
+guestfs_am_v_ocamlopt_0 = @echo " OCAMLOPT " $@;
+guestfs_am_v_javac = $(guestfs_am_v_javac_@AM_V@)
+guestfs_am_v_javac_ = $(guestfs_am_v_javac_@AM_DEFAULT_V@)
+guestfs_am_v_javac_0 = @echo " JAVAC " $@;
+guestfs_am_v_erlc = $(guestfs_am_v_erlc_@AM_V@)
+guestfs_am_v_erlc_ = $(guestfs_am_v_erlc_@AM_DEFAULT_V@)
+guestfs_am_v_erlc_0 = @echo " ERLC " $@;
+
.mli.cmi:
- $(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
+ $(guestfs_am_v_ocamlc)$(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
.ml.cmo:
- $(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
+ $(guestfs_am_v_ocamlc)$(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
if HAVE_OCAMLOPT
.ml.cmx:
- $(OCAMLFIND) ocamlopt $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
+ $(guestfs_am_v_ocamlopt)$(OCAMLFIND) ocamlopt $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
endif
--
2.7.4
8 years, 4 months
[PATCH v2 1/2] firstboot: rename systemd and sysvinit
by Pino Toscano
Currently we install a systemd service named firstboot.service and a
SysV service named virt-sysprep-firstboot. On systems where systemd is
the init system and runs with the SysV compatibility, the different
names make systemd handle them as different services, and thus trying to
run the firstboot script runner twice.
Rename both the systemd service and the SysV one to guestfs-firstboot:
the new name is less generic, and allows the systemd service to be
shadowed by the SysV service (and thus running just once).
Also cleanup the old services: the old SysV service can be removed
directly, since its former name had "virt-sysprep" in it, and so there
could not be much room for confusion and conflict. Regarding the old
systemd service: to avoid leaving it behind, a simple cleanup strategy
is in place, checking the content of the old firstboot.service to really
ensure we are removing one of our versions of this file.
---
customize/firstboot.ml | 74 ++++++++++++++++++++++++++++++++++++--------------
1 file changed, 54 insertions(+), 20 deletions(-)
diff --git a/customize/firstboot.ml b/customize/firstboot.ml
index f1e5807..52dfbbe 100644
--- a/customize/firstboot.ml
+++ b/customize/firstboot.ml
@@ -82,7 +82,7 @@ fi
let firstboot_service = sprintf "\
[Unit]
-Description=virt-sysprep firstboot service
+Description=libguestfs firstboot service
After=network.target
Before=prefdm.service
@@ -122,10 +122,27 @@ WantedBy=default.target
*)
let unitdir = "/usr/lib/systemd/system" in
g#mkdir_p unitdir;
- let unitfile = sprintf "%s/firstboot.service" unitdir in
+ let unitfile = sprintf "%s/guestfs-firstboot.service" unitdir in
g#write unitfile firstboot_service;
g#mkdir_p "/etc/systemd/system/default.target.wants";
- g#ln_sf unitfile "/etc/systemd/system/default.target.wants"
+ g#ln_sf unitfile "/etc/systemd/system/default.target.wants";
+
+ (* Try to remove the old firstboot.service files. *)
+ let oldunitfile = sprintf "%s/firstboot.service" unitdir in
+ if g#is_file oldunitfile then (
+ g#rm_f "/etc/systemd/system/default.target.wants/firstboot.service";
+ (* Remove the old firstboot.service only if it is one of our
+ * versions. *)
+ match g#checksum "md5" oldunitfile with
+ | "6923781f7a1851b40b32b4960eb9a0fc" (* < 1.23.24 *)
+ | "56fafd8c990fc9d24e5b8497f3582e8d" (* < 1.23.32 *)
+ | "a83767e01cf398e2fd7c8f59d65d320a" (* < 1.25.2 *)
+ | "39aeb10df29104797e3a9aca4db37a6e" ->
+ g#rm oldunitfile
+ | csum ->
+ warning (f_"firstboot: unknown version for old firstboot.service file %s (md5=%s), it will not be removed")
+ oldunitfile csum
+ )
and install_sysvinit_service g = function
| "fedora"|"rhel"|"centos"|"scientificlinux"|"redhat-based" ->
@@ -142,11 +159,16 @@ WantedBy=default.target
g#mkdir_p "/etc/rc.d/rc3.d";
g#mkdir_p "/etc/rc.d/rc5.d";
g#ln_sf (sprintf "%s/firstboot.sh" firstboot_dir)
- "/etc/rc.d/rc2.d/S99virt-sysprep-firstboot";
+ "/etc/rc.d/rc2.d/S99guestfs-firstboot";
g#ln_sf (sprintf "%s/firstboot.sh" firstboot_dir)
- "/etc/rc.d/rc3.d/S99virt-sysprep-firstboot";
+ "/etc/rc.d/rc3.d/S99guestfs-firstboot";
g#ln_sf (sprintf "%s/firstboot.sh" firstboot_dir)
- "/etc/rc.d/rc5.d/S99virt-sysprep-firstboot"
+ "/etc/rc.d/rc5.d/S99guestfs-firstboot";
+
+ (* Try to remove the files of the old service. *)
+ g#rm_f "/etc/rc.d/rc2.d/S99virt-sysprep-firstboot";
+ g#rm_f "/etc/rc.d/rc3.d/S99virt-sysprep-firstboot";
+ g#rm_f "/etc/rc.d/rc5.d/S99virt-sysprep-firstboot"
(* Make firstboot.sh look like a runlevel script to avoid insserv warnings. *)
and install_sysvinit_suse g =
@@ -154,13 +176,19 @@ WantedBy=default.target
g#mkdir_p "/etc/init.d/rc3.d";
g#mkdir_p "/etc/init.d/rc5.d";
g#ln_sf (sprintf "%s/firstboot.sh" firstboot_dir)
- "/etc/init.d/virt-sysprep-firstboot";
- g#ln_sf "../virt-sysprep-firstboot"
- "/etc/init.d/rc2.d/S99virt-sysprep-firstboot";
- g#ln_sf "../virt-sysprep-firstboot"
- "/etc/init.d/rc3.d/S99virt-sysprep-firstboot";
- g#ln_sf "../virt-sysprep-firstboot"
- "/etc/init.d/rc5.d/S99virt-sysprep-firstboot"
+ "/etc/init.d/guestfs-firstboot";
+ g#ln_sf "../guestfs-firstboot"
+ "/etc/init.d/rc2.d/S99guestfs-firstboot";
+ g#ln_sf "../guestfs-firstboot"
+ "/etc/init.d/rc3.d/S99guestfs-firstboot";
+ g#ln_sf "../guestfs-firstboot"
+ "/etc/init.d/rc5.d/S99guestfs-firstboot";
+
+ (* Try to remove the files of the old service. *)
+ g#rm_f "/etc/init.d/virt-sysprep-firstboot";
+ g#rm_f "/etc/init.d/rc2.d/S99virt-sysprep-firstboot";
+ g#rm_f "/etc/init.d/rc3.d/S99virt-sysprep-firstboot";
+ g#rm_f "/etc/init.d/rc5.d/S99virt-sysprep-firstboot"
and install_sysvinit_debian g =
g#mkdir_p "/etc/init.d";
@@ -168,13 +196,19 @@ WantedBy=default.target
g#mkdir_p "/etc/rc3.d";
g#mkdir_p "/etc/rc5.d";
g#ln_sf (sprintf "%s/firstboot.sh" firstboot_dir)
- "/etc/init.d/virt-sysprep-firstboot";
- g#ln_sf "/etc/init.d/virt-sysprep-firstboot"
- "/etc/rc2.d/S99virt-sysprep-firstboot";
- g#ln_sf "/etc/init.d/virt-sysprep-firstboot"
- "/etc/rc3.d/S99virt-sysprep-firstboot";
- g#ln_sf "/etc/init.d/virt-sysprep-firstboot"
- "/etc/rc5.d/S99virt-sysprep-firstboot"
+ "/etc/init.d/guestfs-firstboot";
+ g#ln_sf "/etc/init.d/guestfs-firstboot"
+ "/etc/rc2.d/S99guestfs-firstboot";
+ g#ln_sf "/etc/init.d/guestfs-firstboot"
+ "/etc/rc3.d/S99guestfs-firstboot";
+ g#ln_sf "/etc/init.d/guestfs-firstboot"
+ "/etc/rc5.d/S99guestfs-firstboot";
+
+ (* Try to remove the files of the old service. *)
+ g#rm_f "/etc/init.d/virt-sysprep-firstboot";
+ g#rm_f "/etc/rc2.d/S99virt-sysprep-firstboot";
+ g#rm_f "/etc/rc3.d/S99virt-sysprep-firstboot";
+ g#rm_f "/etc/rc5.d/S99virt-sysprep-firstboot"
end
module Windows = struct
--
2.7.4
8 years, 4 months
[PATCH] firstboot: rename systemd service file
by Pino Toscano
Currently we install a systemd service named firstboot.service and a
SysV service named virt-sysprep-firstboot. On systems where systemd is
the init system and runs with the SysV compatibility, the different
names make systemd handle them as different services, and thus trying to
run the firstboot script runner twice.
Rename the systemd service to virt-sysprep-firstboot as well: other than
being sligtly less generic, it is also shadowed by the SysV service, and
thus run just once. To avoid leaving the old systemd service behind, a
simple cleanup strategy is in place, checking the content of the old
firstboot.service to really ensure we are removing one of our versions
of this file.
---
customize/firstboot.ml | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/customize/firstboot.ml b/customize/firstboot.ml
index f1e5807..6d7b065 100644
--- a/customize/firstboot.ml
+++ b/customize/firstboot.ml
@@ -122,10 +122,27 @@ WantedBy=default.target
*)
let unitdir = "/usr/lib/systemd/system" in
g#mkdir_p unitdir;
- let unitfile = sprintf "%s/firstboot.service" unitdir in
+ let unitfile = sprintf "%s/virt-sysprep-firstboot.service" unitdir in
g#write unitfile firstboot_service;
g#mkdir_p "/etc/systemd/system/default.target.wants";
- g#ln_sf unitfile "/etc/systemd/system/default.target.wants"
+ g#ln_sf unitfile "/etc/systemd/system/default.target.wants";
+
+ (* Try to remove the old firstboot.service files. *)
+ let oldunitfile = sprintf "%s/firstboot.service" unitdir in
+ if g#is_file oldunitfile then (
+ g#rm_f "/etc/systemd/system/default.target.wants/firstboot.service";
+ (* Remove the old firstboot.service only if it is one of our
+ * versions. *)
+ match g#checksum "md5" oldunitfile with
+ | "6923781f7a1851b40b32b4960eb9a0fc" (* < 1.23.24 *)
+ | "56fafd8c990fc9d24e5b8497f3582e8d" (* < 1.23.32 *)
+ | "a83767e01cf398e2fd7c8f59d65d320a" (* < 1.25.2 *)
+ | "39aeb10df29104797e3a9aca4db37a6e" ->
+ g#rm oldunitfile
+ | csum ->
+ warning (f_"firstboot: unknown version for old firstboot.service file %s (md5=%s), it will not be removed")
+ oldunitfile csum
+ )
and install_sysvinit_service g = function
| "fedora"|"rhel"|"centos"|"scientificlinux"|"redhat-based" ->
--
2.7.4
8 years, 4 months
[PATCH] mllib: move _exit from v2v as Exit module
by Pino Toscano
Move the OCaml binding to C _exit to an own module.
Just code motion, adapting v2v in the process.
---
docs/C_SOURCE_FILES | 2 +-
mllib/Makefile.am | 5 ++++-
mllib/exit-c.c | 33 +++++++++++++++++++++++++++++++++
mllib/exit.ml | 19 +++++++++++++++++++
mllib/exit.mli | 20 ++++++++++++++++++++
v2v/Makefile.am | 1 -
v2v/changeuid-c.c | 33 ---------------------------------
v2v/changeuid.ml | 7 ++-----
8 files changed, 79 insertions(+), 41 deletions(-)
create mode 100644 mllib/exit-c.c
create mode 100644 mllib/exit.ml
create mode 100644 mllib/exit.mli
delete mode 100644 v2v/changeuid-c.c
diff --git a/docs/C_SOURCE_FILES b/docs/C_SOURCE_FILES
index 3db4db3..551ce16 100644
--- a/docs/C_SOURCE_FILES
+++ b/docs/C_SOURCE_FILES
@@ -181,6 +181,7 @@ lua/lua-guestfs.c
make-fs/make-fs.c
mllib/dev_t-c.c
mllib/dummy.c
+mllib/exit-c.c
mllib/fsync-c.c
mllib/getopt-c.c
mllib/mkdtemp-c.c
@@ -286,7 +287,6 @@ utils/boot-analysis/boot-analysis.c
utils/boot-benchmark/boot-benchmark.c
utils/qemu-boot/qemu-boot.c
utils/qemu-speed-test/qemu-speed-test.c
-v2v/changeuid-c.c
v2v/domainxml-c.c
v2v/utils-c.c
v2v/xml-c.c
diff --git a/mllib/Makefile.am b/mllib/Makefile.am
index 8f8b5f4..69df1bc 100644
--- a/mllib/Makefile.am
+++ b/mllib/Makefile.am
@@ -32,6 +32,7 @@ SOURCES_MLI = \
common_utils.mli \
curl.mli \
dev_t.mli \
+ exit.mli \
fsync.mli \
getopt.mli \
JSON.mli \
@@ -60,12 +61,14 @@ SOURCES_ML = \
regedit.ml \
StatVFS.ml \
JSON.ml \
- curl.ml
+ curl.ml \
+ exit.ml
SOURCES_C = \
../fish/progress.c \
../fish/uri.c \
dev_t-c.c \
+ exit-c.c \
fsync-c.c \
getopt-c.c \
mkdtemp-c.c \
diff --git a/mllib/exit-c.c b/mllib/exit-c.c
new file mode 100644
index 0000000..eed58a3
--- /dev/null
+++ b/mllib/exit-c.c
@@ -0,0 +1,33 @@
+/* libguestfs OCaml tools common code
+ * Copyright (C) 2009-2016 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.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <caml/mlvalues.h>
+
+extern int guestfs_int_mllib_exit (value rv) __attribute__((noreturn));
+
+int
+guestfs_int_mllib_exit (value rv)
+{
+ _exit (Int_val (rv));
+}
diff --git a/mllib/exit.ml b/mllib/exit.ml
new file mode 100644
index 0000000..e752bfe
--- /dev/null
+++ b/mllib/exit.ml
@@ -0,0 +1,19 @@
+(* libguestfs OCaml tools common code
+ * Copyright (C) 2016 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.
+ *)
+
+external _exit : int -> unit = "guestfs_int_mllib_exit" "noalloc"
diff --git a/mllib/exit.mli b/mllib/exit.mli
new file mode 100644
index 0000000..c1f0ab5
--- /dev/null
+++ b/mllib/exit.mli
@@ -0,0 +1,20 @@
+(* libguestfs OCaml tools common code
+ * Copyright (C) 2016 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 _exit : int -> unit
+(** Call _exit directly, ie. do not run OCaml atexit handlers. *)
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 8fd013d..008c5ba 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -95,7 +95,6 @@ SOURCES_ML = \
SOURCES_C = \
domainxml-c.c \
- changeuid-c.c \
utils-c.c \
xml-c.c
diff --git a/v2v/changeuid-c.c b/v2v/changeuid-c.c
deleted file mode 100644
index 0de5a30..0000000
--- a/v2v/changeuid-c.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/* virt-v2v
- * Copyright (C) 2009-2016 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.
- */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <caml/mlvalues.h>
-
-extern int v2v_exit (value rv) __attribute__((noreturn));
-
-int
-v2v_exit (value rv)
-{
- _exit (Int_val (rv));
-}
diff --git a/v2v/changeuid.ml b/v2v/changeuid.ml
index 07cf6fb..53c0bc3 100644
--- a/v2v/changeuid.ml
+++ b/v2v/changeuid.ml
@@ -33,9 +33,6 @@ type t = {
let create ?uid ?gid () = { uid = uid; gid = gid }
-(* Call _exit directly, ie. do not run OCaml atexit handlers. *)
-external _exit : int -> unit = "v2v_exit" "noalloc"
-
let with_fork { uid = uid; gid = gid } name f =
let pid = fork () in
@@ -46,9 +43,9 @@ let with_fork { uid = uid; gid = gid } name f =
(try f ()
with exn ->
eprintf "%s: changeuid: %s: %s\n%!" prog name (Printexc.to_string exn);
- _exit 1
+ Exit._exit 1
);
- _exit 0
+ Exit._exit 0
);
(* Parent. *)
--
2.7.4
8 years, 4 months
[PATCH] v2v: fixed file_owner function
by Tomáš Golembiovský
What was happening in file_owner function did not match the description
in the comment. When a path is owned by multiple packages the returned
string was in fact a concatenation of the names of all packages that own
it. E.g. for `Linux.is_file_owned g inspect "/etc"` the returned value
was "filesystemyum" (i.e. "filesystem" + "yum").
Signed-off-by: Tomáš Golembiovský <tgolembi(a)redhat.com>
---
v2v/linux.ml | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/v2v/linux.ml b/v2v/linux.ml
index d20194b..aeff5c5 100644
--- a/v2v/linux.ml
+++ b/v2v/linux.ml
@@ -99,14 +99,18 @@ let rec file_owner g inspect path =
(* Although it is possible in RPM for multiple packages to own
* a file, this deliberately only returns one package.
*)
- let cmd = [| "rpm"; "-qf"; "--qf"; "%{NAME}"; path |] in
+ let cmd = [| "rpm"; "-qf"; "--qf"; "%{NAME}\\n"; path |] in
debug "%s" (String.concat " " (Array.to_list cmd));
- (try g#command cmd
+ (try
+ let pkgs = g#command_lines cmd in
+ pkgs.(0)
with Guestfs.Error msg as exn ->
if String.find msg "is not owned" >= 0 then
raise Not_found
else
raise exn
+ | Invalid_argument msg ->
+ raise Not_found
)
| format ->
--
2.9.2
8 years, 4 months
[PATCH] mllib: move which and its exception from dib
by Pino Toscano
Rename it from "tool" to "executable" in the process, but otherwise
it is just code motion (with minimal adjustments in dib).
---
dib/dib.ml | 2 +-
dib/utils.ml | 16 +---------------
mllib/common_utils.ml | 14 ++++++++++++++
mllib/common_utils.mli | 9 +++++++++
4 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/dib/dib.ml b/dib/dib.ml
index de4f242..87af4eb 100644
--- a/dib/dib.ml
+++ b/dib/dib.ml
@@ -297,7 +297,7 @@ $cmd \"$@\"
(try
let loc = which "dib-run-parts" in
do_cp loc (destdir // "fake-bin")
- with Tool_not_found _ ->
+ with Executable_not_found _ ->
let fake_dib_run_parts = "\
#!/bin/sh
echo \"Please install dib-run-parts on the host\"
diff --git a/dib/utils.ml b/dib/utils.ml
index f316264..a2046cb 100644
--- a/dib/utils.ml
+++ b/dib/utils.ml
@@ -21,8 +21,6 @@ open Common_utils
open Printf
-exception Tool_not_found of string (* tool *)
-
let quote = Filename.quote
let unit_GB howmany =
@@ -97,21 +95,9 @@ let rec remove_dups = function
| [] -> []
| x :: xs -> x :: (remove_dups (List.filter ((<>) x) xs))
-let which tool =
- let paths = String.nsplit ":" (Sys.getenv "PATH") in
- let paths = filter_map (
- fun p ->
- let path = p // tool in
- try Unix.access path [Unix.X_OK]; Some path
- with Unix.Unix_error _ -> None
- ) paths in
- match paths with
- | [] -> raise (Tool_not_found tool)
- | x :: _ -> x
-
let require_tool tool =
try ignore (which tool)
- with Tool_not_found tool ->
+ with Executable_not_found tool ->
error (f_"%s needed but not found") tool
let do_cp src destdir =
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index e7ee84a..14f4935 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -142,6 +142,8 @@ module String = struct
)
end
+exception Executable_not_found of string (* executable *)
+
let (//) = Filename.concat
let ( +^ ) = Int64.add
@@ -316,6 +318,18 @@ let protect ~f ~finally =
finally ();
match r with Either ret -> ret | Or exn -> raise exn
+let which executable =
+ let paths = String.nsplit ":" (Sys.getenv "PATH") in
+ let paths = filter_map (
+ fun p ->
+ let path = p // executable in
+ try Unix.access path [Unix.X_OK]; Some path
+ with Unix.Unix_error _ -> None
+ ) paths in
+ match paths with
+ | [] -> raise (Executable_not_found executable)
+ | x :: _ -> x
+
(* Program name. *)
let prog = Filename.basename Sys.executable_name
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index de97815..4959de6 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -78,6 +78,10 @@ module String : sig
end
(** Override the String module from stdlib. *)
+(** Exception thrown by [which] when the specified executable is not found
+ in [$PATH]. *)
+exception Executable_not_found of string (* executable *)
+
val ( // ) : string -> string -> string
(** Concatenate directory and filename. *)
@@ -379,3 +383,8 @@ val inspect_mount_root_ro : Guestfs.guestfs -> string -> unit
val is_btrfs_subvolume : Guestfs.guestfs -> string -> bool
(** Checks if a filesystem is a btrfs subvolume. *)
+
+val which : string -> string
+(** Return the full path of the specified executable from [$PATH].
+
+ Throw [Executable_not_found] if not available. *)
--
2.7.4
8 years, 4 months