[CRIU] [PATCH 2/3] lib/py: allow to execute page-server as a child process

Andrei Vagin avagin at openvz.org
Tue May 16 22:07:12 PDT 2017


From: Andrei Vagin <avagin at virtuozzo.com>

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 lib/py/criu.py | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/lib/py/criu.py b/lib/py/criu.py
index c4a09ea..f10dbc0 100644
--- a/lib/py/criu.py
+++ b/lib/py/criu.py
@@ -195,6 +195,7 @@ class criu:
 	def __init__(self):
 		self.use_binary('criu')
 		self.opts = rpc.criu_opts()
+		self.sk = None
 
 	def use_sk(self, sk_name):
 		"""
@@ -227,13 +228,20 @@ class criu:
 			daemon = True
 
 		try:
-			s = self._comm.connect(daemon)
+			if not self.sk:
+				s = self._comm.connect(daemon)
+			else:
+				s = self.sk
+
+			if req.keep_open:
+				self.sk = s
 
 			s.send(req.SerializeToString())
 
 			buf = s.recv(len(s.recv(1, socket.MSG_TRUNC | socket.MSG_PEEK)))
 
-			self._comm.disconnect()
+			if not req.keep_open:
+				self._comm.disconnect()
 
 			resp = rpc.criu_resp()
 			resp.ParseFromString(buf)
@@ -283,3 +291,28 @@ class criu:
 			raise CRIUExceptionExternal(req.type, resp.type, resp.cr_errno)
 
 		return resp.restore
+
+	def page_server_chld(self):
+		req		= rpc.criu_req()
+		req.type	= rpc.PAGE_SERVER_CHLD
+		req.opts.MergeFrom(self.opts)
+		req.keep_open   = True
+
+		resp = self._send_req_and_recv_resp(req)
+
+		if not resp.success:
+			raise CRIUExceptionExternal(req.type, resp.type, resp.cr_errno)
+
+		return resp.ps
+
+	def wait_pid(self, pid):
+		req		= rpc.criu_req()
+		req.type	= rpc.WAIT_PID
+		req.pid	 = pid
+
+		resp = self._send_req_and_recv_resp(req)
+
+		if not resp.success:
+			raise CRIUExceptionExternal(req.type, resp.type, resp.cr_errno)
+
+		return resp.status
-- 
2.9.3



More information about the CRIU mailing list