HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux bsx-1-dev 6.8.0-101-generic #101-Ubuntu SMP PREEMPT_DYNAMIC Mon Feb 9 10:15:05 UTC 2026 x86_64
User: www-data (33)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/cloudinit/__pycache__/socket.cpython-312.pyc
�

�t�hg���dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZeje�Zdefd�ZGd	�d
�Zy)z#A module for common socket helpers.�N)�suppress)�Dict)�performance)�DEFAULT_RUN_DIR�messagec��tjjdd�}|sy|ddk(r|jddd�n|ddk7rt	d	��tj
t
jt
jt
jz�5}tjd
t|��|j|�|j|jd��ddd�y#1swYyxYw)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�socks   �2/usr/lib/python3/dist-packages/cloudinit/socket.py�	sd_notifyr"s���
�*�*�.�.��"�5�K���	�Q��3�	����C��q�)�
�Q��3�	��/�0�0�	�������)�)�F�,?�,?�?�
�.�	
����(�#�g�,�7����[�!����W�^�^�G�,�-�.�.�.�s
�AC0�0C9c�4�eZdZdZdefd�Zdefd�Zd�Zd�Zy)	�
SocketSyncz<A two way synchronization protocol over Unix domain sockets.�namesc	�P�d|_d|_d|_d|_|D�cic]F}|t	jtj
tjtjz���Hc}|_i|_	tjt�d�dd��|jj�D]_\}}t�d|�d	�}tt�5tj |�d
d
d
�|j#|�|j%��ay
cc}w#1swY�2xYw)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
        r
rFz/sharei�T)�mode�exist_okz/share/z.sockN)�stage�first_exception�systemd_exit_code�experienced_any_errorrr�SOCK_STREAMr�sockets�connectionsr�makedirsr�itemsr�FileNotFoundError�remove�bind�listen)�selfr%�namer rs     r!�__init__zSocketSync.__init__.s����
�!���!"���%*��"�
�	
��
�&�-�-����� 2� 2�V�5H�5H� H��
�
���68���
����'�v�.�U�T�J��,�,�,�,�.�	�J�D�$�,�-�W�T�F�%�@�K��+�,�
'��	�	�+�&�
'��I�I�k�"��K�K�M�	��
�
'�
'�s�AD�D�D%	r)c�L�||jvrtd|����||_|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)s  r!�__call__zSocketSync.__call__Os/������$��3�E�7�;�<�<���
���c��tjtjj	��rt
j
d�yd|_td|j�d��|j|j}tjd|j���5|j�\}}|jd�\}}||j|j<ddd�dk7r+|j!ddd�t#d	t%|��d
���td|j�d��|S#1swY�TxYw)
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__r:r)r6r �
connection�_�chunks     r!�	__enter__zSocketSync.__enter__cs��
�9�9�S�Y�Y�%�%�'�(��H�H�L�
�
�!"����
,�,0�J�J�<�w�
@�	
��|�|�D�J�J�'��
�
�
�!8�����E�
F�	6� �K�K�M�M�J��!�*�*�1�-�H�E�1�+5�D���T�Z�Z�(�	6�
�u���M�M�$��d�+��:�3�u�:�,�a�H�I�I��$�T�Z�Z�L��8�9���	6�	6�s
�#AD7�7Ec�L�tjtjj	��ryd|j
��}|r`d|_d|_t|��d|j��}d}|js||_
tj|�td|���|jxst|j�|_|j|j
}|j!d|�d	|j�d
�j#��|j%�y)z.Notify the socket that this stage is complete.Nz,Completed socket interaction for boot stage r
Tz in zkfatal error, run "systemctl status cloud-init-main.service" and "cloud-init status --long" for more detailszSTATUS=zecho 'z'; exit �;)rr@rArBrCr)r+r,�repr�tb_framer*r�fatalr"�boolr/rr�close)r6�exc_type�exc_val�exc_tbr�statusr s       r!rGzSocketSync.__exit__�s
��
�9�9�S�Y�Y�%�%�'�(��@�����M���%&�D�"�)-�D�&��W�
��d�6�?�?�*;�<�F�B�
��'�'�'-��$��I�I�f�����x�(�)�%)�%?�%?�&
�4��"�"�D
��"�����
�
�+��
	
����W�I�X�d�&<�&<�%=�Q�?�F�F�H�	
�	
�
�
��r<N)	�__name__�
__module__�__qualname__�__doc__rr8r;rKrG�r<r!r$r$+s)��F��s��B�c��( �D%r<r$)rZ�loggingrrrA�
contextlibr�typingr�	cloudinitr�cloudinit.settingsr�	getLoggerrWrrr"r$r[r<r!�<module>rbsJ��)��	�
�
���!�.��g����!��.�s�.�6�r<