Blame SOURCES/0069-customize-port-do_run-to-run_in_guest_command.patch

da373f
From 02f8969558ecadc13726068ccb732595c5d29565 Mon Sep 17 00:00:00 2001
3efd08
From: Pino Toscano <ptoscano@redhat.com>
3efd08
Date: Mon, 4 May 2020 11:55:41 +0200
3efd08
Subject: [PATCH] customize: port do_run to run_in_guest_command
3efd08
3efd08
Make use of the new helper function in Tools_utils to run commands in
3efd08
the guest.
3efd08
3efd08
(cherry picked from commit b25e3495f522378f59d201526d7d2d02c2bf6f3f)
3efd08
---
da373f
 customize/customize_run.ml | 46 +++++---------------------------------
da373f
 1 file changed, 6 insertions(+), 40 deletions(-)
3efd08
3efd08
diff --git a/customize/customize_run.ml b/customize/customize_run.ml
3efd08
index 3eacdaca0..f2ee20413 100644
3efd08
--- a/customize/customize_run.ml
3efd08
+++ b/customize/customize_run.ml
3efd08
@@ -30,12 +30,6 @@ open Append_line
3efd08
 module G = Guestfs
3efd08
 
3efd08
 let run (g : G.guestfs) root (ops : ops) =
3efd08
-  (* Is the host_cpu compatible with the guest arch?  ie. Can we
3efd08
-   * run commands in this guest?
3efd08
-   *)
3efd08
-  let guest_arch = g#inspect_get_arch root in
3efd08
-  let guest_arch_compatible = guest_arch_compatible guest_arch in
3efd08
-
3efd08
   (* Based on the guest type, choose a log file location. *)
3efd08
   let logfile =
3efd08
     match g#inspect_get_type root with
3efd08
@@ -54,42 +48,14 @@ let run (g : G.guestfs) root (ops : ops) =
3efd08
 
3efd08
   (* Useful wrapper for scripts. *)
3efd08
   let do_run ~display ?(warn_failed_no_network = false) cmd =
3efd08
-    if not guest_arch_compatible then
3efd08
+    let incompatible_fn () =
3efd08
+      let guest_arch = g#inspect_get_arch root in
3efd08
       error (f_"host cpu (%s) and guest arch (%s) are not compatible, so you cannot use command line options that involve running commands in the guest.  Use --firstboot scripts instead.")
3efd08
-            Guestfs_config.host_cpu guest_arch;
da373f
+            Guestfs_config.host_cpu guest_arch
da373f
+    in
da373f
 
3efd08
-    (* Add a prologue to the scripts:
3efd08
-     * - Pass environment variables through from the host.
3efd08
-     * - Send stdout and stderr to a log file so we capture all output
3efd08
-     *   in error messages.
3efd08
-     * - Use setarch when running x86_64 host + i686 guest.
3efd08
-     * Also catch errors and dump the log file completely on error.
3efd08
-     *)
3efd08
-    let env_vars =
3efd08
-      List.filter_map (
3efd08
-        fun name ->
3efd08
-          try Some (sprintf "export %s=%s" name (quote (Sys.getenv name)))
3efd08
-          with Not_found -> None
3efd08
-      ) [ "http_proxy"; "https_proxy"; "ftp_proxy"; "no_proxy" ] in
3efd08
-    let env_vars = String.concat "\n" env_vars ^ "\n" in
3efd08
-
3efd08
-    let cmd =
3efd08
-      match Guestfs_config.host_cpu, guest_arch with
3efd08
-      | "x86_64", ("i386"|"i486"|"i586"|"i686") ->
3efd08
-        sprintf "setarch i686 <<\"__EOCMD\"
3efd08
-%s
3efd08
-__EOCMD
3efd08
-" cmd
3efd08
-      | _ -> cmd in
3efd08
-
3efd08
-    let cmd = sprintf "\
3efd08
-exec >>%s 2>&1
3efd08
-%s
3efd08
-%s
3efd08
-" (quote logfile) env_vars cmd in
3efd08
-
3efd08
-    debug "running command:\n%s" cmd;
3efd08
-    try ignore (g#sh cmd)
3efd08
+    try
3efd08
+      run_in_guest_command g root ~logfile ~incompatible_fn cmd
3efd08
     with
3efd08
       G.Error msg ->
3efd08
         debug_logfile ();
3efd08
-- 
da373f
2.18.4
3efd08