o
    2c?	                     @   s,   d dl Z d dlZd dlZG dd deZdS )    Nc                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )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                 C   s   || _ d | _d S N)fnamepid)selfr    r   F/var/www/html/gps/gps/lib/python3.10/site-packages/gunicorn/pidfile.py__init__   s   
zPidfile.__init__c                 C   s   |   }|r|t krd S d}t||| jf || _tj| j}|r1tj|s1td| t	j
|d\}}t|d| j d | jrPt|| j n|| _t| t| jd d S )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   r   r   r   create   s"   
zPidfile.createc                 C   s   |    || _| | j d S r   )unlinkr   r   r   )r   r   r   r   r   r   /   s   zPidfile.renamec                 C   st   z/t | jd}t| pd}W d   n1 sw   Y  || jkr-t| j W dS W dS  ty9   Y dS w )z delete pidfilerr   N)openr   intreadr   r   r   	Exception)r   fpid1r   r   r   r   4   s   
zPidfile.unlinkc                 C   s6  | j sdS zyt| j dh}zt| }W n ty&   Y W d   W dS w zt|d |W W  d   W S  tys } z/|jd t	j
krX|W  Y d}~W  d   W S |jd t	jkrnW Y d}~W d   W dS  d}~ww 1 sww   Y  W dS  ty } z|jd t	jkrW Y d}~dS  d}~w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er   r   r   r   ?   s>   	
zPidfile.validateN)	__name__
__module____qualname____doc__r	   r   r   r   r   r   r   r   r   r      s    r   )r*   r   r   objectr   r   r   r   r   <module>   s   