Pino Toscano
2017-Feb-21 14:39 UTC
[Libguestfs] [PATCH 1/3] dib: unset all temporary dirs envvars in fake-sudo
The real sudo does it as well, and leaving them when preserving the environment (-E) maybe breaks the applications, as e.g. chroot will have a TMPDIR path pointing outside of it. --- dib/dib.ml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dib/dib.ml b/dib/dib.ml index df83ba1..d15cd19 100644 --- a/dib/dib.ml +++ b/dib/dib.ml @@ -301,6 +301,11 @@ if [ -z \"$preserve_env\" ]; then esac done fi +# TMPDIR needs to be unset, regardless of -E +unset TMPDIR +# ... and do that also to the other \"TMPDIR\"-like variables +unset TMP +unset TMP_DIR cmd=$1 shift -- 2.9.3
Pino Toscano
2017-Feb-21 14:39 UTC
[Libguestfs] [PATCH 2/3] dib: handle lack of phases when reloading scripts list
Commit 8ee51ee39603d8a1117c471e6660bf605c7d6b3a re-scans for the available scripts when running certain phases; OTOH, some of them may be missing, usually due to the lack of scripts for that phase in the selected set of elements. Indeed, if there is no directory for a phase, safely raise Not_found so the case is handled as if the phase was missing in the final_hooks Hashtbl. --- dib/dib.ml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dib/dib.ml b/dib/dib.ml index d15cd19..bcb81c0 100644 --- a/dib/dib.ml +++ b/dib/dib.ml @@ -649,7 +649,12 @@ let main () *) match hook with | "pre-install.d" | "install.d" | "post-install.d" | "finalise.d" -> - load_scripts g ("/tmp/aux/hooks/" ^ hook) + let scripts_path = "/tmp/aux/hooks/" ^ hook in + (* Cleanly handle cases when the phase directory does not exist. *) + if g#is_dir ~followsymlinks:true scripts_path then + load_scripts g scripts_path + else + raise Not_found | _ -> Hashtbl.find final_hooks hook in if debug >= 1 then ( -- 2.9.3
Pino Toscano
2017-Feb-21 14:39 UTC
[Libguestfs] [PATCH 3/3] dib: rename "aux" to "in_target.aux"
Sadly, there are elements (hello "gentoo"!) that, during the cleanup.d phase, wipe out almost everything in the /tmp of the guest, including the /tmp/aux where virt-dib mounts the auxiliary data. Since that removal excludes things starting with "in_target" (mostly to avoid wiping the "in_target.d" that disk-image-create itself sets up, then rename our "aux" subdirectory to "in_target.aux" to work it around. Hopefully, the "gentoo" element will be fixed upstream: https://review.openstack.org/#/c/436101/ --- dib/dib.ml | 62 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/dib/dib.ml b/dib/dib.ml index bcb81c0..5713bc6 100644 --- a/dib/dib.ml +++ b/dib/dib.ml @@ -176,8 +176,8 @@ shift %s # system variables -export HOME=$mysysroot/tmp/aux/perm/home -export PATH=$mysysroot/tmp/aux/hooks/bin:$PATH +export HOME=$mysysroot/tmp/in_target.aux/perm/home +export PATH=$mysysroot/tmp/in_target.aux/hooks/bin:$PATH export TMP=$mysysroot/tmp export TMPDIR=$TMP export TMP_DIR=$TMP @@ -190,12 +190,12 @@ export IMAGE_NAME=\"%s\" export DIB_IMAGE_ROOT_FS_UUID=%s export DIB_IMAGE_CACHE=$HOME/.cache/image-create export DIB_ROOT_LABEL=\"%s\" -export _LIB=$mysysroot/tmp/aux/lib -export _PREFIX=$mysysroot/tmp/aux/elements +export _LIB=$mysysroot/tmp/in_target.aux/lib +export _PREFIX=$mysysroot/tmp/in_target.aux/elements export ARCH=%s -export TMP_HOOKS_PATH=$mysysroot/tmp/aux/hooks +export TMP_HOOKS_PATH=$mysysroot/tmp/in_target.aux/hooks export DIB_ARGS=\"%s\" -export DIB_MANIFEST_SAVE_DIR=\"$mysysroot/tmp/aux/out/${IMAGE_NAME}.d\" +export DIB_MANIFEST_SAVE_DIR=\"$mysysroot/tmp/in_target.aux/out/${IMAGE_NAME}.d\" export IMAGE_BLOCK_DEVICE=$blockdev export IMAGE_ELEMENT=\"%s\" export DIB_ENV=%s @@ -204,11 +204,11 @@ export DIB_NO_TMPFS=1 export FS_TYPE=%s export DIB_CHECKSUM=%s -export TMP_BUILD_DIR=$mysysroot/tmp/aux -export TMP_IMAGE_DIR=$mysysroot/tmp/aux +export TMP_BUILD_DIR=$mysysroot/tmp/in_target.aux +export TMP_IMAGE_DIR=$mysysroot/tmp/in_target.aux if [ -n \"$mysysroot\" ]; then - export PATH=$mysysroot/tmp/aux/fake-bin:$PATH + export PATH=$mysysroot/tmp/in_target.aux/fake-bin:$PATH source $_LIB/die else export PATH=\"$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\" @@ -376,7 +376,7 @@ let timed_run fn let run_parts ~debug ~sysroot ~blockdev ~log_file ?(new_wd = "") (g : Guestfs.guestfs) hook_name scripts - let hook_dir = "/tmp/aux/hooks/" ^ hook_name in + let hook_dir = "/tmp/in_target.aux/hooks/" ^ hook_name in let scripts = List.sort digit_prefix_compare scripts in let outbuf = Buffer.create 16384 in let timings = Hashtbl.create 13 in @@ -393,11 +393,11 @@ let run_parts ~debug ~sysroot ~blockdev ~log_file ?(new_wd = "") let outstr match sysroot with | In -> - g#sh (sprintf "/tmp/aux/run-and-log.sh '%s' '' '' '%s' '%s' '%s' '%s'" log_file blockdev hook_dir new_wd x) + g#sh (sprintf "/tmp/in_target.aux/run-and-log.sh '%s' '' '' '%s' '%s' '%s' '%s'" log_file blockdev hook_dir new_wd x) | Out -> - g#debug "sh" [| "/sysroot/tmp/aux/run-and-log.sh"; "/sysroot" ^ log_file; "/sysroot"; "/sysroot"; blockdev; "/sysroot" ^ hook_dir; new_wd; x |] + g#debug "sh" [| "/sysroot/tmp/in_target.aux/run-and-log.sh"; "/sysroot" ^ log_file; "/sysroot"; "/sysroot"; blockdev; "/sysroot" ^ hook_dir; new_wd; x |] | Subroot -> - g#debug "sh" [| "/sysroot/tmp/aux/run-and-log.sh"; "/sysroot" ^ log_file; "/sysroot/subroot"; "/sysroot"; blockdev; "/sysroot" ^ hook_dir; new_wd; x |] in + g#debug "sh" [| "/sysroot/tmp/in_target.aux/run-and-log.sh"; "/sysroot" ^ log_file; "/sysroot/subroot"; "/sysroot"; blockdev; "/sysroot" ^ hook_dir; new_wd; x |] in out := outstr; Buffer.add_string outbuf outstr in let delta_t = timed_run run in @@ -419,7 +419,7 @@ let run_parts_host ~debug (g : Guestfs.guestfs) hook_name base_mount_dir scripts (* Point to the in-guest hooks, so that changes there can affect * other phases. *) - let hooks_dir = mount_dir // "tmp" // "aux" // "hooks" in + let hooks_dir = mount_dir // "tmp" // "in_target.aux" // "hooks" in let hook_dir = hooks_dir // hook_name in do_mkdir mount_dir; @@ -479,7 +479,7 @@ let run_install_packages ~debug ~blockdev ~log_file let pkgs_string = String.concat " " packages in message (f_"Installing: %s") pkgs_string; g#write_append log_file (sprintf "Installing %s...\n" pkgs_string); - let out = g#sh (sprintf "/tmp/aux/run-and-log.sh '%s' '' '' '%s' '/tmp/aux' '' 'install-packages.sh'" log_file blockdev) in + let out = g#sh (sprintf "/tmp/in_target.aux/run-and-log.sh '%s' '' '' '%s' '/tmp/in_target.aux' '' 'install-packages.sh'" log_file blockdev) in let out = ensure_trailing_newline out in if debug >= 1 then ( printf "%s%!" out; @@ -513,7 +513,7 @@ let main () let tmpdir = Mkdtemp.temp_dir "dib." "" in rmdir_on_exit tmpdir; - let auxtmpdir = tmpdir // "aux" in + let auxtmpdir = tmpdir // "in_target.aux" in do_mkdir auxtmpdir; let hookstmpdir = auxtmpdir // "hooks" in do_mkdir (hookstmpdir // "environment.d"); (* Just like d-i-b does. *) @@ -581,7 +581,7 @@ let main () *) let final_hooks = load_hooks ~debug hookstmpdir in - let log_file = "/tmp/aux/perm/" ^ (log_filename ()) in + let log_file = "/tmp/in_target.aux/perm/" ^ (log_filename ()) in let arch match cmdline.arch with @@ -649,7 +649,7 @@ let main () *) match hook with | "pre-install.d" | "install.d" | "post-install.d" | "finalise.d" -> - let scripts_path = "/tmp/aux/hooks/" ^ hook in + let scripts_path = "/tmp/in_target.aux/hooks/" ^ hook in (* Cleanly handle cases when the phase directory does not exist. *) if g#is_dir ~followsymlinks:true scripts_path then load_scripts g scripts_path @@ -715,7 +715,7 @@ let main () Output_format.check_formats_appliance_prerequisites cmdline.formats g; - (* Prepare the /aux partition. *) + (* Prepare the /in_target.aux partition. *) g#mkfs "ext2" "/dev/sdb"; g#mount "/dev/sdb" "/"; @@ -723,7 +723,7 @@ let main () copy_in g cmdline.basepath "/lib"; g#umount "/"; - (* Prepare the /aux/perm partition. *) + (* Prepare the /in_target.aux/perm partition. *) let drive_partition match cmdline.drive with | None -> @@ -746,9 +746,9 @@ let main () g, fn, fmt, drive_partition in let mount_aux () - g#mkmountpoint "/tmp/aux"; - g#mount "/dev/sdb" "/tmp/aux"; - g#mount drive_partition "/tmp/aux/perm" in + g#mkmountpoint "/tmp/in_target.aux"; + g#mount "/dev/sdb" "/tmp/in_target.aux"; + g#mount drive_partition "/tmp/in_target.aux/perm" in (* Small kludge: try to umount all first: if that fails, use lsof and fuser * to find out what might have caused the failure, run udevadm to try @@ -846,8 +846,8 @@ let main () run_hook_subroot "root.d"; g#sync (); - g#umount "/tmp/aux/perm"; - g#umount "/tmp/aux"; + g#umount "/tmp/in_target.aux/perm"; + g#umount "/tmp/in_target.aux"; g#rm_rf "/tmp"; let subroot_items let l = Array.to_list (g#ls "/subroot") in @@ -861,7 +861,7 @@ let main () (* Check /tmp exists already. *) ignore (g#is_dir "/tmp"); mount_aux (); - g#ln_s "aux/hooks" "/tmp/in_target.d"; + g#ln_s "in_target.aux/hooks" "/tmp/in_target.d"; run_hook_host "extra-data.d"; @@ -880,14 +880,14 @@ let main () checked_umount_all (); flush_all (); g#mount blockdev "/"; - (* Check /tmp/aux still exists. *) - ignore (g#is_dir "/tmp/aux"); - g#mount "/dev/sdb" "/tmp/aux"; - g#mount drive_partition "/tmp/aux/perm"; + (* Check /tmp/in_target.aux still exists. *) + ignore (g#is_dir "/tmp/in_target.aux"); + g#mount "/dev/sdb" "/tmp/in_target.aux"; + g#mount drive_partition "/tmp/in_target.aux/perm"; run_hook_in "finalise.d"; - let out_dir = "/tmp/aux/out/" ^ image_basename_d in + let out_dir = "/tmp/in_target.aux/out/" ^ image_basename_d in run_hook_out ~new_wd:out_dir "cleanup.d"; -- 2.9.3
Richard W.M. Jones
2017-Feb-21 15:25 UTC
Re: [Libguestfs] [PATCH 3/3] dib: rename "aux" to "in_target.aux"
TMP and TMP_DIR are really a thing? Anyway, yes, ACK series, thanks. 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
Possibly Parallel Threads
- [PATCH] mllib: move _exit from v2v as Exit module
- [PATCH 3/3] dib: rename "aux" to "in_target.aux"
- [PATCH 00/10] dib/API: improvements and fixes
- [PATCH 0/5] dib: initial work to support d-i-b 2.0
- [PATCH 1/2] sparsify: Refactor handling of checks of copying mode / --in-place.