HEX
Server: nginx/1.28.3
System: Linux lightweb-s1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64
User: dawonefr-98 (1071)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/cloudinit/__pycache__/socket.cpython-310.pyc
o

�t�hg�@s~dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZe�
e�Zdefdd	�ZGd
d�d�ZdS)z#A module for common socket helpers.�N)�suppress)�Dict)�performance)�DEFAULT_RUN_DIR�messagecCs�tj�dd�}|sdS|ddkr|�ddd�n
|ddkr#td	��t�tjtjtjB��}t	�
d
t|��|�|�|�
|�d��Wd�dS1sOwYdS)z[Send a sd_notify message.

    :param message: sd-notify message (must be valid ascii)
    �
NOTIFY_SOCKET�Nr�@���/zUnsupported socket typezSending sd_notify(%s)�ascii)�os�environ�get�replace�OSError�socket�AF_UNIX�
SOCK_DGRAM�SOCK_CLOEXEC�LOG�info�str�connect�sendall�encode)r�socket_path�sock�r�2/usr/lib/python3/dist-packages/cloudinit/socket.py�	sd_notifys�
"�r!c@s<eZdZdZdefdd�Zdefdd�Zdd	�Zd
d�ZdS)
�
SocketSyncz<A two way synchronization protocol over Unix domain sockets.�namesc	Gs�d|_d|_d|_d|_dd�|D�|_i|_tjt�d�ddd	�|j�	�D].\}}t�d
|�d�}t
t��
t�|�Wd�n1sGwY|�
|�|��q'dS)
anInitialize a synchronization context.

        1) Ensure that the socket directory exists.
        2) Bind a socket for each stage.

        Binding the sockets on initialization allows receipt of stage
        "start" notifications prior to the cloud-init stage being ready to
        start.

        :param names: stage names, used as a unique identifiers
        rrFcSs$i|]}|t�tjtjtjB��qSr)rr�SOCK_STREAMr)�.0�namerrr �
<dictcomp>>s���z'SocketSync.__init__.<locals>.<dictcomp>z/sharei�T)�mode�exist_okz/share/z.sockN)�stage�first_exception�systemd_exit_code�experienced_any_error�sockets�connectionsr�makedirsr�itemsr�FileNotFoundError�remove�bind�listen)�selfr#r&rrrrr �__init__.s"�
�

�zSocketSync.__init__r*cCs"||jvrtd|����||_|S)a�Set the stage before entering context.

        This enables the context manager to be initialized separately from
        each stage synchronization.

        :param stage: the name of a stage to synchronize

        Example:
            sync = SocketSync("stage 1", "stage 2"):
            with sync("stage 1"):
                pass
            with sync("stage 2"):
                pass
        zInvalid stage name: )r.�
ValueErrorr*)r6r*rrr �__call__Os
zSocketSync.__call__cCs�t�tj���rt�d�dSd|_td|j	�d��|j
|j	}t�d|j	����|�
�\}}|�d�\}}||j|j	<Wd�n1sHwYd|krb|�ddd�td	t|��d
���td|j	�d��|S)
z�Wait until a message has been received on this stage's socket.

        Once the message has been received, enter the context.
        z:Stdin is a tty, so skipping stage synchronization protocolNrzDSTATUS=Waiting on external services to complete before starting the z stage.zWaiting to start stage �sstartzReceived invalid message: [�]zSTATUS=Running (z stage))r�isatty�sys�stdin�filenorrr,r!r*r.r�Timed�accept�recvfromr/�__exit__r8r)r6r�
connection�_�chunkrrr �	__enter__cs,���	�zSocketSync.__enter__cCs�t�tj���r
dSd|j��}|r6d|_d|_t|��d|j	��}d}|j
s*||_
t�|�t
d|���|jp=t|j�|_|j|j}|�d|�d	|j�d
����|��dS)z.Notify the socket that this stage is complete.Nz,Completed socket interaction for boot stage rTz in zkfatal error, run "systemctl status cloud-init-main.service" and "cloud-init status --long" for more detailszSTATUS=zecho 'z'; exit �;)rr<r=r>r?r*r,r-�repr�tb_framer+r�fatalr!�boolr/rr�close)r6�exc_type�exc_val�exc_tbr�statusrrrr rC�s,�
��zSocketSync.__exit__N)	�__name__�
__module__�__qualname__�__doc__rr7r9rGrCrrrr r"+s!"r")rU�loggingrrr=�
contextlibr�typingr�	cloudinitr�cloudinit.settingsr�	getLoggerrRrrr!r"rrrr �<module>s