
    f                     \    d Z ddlZddlZddlZddlZ G d d      Zd Zedk(  r e        yy)a  pidproxy -- run command and proxy signals to it via its pidfile.

This executable runs a command and then monitors a pidfile.  When this
executable receives a signal, it sends the same signal to the pid
in the pidfile.

Usage: %s <pidfile name> <command> [<cmdarg1> ...]
    Nc                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)PidProxyNc                     	 |d   |dd  c| _         }t        j                  j                  |d         | _        || _        y # t        t        f$ r( | j                          t        j                  d       Y y w xY w)N      r   )pidfileospathabspathabscmdcmdargs
ValueError
IndexErrorusagesysexit)selfargsr   s      5/usr/lib/python3/dist-packages/supervisor/pidproxy.py__init__zPidProxy.__init__   sf    	$(GT!"X!DL'''//'!*5DK"DLJ' 	JJLHHQK	s   >A 4A87A8c                 D   | j                          t        j                  t        j                  | j                  | j
                        | _        	 t        j                  d       	 t        j                  dt        j                        d   }|ry A# t        $ r d }Y w xY w)N   r   )
setsignalsr	   spawnvP_NOWAITr   r   pidtimesleepwaitpidWNOHANGOSError)r   r   s     r   gozPidProxy.go   s{    99R[[$++t||DJJqMjjRZZ03    s   &'B BBc                 J    t        t        t        j                  d   z         y )Nr   )print__doc__r   argvr   s    r   r   zPidProxy.usage)   s    g#$    c                    t        j                   t         j                  | j                         t        j                   t         j                  | j                         t        j                   t         j                  | j                         t        j                   t         j
                  | j                         t        j                   t         j                  | j                         t        j                   t         j                  | j                         t        j                   t         j                  | j                         y N)
signalSIGTERMpasstochildSIGHUPSIGINTSIGUSR1SIGUSR2SIGQUITSIGCHLDreapr(   s    r   r   zPidProxy.setsignals,   s    fnnd&6&67fmmT%5%56fmmT%5%56fnnd&6&67fnnd&6&67fnnd&6&67fnndii0r)   c                      y r+    )r   sigframes      r   r5   zPidProxy.reap5   s    r)   c                    	 t        | j                  d      5 }t        |j                         j	                               }d d d        t        j                  |       |t        j                  t        j                  t        j                  fv rt        j                  d       y y # 1 sw Y   gxY w#  t        d| j                  z         Y y xY w)NrzCan't read child pidfile %s!r   )openr   intreadstripr%   r	   killr,   r-   r0   r3   r   r   )r   r8   r9   fr   s        r   r.   zPidProxy.passtochild9   s    	dllC( ,A!&&(..*+,
 	S6>>6==&..AAHHQK B, ,	04<<?@s"   B2 (B& B2 &B/+B2 2C)
__name__
__module____qualname__r   r   r#   r   r   r5   r.   r7   r)   r   r   r      s%    
C
%1	r)   r   c                  V    t        t        j                        } | j                          y r+   )r   r   r'   r#   )pps    r   mainrG   D   s    	#((	BEEGr)   __main__)r&   r	   r   r,   r   r   rG   rB   r7   r)   r   <module>rI      s<    
 
  1 1f zF r)   