ó k°x]c@sùddlZddlZddlZddlZddlZddljZddd„ƒYZdefd„ƒYZ defd„ƒYZ defd „ƒYZ d e fd „ƒYZ d e fd „ƒYZde fd„ƒYZddd„ƒYZdS(iÿÿÿÿNt _criu_commcBsDeZdZdZdZdZdZdZdZ d„Z d„Z RS(s/ Base class for communication classes. iiicCsdS(s¢ Connect to criu and return socket object. daemon -- is for whether or not criu should daemonize if executing criu from binary(comm_bin). N((tselftdaemon((s//usr/lib/python2.7/site-packages/pycriu/criu.pytconnectscCsdS(s' Disconnect from criu. N((R((s//usr/lib/python2.7/site-packages/pycriu/criu.pyt disconnectsN( t__name__t __module__t__doc__tCOMM_SKtCOMM_FDtCOMM_BINtNonet comm_typetcommtskRR(((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR s t _criu_comm_skcBs)eZdZd„Zd„Zd„ZRS(s. Communication class for unix socket. cCs|j|_||_dS(N(RR R (Rtsk_path((s//usr/lib/python2.7/site-packages/pycriu/criu.pyt__init__*s cCs5tjtjtjƒ|_|jj|jƒ|jS(N(tsockettAF_UNIXtSOCK_SEQPACKETRRR (RR((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR.scCs|jjƒdS(N(Rtclose(R((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR4s(RRRRRR(((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR%s  t _criu_comm_fdcBs)eZdZd„Zd„Zd„ZRS(s2 Communication class for file descriptor. cCs|j|_||_dS(N(R R R (Rtfd((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR=s cCs(tj|jtjtjƒ|_|jS(N(RtfromfdR RRR(RR((s//usr/lib/python2.7/site-packages/pycriu/criu.pyRAscCs|jjƒdS(N(RR(R((s//usr/lib/python2.7/site-packages/pycriu/criu.pyRGs(RRRRRR(((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR8s  t_criu_comm_bincBs)eZdZd„Zd„Zd„ZRS(s) Communication class for binary. cCs+|j|_||_d|_d|_dS(N(R R R R tswrkR(Rtbin_path((s//usr/lib/python2.7/site-packages/pycriu/criu.pyRPs   csmtjtjtjƒ‰tjˆdtjƒ}tjˆdtj|tjBƒtjˆdtjƒ}tjˆdtj|tj@ƒ|ˆ_t j ƒ}|dkr ‡‡fd†}|rt j ƒ}|dkròt j ƒ|ƒq t j dƒq%|ƒn|r%t j |dƒnˆdjƒtjdˆdjdƒƒdˆ_ˆdˆ_ˆjS(Niicsˆtjdƒtjdƒtjdƒˆdjtjdtjƒƒƒtjˆjˆjddˆdjƒgƒtj dƒdS(NiiitiRs%d( tosRtsendtstructtpacktgetpidtexecvR tfilenot_exit((tcssR(s//usr/lib/python2.7/site-packages/pycriu/criu.pyt exec_criuds   #  Ri(Rt socketpairRRtfcntltF_GETFDtF_SETFDt FD_CLOEXECRRtforktsetsidR$twaitpidRRtunpacktrecvRR(RRtflagstpR&((R%Rs//usr/lib/python2.7/site-packages/pycriu/criu.pyRVs,!"         & cCs0|jjƒ|js,tj|jdƒndS(Ni(RRRRR.R(R((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR†s  (RRRRRR(((s//usr/lib/python2.7/site-packages/pycriu/criu.pyRKs  0t CRIUExceptioncBs#eZdZdZdZd„ZRS(s? Exception class for handling and storing criu errors. cCs|jS(N(t_str(R((s//usr/lib/python2.7/site-packages/pycriu/criu.pyt__str__“sN(RRRR ttypR4R5(((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR3ŒstCRIUExceptionInternalcBseZdZd„ZRS(sC Exception class for handling and storing internal errors. cCs/||_dtjj|jƒ|f|_dS(Ns!%s failed with internal error: %s(R6trpct criu_req_typetNameR4(RR6ts((s//usr/lib/python2.7/site-packages/pycriu/criu.pyRœs (RRRR(((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR7—stCRIUExceptionExternalcBs eZdZd„Zd„ZRS(sC Exception class for handling and storing criu RPC errors. cCs.||_||_||_|jƒ|_dS(N(R6tresp_typterrnot_gen_error_strR4(Rtreq_typR=R>((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR§s   cCsîdtjj|jƒf}|j|jkrE|d|jf7}n|d|jf7}|jtjkrx|d7}n|jtjkr¬|jtjkr¬|d7}q¬n|jtj krà|jtj krà|d7}qàn|d7}|S(Ns %s failed: sUnexpected response type %d: s Error(%d): s Bad optionssNo process with such pids)Process with requested pid already existstUnknown( R8R9R:R6R=R>tEBADRQCtDUMPtESRCHtRESTOREtEEXIST(RR;((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR?­s  (RRRRR?(((s//usr/lib/python2.7/site-packages/pycriu/criu.pyR<¢s tcriucBs}eZdZd Zd Zd„Zd„Zd„Zd„Z d„Z d„Z d„Z d„Z d „Zd „Zd „ZRS( s Call criu through RPC. cCs)|jdƒtjƒ|_d|_dS(NRG(t use_binaryR8t criu_optstoptsR R(R((s//usr/lib/python2.7/site-packages/pycriu/criu.pyRÍs cCst|ƒ|_dS(sZ Access criu using unix socket which that belongs to criu service daemon. N(Rt_comm(Rtsk_name((s//usr/lib/python2.7/site-packages/pycriu/criu.pytuse_skÒscCst|ƒ|_dS(s0 Access criu using provided fd. N(RRK(RR((s//usr/lib/python2.7/site-packages/pycriu/criu.pytuse_fdØscCst|ƒ|_dS(sO Access criu by execing it using provided path to criu binary. N(RRK(Rtbin_name((s//usr/lib/python2.7/site-packages/pycriu/criu.pyRHÞscCst}|jtjkr4|jjdƒ r4t}ny°|jsU|jj |ƒ}n |j}|j rs||_n|j |j ƒƒ|j t|j dtjtjBƒƒƒ}|j sÊ|jjƒntjƒ}|j|ƒWn+tk r}t|jt|ƒƒ‚nX|S(sA As simple as send request and receive response. tpidi(tFalsettypeR8RCRJtHasFieldtTrueRRKRt keep_openRtSerializeToStringR0tlenRt MSG_TRUNCtMSG_PEEKRt criu_resptParseFromStringt ExceptionR7tstr(RtreqRR;tbuftrespte((s//usr/lib/python2.7/site-packages/pycriu/criu.pyt_send_req_and_recv_respäs$%     +  cCsRtjƒ}tj|_|j|ƒ}|jsNt|j|j|jƒ‚ndS(sB Checks whether the kernel support is up-to-date. N(R8tcriu_reqtCHECKRRRbtsuccessR<tcr_errno(RR^R`((s//usr/lib/python2.7/site-packages/pycriu/criu.pytchecks    cCshtjƒ}tj|_|jj|jƒ|j|ƒ}|jsat|j|j|j ƒ‚n|j S(sC Checkpoint a process/tree identified by opts.pid. ( R8RcRCRRRJt MergeFromRbReR<Rftdump(RR^R`((s//usr/lib/python2.7/site-packages/pycriu/criu.pyRis   cCshtjƒ}tj|_|jj|jƒ|j|ƒ}|jsat|j|j|j ƒ‚n|j S(sC Checkpoint a process/tree identified by opts.pid. ( R8RctPRE_DUMPRRRJRhRbReR<RfRi(RR^R`((s//usr/lib/python2.7/site-packages/pycriu/criu.pytpre_dump"s   cCshtjƒ}tj|_|jj|jƒ|j|ƒ}|jsat|j|j|j ƒ‚n|j S(s) Restore a process/tree. ( R8RcRERRRJRhRbReR<Rftrestore(RR^R`((s//usr/lib/python2.7/site-packages/pycriu/criu.pyRl1s   cCsqtjƒ}tj|_|jj|jƒt|_|j|ƒ}|j sjt |j|j|j ƒ‚n|j S(N( R8RctPAGE_SERVER_CHLDRRRJRhRTRURbReR<Rftps(RR^R`((s//usr/lib/python2.7/site-packages/pycriu/criu.pytpage_server_chld@s    cCs^tjƒ}tj|_||_|j|ƒ}|jsWt|j|j|jƒ‚n|j S(N( R8RctWAIT_PIDRRRPRbReR<Rftstatus(RRPR^R`((s//usr/lib/python2.7/site-packages/pycriu/criu.pytwait_pidMs    N(RRRR RJRKRRMRNRHRbRgRiRkRlRoRr(((s//usr/lib/python2.7/site-packages/pycriu/criu.pyRGÅs     #    (((RR>R(RRtpycriu.rpc_pb2trpc_pb2R8RRRRR\R3R7R<RG(((s//usr/lib/python2.7/site-packages/pycriu/criu.pyts     A  #