[CRIU] [PATCH 1/2] p.haul: handle output of execed utilities properly

Nikita Spiridonov nspiridonov at odin.com
Thu Oct 1 05:31:12 PDT 2015


Handle output of execed utilities properly in order to append
their output to logs when io redirected to file.

Signed-off-by: Nikita Spiridonov <nspiridonov at odin.com>
---
 phaul/p_haul_vz.py |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/phaul/p_haul_vz.py b/phaul/p_haul_vz.py
index 4d799e3..7710cde 100644
--- a/phaul/p_haul_vz.py
+++ b/phaul/p_haul_vz.py
@@ -166,8 +166,11 @@ class p_haul_type:
 			# Run vzctl restore
 			logging.info("Starting vzctl restore")
 			proc = subprocess.Popen([vzctl_bin, "restore", self._ctid,
-				"--dumpfile", img.image_dir()])
-			if proc.wait() != 0:
+				"--dumpfile", img.image_dir()],
+				stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+			proc_output = proc.communicate()[0]
+			logging.info(proc_output)
+			if proc.returncode != 0:
 				raise Exception("Restore failed ({0})".format(proc.returncode))
 		finally:
 			# Remove restore extra arguments
@@ -185,7 +188,11 @@ class p_haul_type:
 
 	def mount(self):
 		logging.info("Mounting CT root to %s", self._ct_root)
-		os.system("vzctl mount {0}".format(self._ctid))
+		logging.info("Starting vzctl mount")
+		proc = subprocess.Popen(["vzctl", "mount", self._ctid],
+			stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+		proc_output = proc.communicate()[0]
+		logging.info(proc_output)
 		self._fs_mounted = True
 		return self._ct_root
 
@@ -193,7 +200,10 @@ class p_haul_type:
 		if self._fs_mounted:
 			logging.info("Umounting CT root")
 			logging.info("Starting vzctl umount")
-			os.system("vzctl umount {0}".format(self._ctid))
+			proc = subprocess.Popen(["vzctl", "umount", self._ctid],
+				stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+			proc_output = proc.communicate()[0]
+			logging.info(proc_output)
 			self._fs_mounted = False
 
 	def get_fs(self):
-- 
1.7.1



More information about the CRIU mailing list