
    +h?	                     2    d dl Z d dlZd dlZ G d de      Zy)    Nc                   .    e Zd ZdZd Zd Zd Zd Zd Zy)Pidfilez    Manage a PID file. If a specific name is provided
    it and '"%s.oldpid" % name' will be used. Otherwise
    we create a temp file using os.mkstemp.
    c                      || _         d | _        y N)fnamepid)selfr   s     C/var/www/html/venv/lib/python3.12/site-packages/gunicorn/pidfile.py__init__zPidfile.__init__   s    
    c                    | j                         }|r4|t        j                         k(  ry d}t        ||| j                  fz        || _        t        j                  j                  | j                        }|r-t        j                  j                  |      st        d|z        t        j                  |      \  }}t        j                  |d| j
                  z  j                  d             | j                  r!t        j                  || j                         n|| _        t        j                  |       t        j                  | j                  d       y )Nz5Already running on PID %s (or pid file '%s' is stale)z'%s doesn't exist. Can't create pidfile.)dirz%s
zutf-8i  )validateosgetpidRuntimeErrorr   r   pathdirnameisdirtempfilemkstempwriteencoderenameclosechmod)r	   r   oldpidmsgfdirfdr   s          r
   createzPidfile.create   s    $ICsfdjj%99:: wwtzz*d+H4OPP$$.	E
ftxx'//89::IIeTZZ(DJ
 	S!r   c                 h    | j                          || _        | j                  | j                         y r   )unlinkr   r!   r   )r	   r   s     r
   r   zPidfile.rename/   s"    
DHHr   c                    	 t        | j                  d      5 }t        |j                         xs d      }ddd       | j                  k(  r t        j                  | j                         yy# 1 sw Y   9xY w# t        $ r Y yw xY w)z delete pidfilerr   N)openr   intreadr   r   r#   	Exception)r	   fpid1s      r
   r#   zPidfile.unlink4   sv    	djj#& *!1668=q)* txx		$**%  * *
  		s'   A: A.6A: .A73A: :	BBc                 V   | j                   sy	 t        | j                   d      5 }	 t        |j                               }	 t        j                  |d       |cddd       S # t        $ r Y ddd       yw xY w# t        $ rc}|j                  d   t        j                  k(  r|cY d}~cddd       S |j                  d   t        j                  k(  rY d}~ddd       y d}~ww xY w# 1 sw Y   yxY w# t        $ r+}|j                  d   t        j                  k(  rY d}~y d}~ww xY w)z- Validate pidfile and make it stale if neededNr%   r   )r   r&   r'   r(   
ValueErrorr   killOSErrorargserrnoEPERMESRCHIOErrorENOENT)r	   r*   wpides       r
   r   zPidfile.validate?   s
   zz	djj#& !qvvx=DGGD!$  " 	   vvayEKK/#  vvayEKK/     	vvayELL(	s   C4 C(A"A9	C4 "	A6+C(,C4 5A66C(9	C%!C #C%$C((	C4 2 C C(C4 C  C%%C((C1-C4 1C4 4	D(= D#"D##D(N)	__name__
__module____qualname____doc__r   r!   r   r#   r    r   r
   r   r      s     "2
	r   r   )r1   r   r   objectr   r<   r   r
   <module>r>      s     	 Kf Kr   