Commit 397df9c0 authored by Andrei Vagin's avatar Andrei Vagin

lib/py: allow to execute page-server as a child process

Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent ebd64bdd
...@@ -195,6 +195,7 @@ class criu: ...@@ -195,6 +195,7 @@ class criu:
def __init__(self): def __init__(self):
self.use_binary('criu') self.use_binary('criu')
self.opts = rpc.criu_opts() self.opts = rpc.criu_opts()
self.sk = None
def use_sk(self, sk_name): def use_sk(self, sk_name):
""" """
...@@ -227,12 +228,19 @@ class criu: ...@@ -227,12 +228,19 @@ class criu:
daemon = True daemon = True
try: try:
if not self.sk:
s = self._comm.connect(daemon) s = self._comm.connect(daemon)
else:
s = self.sk
if req.keep_open:
self.sk = s
s.send(req.SerializeToString()) s.send(req.SerializeToString())
buf = s.recv(len(s.recv(1, socket.MSG_TRUNC | socket.MSG_PEEK))) buf = s.recv(len(s.recv(1, socket.MSG_TRUNC | socket.MSG_PEEK)))
if not req.keep_open:
self._comm.disconnect() self._comm.disconnect()
resp = rpc.criu_resp() resp = rpc.criu_resp()
...@@ -283,3 +291,28 @@ class criu: ...@@ -283,3 +291,28 @@ class criu:
raise CRIUExceptionExternal(req.type, resp.type, resp.cr_errno) raise CRIUExceptionExternal(req.type, resp.type, resp.cr_errno)
return resp.restore 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment