def _send_req_and_recv_resp(self, req): """ As simple as send request and receive response. """ # In case of self-dump we need to spawn criu swrk detached # from our current process, as criu has a hard time separating # process resources from its own if criu is located in a same # process tree it is trying to dump. daemon = False if req.type == rpc.DUMP and not req.opts.HasField('pid'): daemon = True try: s = self._comm.connect(daemon) s.send(req.SerializeToString()) buf = s.recv(len(s.recv(1, socket.MSG_TRUNC | socket.MSG_PEEK))) self._comm.disconnect() resp = rpc.criu_resp() resp.ParseFromString(buf) except Exception as e: raise CRIUExceptionInternal(req.type, str(e)) return resp
def do_rpc(s, req): # Send request s.send(req.SerializeToString()) # Recv response resp = rpc.criu_resp() MAX_MSG_SIZE = 1024 resp.ParseFromString(s.recv(MAX_MSG_SIZE)) s.close() return resp
# Create criu msg, set it's type to dump request # and set dump options. Checkout more options in protobuf/rpc.proto req = rpc.criu_req() req.type = rpc.RESTORE req.opts.images_dir_fd = os.open(args['dir'], os.O_DIRECTORY) # As the dumped process is running with setsid this should not # be necessary. There seems to be a problem for this testcase # in combination with alpine's setsid. # The dump is now done with -j and the restore also. req.opts.shell_job = True # Send request s.send(req.SerializeToString()) # Recv response resp = rpc.criu_resp() MAX_MSG_SIZE = 1024 resp.ParseFromString(s.recv(MAX_MSG_SIZE)) if resp.type != rpc.RESTORE: print('Unexpected msg type') sys.exit(-1) else: if resp.success: print('Restore success') else: print('Restore fail') sys.exit(-1) print("PID of the restored program is %d\n" %(resp.restore.pid))
def recv_resp(self): resp = rpc.criu_resp() resp.ParseFromString(self.s.recv(self._MAX_MSG_SIZE)) return resp
# Connect to service socket s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET) s.connect(args['socket']) # Start page-server print 'Starting page-server' req = rpc.criu_req() req.type = rpc.PAGE_SERVER req.opts.log_file = 'page-server.log' req.opts.log_level = 4 req.opts.images_dir_fd = os.open(args['dir'], os.O_DIRECTORY) s.send(req.SerializeToString()) resp = rpc.criu_resp() MAX_MSG_SIZE = 1024 resp.ParseFromString(s.recv(MAX_MSG_SIZE)) if resp.type != rpc.PAGE_SERVER: print 'Unexpected msg type' sys.exit(1) else: if resp.success: # check if pid even exists try: os.kill(resp.ps.pid, 0) except OSError as err: if err.errno == errno.ESRCH: print 'No process with page-server pid %d' %(resp.ps.pid) else:
def recv_resp(self): resp = cr_rpc.criu_resp() resp.ParseFromString(self.cs.recv(1024)) return resp