Blob Blame History Raw
From 42c6c4c7130e4cc88458428edb0fb4654c52c2ab Mon Sep 17 00:00:00 2001
From: Pino Toscano <ptoscano@redhat.com>
Date: Wed, 3 Aug 2016 15:01:59 +0200
Subject: [PATCH] mllib: move _exit from v2v as Exit module

Move the OCaml binding to C _exit to an own module.

Just code motion, adapting v2v in the process.

(cherry picked from commit 5077c020469827e104995cb2143d6d4eda981b9f)
---
 mllib/Makefile.am |  5 ++++-
 mllib/exit-c.c    | 33 +++++++++++++++++++++++++++++++++
 mllib/exit.ml     | 19 +++++++++++++++++++
 mllib/exit.mli    | 20 ++++++++++++++++++++
 po/POTFILES       |  2 +-
 po/POTFILES-ml    |  1 +
 v2v/Makefile.am   |  3 ++-
 v2v/changeuid-c.c | 33 ---------------------------------
 v2v/changeuid.ml  |  7 ++-----
 9 files changed, 82 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/mllib/Makefile.am b/mllib/Makefile.am
index 8807d86..22ee5db 100644
--- a/mllib/Makefile.am
+++ b/mllib/Makefile.am
@@ -30,6 +30,7 @@ SOURCES_MLI = \
 	common_utils.mli \
 	curl.mli \
 	dev_t.mli \
+	exit.mli \
 	fsync.mli \
 	JSON.mli \
 	mkdtemp.mli \
@@ -55,12 +56,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 \
 	mkdtemp-c.c \
 	progress-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/po/POTFILES b/po/POTFILES
index 98d4623..756fc5e 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -265,6 +265,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/mkdtemp-c.c
 mllib/progress-c.c
@@ -369,7 +370,6 @@ utils/boot-benchmark/boot-benchmark-range.pl
 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/po/POTFILES-ml b/po/POTFILES-ml
index f5e8eba..8b1cad7 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -46,6 +46,7 @@ mllib/common_utils.ml
 mllib/common_utils_tests.ml
 mllib/curl.ml
 mllib/dev_t.ml
+mllib/exit.ml
 mllib/fsync.ml
 mllib/guestfs_config.ml
 mllib/libdir.ml
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 73a2d68..0486cfe 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -116,8 +116,8 @@ SOURCES_C = \
 	../mllib/dev_t-c.c \
 	../mllib/mkdtemp-c.c \
 	../mllib/statvfs-c.c \
+	../mllib/exit-c.c \
 	domainxml-c.c \
-	changeuid-c.c \
 	utils-c.c \
 	xml-c.c
 
@@ -146,6 +146,7 @@ BOBJECTS = \
 	$(top_builddir)/mllib/mkdtemp.cmo \
 	$(top_builddir)/mllib/JSON.cmo \
 	$(top_builddir)/mllib/StatVFS.cmo \
+	$(top_builddir)/mllib/exit.cmo \
 	$(top_builddir)/mllib/curl.cmo \
 	$(top_builddir)/customize/customize_utils.cmo \
 	$(top_builddir)/customize/firstboot.cmo \
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. *)
-- 
1.8.3.1