From de656448f7949d2b04e75455d5a2233d0c5856b9 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sun, 1 Apr 2012 20:00:06 +0100 Subject: sysprep: script: Wait for child process to exit. --- sysprep/sysprep_operation_script.ml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/sysprep/sysprep_operation_script.ml b/sysprep/sysprep_operation_script.ml index a6591759..5e47733b 100644 --- a/sysprep/sysprep_operation_script.ml +++ b/sysprep/sysprep_operation_script.ml @@ -52,13 +52,26 @@ let rec script_perform (g : Guestfs.guestfs) root = g#mount_local scriptdir; (* Run the script(s)/program(s). *) - run_scripts scriptdir scripts; + let pid = run_scripts scriptdir scripts in (* Run FUSE. *) g#mount_local_run (); + let ok = + match snd (waitpid [] pid) with + | WEXITED 0 -> true + | WEXITED i -> + eprintf "virt-sysprep: script: failed (code %d)\n" i; + false + | WSIGNALED i + | WSTOPPED i -> + eprintf "virt-sysprep: script: killed by signal (%d)\n" i; + false in + (* Remote temporary directory / mountpoint. *) - if cleanup then rmdir scriptdir + if cleanup then rmdir scriptdir; + + if not ok then failwith "script failed" ); [] @@ -87,7 +100,8 @@ trap sysprep_unmount INT TERM QUIT EXIT ERR\n" (Filename.quote mp) ^ if pid = 0 then ( (* child *) chdir mp; execv sh args - ) + ); + pid let script_op = { name = "script"; -- cgit