a ì)gÇ#ã@sÀddlmZmZmZeZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZmZddlmZmZddd„Zdd„Zd d „Zd d „Zddd„Zdd„Zdd„Zdd„ZdS)é)Úabsolute_importÚdivisionÚprint_functionN)ÚPY2Úb)Úto_bytesÚto_textcCsp|r|jdt ¡dYn:tyv}z"|jt|ƒt ¡dWYd}~n d}~00|dkrt  ˆd¡t |t ƒsÄt r²t  t||d¡}nt  t||d¡}g}|D]}| t||d¡qÌtj|dtjtj‡fd d „d }|j|jg} |jtd ƒ|jtd ƒi} | r®t | g| d ¡\} } } | | | s\| ¡r(t | ƒD]D}|| vr’t | ¡|¡}|s’|  |¡| |t|ƒ7<qdq(| ¡tj|jt| |jƒt| |jƒgtj d}t !ˆd t||d¡t  ˆd ¡t "d¡n¤|dkr,|jddnŒt  ˆd ¡t #|d¡td ƒ}t ˆdggˆdg¡\} } } ˆd| vrNt ˆd|¡}|s–q¦|t|ƒ7}qNt $t||d¡SdS)aÏ Execute a command while detaching as a daemon, returns rc, stdout, and stderr. :arg module: is an AnsibleModule object, used for it's utility methods :arg cmd: is a list or string representing the command and options to run This is complex because daemonization is hard for people. What we do is daemonize a part of this module, the daemon runs the command, picks up the return code and output, and returns it to the main process. iZsurrogate_or_strictz"Error while attempting to fork: %s)r+Ú exceptionNr)ÚerrorsFcst ˆd¡S)Né)r r6r©ÚpiperrÚÏózdaemonize..)ÚshellÚstdoutÚstderrZ preexec_fnr)r@)Zprotocolr/zSUnable to fork, no exception thrown, probably due to lack of resources, check logs.r*)%r rBr=ÚOSErrorr,Ú tracebackÚ format_excr9rr6Ú isinstanceÚlistrÚshlexÚsplitrÚappendÚ subprocessÚPopenÚPIPErFrGrÚselectZpollÚreadÚfilenoÚremoveÚwaitÚpickleÚdumpsÚ returncodeZHIGHEST_PROTOCOLÚwriter7ÚwaitpidÚloads)r!ÚcmdÚchunkr?r;ÚexcZrun_cmdÚcÚpZfdsÚoutputZrfdZwfdZefdÚoutÚdataZ return_datarrArÚ daemonize¥s^   ,       ,    rfcCsdt ¡dkrd}nd}| dd¡}| d||f¡\}}}|dkr`| d¡D]}||vrLdSqLd S) NrrrrTz%s %srÚ F)rrrrrN)r!r"Zpsflagsr%r&rdÚerrr'rrrÚcheck_pss  ri)N)r))Z __future__rrrÚtypeZ __metaclass__r r rXrrSrMrPrIZansible.module_utils.sixrrZansible.module_utils._textrrrrrr(r-r=rfrirrrrÚs&   *\