File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/process.cpython-310.pyc
o
;j۲ � @ s& d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z ddlZ ddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZ ddlmZ e�e �Z!dZ"zddl#Z#dZ"W n e$y� Y nw zddl%Z%dZ&W n e$y� dZ&Y nw g Z'dd� Z(d4d d
�Z)dd� Z*d
d� Z+dd� Z,dd� Z-d5dd�Z.dd� Z/dd� Z0dd� Z1dd� Z2dd� Z3d6d d!�Z4d"d#� Z5G d$d%� d%�Z6G d&d'� d'�Z7G d(d)� d)e j8�Z8G d*d+� d+e8�Z9ej:d,d-� �Z;G d.d/� d/�Z<d0d1� Z=d2d3� Z>dS )7zE
Functions for daemonizing and otherwise modifying running processes
� N)�gen)�get_machine_identifierFTc C sJ t r#t�� }|�� �d�r|�dd�\}}t�|�� � d| � �� dS dS )z4
Append "name" to the current process title
�MainProcess� � N)�HAS_SETPROCTITLE�setproctitleZgetproctitle�strip�endswith�rsplit�rstrip)�name�current�_� r �F/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/process.py�appendproctitle@ s �r c
C sx ddl }zt�� }|dkrt�|jjj� W n" ty8 } zt� d|j
|� t�|jjj
� W Y d}~nd}~ww t�d� t�� t�d� zt�� }|dkrXt�|jjj� W n" ty{ } zt� d|j
|� t�|jjj
� W Y d}~nd}~ww | r�|jj�dd��*}t|tj� t|tj� t|tj� t|d� t|d � t|d
� W d � dS 1 s�w Y dS dS )z
Daemonize a process
r Nzfork #1 failed: %s (%s)�/� zfork #2 failed: %s (%s)z /dev/nullzr+r � )Zsalt.utils.crypt�os�fork�_exit�defaults� exitcodes�EX_OK�OSError�log�error�errno�sys�exitZ
EX_GENERIC�chdir�setsid�umask�utils�files�fopen�dup2�stdin�stdout�stderr)Zredirect_out�salt�pid�excZdev_nullr r r � daemonizeK sD ���
���
"��r/ c C s� t | t�r| }nz| �� }W n tjy t�d| � Y dS w t |t�r(|}nz|�� }W n tjy? t�d|� Y dS w t�||� dS )z�
Duplicate file descriptor fd to fd2, closing the latter first if necessary.
This method is similar to os.dup2 but ignores streams that do not have a
supported fileno method.
z!Unsupported operation on file: %rN) �
isinstance�int�fileno�io�UnsupportedOperationr �warningr r( )Zfile1Zfile2Zfno1Zfno2r r r r( z s"