[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH V4] virt-sysprep:add logging feature



On Wed, Apr 11, 2012 at 02:27:49PM +0800, Wanlong Gao wrote:
> Hi Rich,
> 
> I did with your suggestions, please help reviewing.
> 
> I got a compiling error,
> -
> File "sysprep_operation.mli", line 23, characters 17-19:
> Error: Unbound type parameter 'a
> make: *** [sysprep_operation.cmi] Error 2
> make: Leaving directory `/work/git/libguestfs/sysprep'
> -

It turns out that it's hard to make the types work out properly with
this method of passing the 'debug' function around.  We would need to
use some feature of OCaml 3.12, which then wouldn't be compatible with
RHEL 6.

Try the attached patch instead, which is in any case much simpler.

I'm still a bit confused about the purpose of adding logging.  How is
this better than using the -x option?

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org
>From d8dedad8770e4041fa52cfd09fea85868446fa6d Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones redhat com>
Date: Wed, 11 Apr 2012 11:10:16 +0100
Subject: [PATCH] Add logging.

---
 sysprep/main.ml                         |    1 +
 sysprep/sysprep_operation_cron_spool.ml |    7 ++++++-
 sysprep/utils.ml                        |    4 ++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/sysprep/main.ml b/sysprep/main.ml
index d06b0d2..f1d20b2 100644
--- a/sysprep/main.ml
+++ b/sysprep/main.ml
@@ -105,6 +105,7 @@ let debug_gc, operations, g, selinux_relabel =
     "--enable",  Arg.String set_enable,     "operations Enable specific operations";
     "--format",  Arg.Set_string format,     "format Set format (default: auto)";
     "--list-operations", Arg.Unit list_operations, " List supported operations";
+    "--log",     Arg.Unit set_log,          " Enable operation logging";
     "--selinux-relabel", Arg.Unit force_selinux_relabel, " Force SELinux relabel";
     "--no-selinux-relabel", Arg.Unit no_force_selinux_relabel, " Never do SELinux relabel";
     "-v",        Arg.Set verbose,           " Enable debugging messages";
diff --git a/sysprep/sysprep_operation_cron_spool.ml b/sysprep/sysprep_operation_cron_spool.ml
index e67688b..c544731 100644
--- a/sysprep/sysprep_operation_cron_spool.ml
+++ b/sysprep/sysprep_operation_cron_spool.ml
@@ -21,7 +21,12 @@ open Sysprep_operation
 module G = Guestfs
 
 let cron_spool_perform g root =
-  Array.iter g#rm_rf (g#glob_expand "/var/spool/cron/*");
+  let files = g#glob_expand "/var/spool/cron/*" in
+  Array.iter (
+    fun file ->
+      g#rm_rf file;
+      Utils.log "deleted %s" file
+  ) files;
   []
 
 let cron_spool_op = {
diff --git a/sysprep/utils.ml b/sysprep/utils.ml
index dfac57d..1cb32b3 100644
--- a/sysprep/utils.ml
+++ b/sysprep/utils.ml
@@ -69,3 +69,7 @@ let string_random8 =
           String.make 1 c
       ) [1;2;3;4;5;6;7;8]
     )
+
+let f = ref false
+let log fs = ksprintf (fun str -> if !f then prerr_endline str) fs
+let set_log () = f := true
-- 
1.7.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]