Re: [Libguestfs] [PATCH] mllib: move _exit from v2v as Exit module

Richard W.M. Jones
2016-08-03T15:21:37Z

On Wed, Aug 03, 2016 at 04:49:42PM +0200, Pino Toscano
wrote:
> 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
>
> _______________________________________________
> Libguestfs mailing list
> Libguestfs@redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

ACK

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.