+
    ig                         R t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ]P                  ! ]4      tR R lt ! R R	4      tR# )
z#A module for common socket helpers.N)suppress)Dict)performance)DEFAULT_RUN_DIRc                $    V ^8  d   QhR\         /# )   messagestr)formats   "2/usr/lib/python3/dist-packages/cloudinit/socket.py__annotate__r      s     . .s .    c                J   \         P                  P                  RR4      pV'       g   R# V^ ,          R8X  d   VP                  RR^4       MV^ ,          R8w  d   \	        R4      h\
        P
                  ! \
        P                  \
        P                  \
        P                  ,          4      ;_uu_ 4       p\        P                  R\        V 4      4       VP                  V4       VP                  V P                  R	4      4       RRR4       R#   + '       g   i     R# ; i)
zSSend a sd_notify message.

:param message: sd-notify message (must be valid ascii)
NOTIFY_SOCKET N@ /zUnsupported socket typezSending sd_notify(%s)ascii)osenvirongetreplaceOSErrorsocketAF_UNIX
SOCK_DGRAMSOCK_CLOEXECLOGinfor
   connectsendallencode)r   socket_pathsocks   &  r   	sd_notifyr&      s    
 **.."5K	Q3	Cq) 
Q3	/00	))F,?,??
 
	(#g,7[!W^^G,-
 
 
 
s   6ADD"	c                   T   a  ] tR t^+t o RtV 3R lR ltV 3R lR ltR tR tRt	V t
R	# )

SocketSyncz<A two way synchronization protocol over Unix domain sockets.c                    < V ^8  d   QhRS[ /# )r   namesr	   )r   __classdict__s   "r   r   SocketSync.__annotate__.   s      s r   c           	        RV n         RV n        ^ V n        RV n        V Uu/ uFL  pV\        P                  ! \        P
                  \        P                  \        P                  ,          4      bKN  	  upV n        / V n	        \        P                  ! \         R2RRR7       V P                  P                  4        Fh  w  r#\         RV R2p\        \        4      ;_uu_ 4        \        P                   ! V4       R	R	R	4       VP#                  V4       VP%                  4        Kj  	  R	# u upi   + '       g   i     L<; i)
a6  Initialize 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   Fz/sharei  T)modeexist_okz/share/z.sockN)stagefirst_exceptionsystemd_exit_codeexperienced_any_errorr   r   SOCK_STREAMr   socketsconnectionsr   makedirsr   itemsr   FileNotFoundErrorremovebindlisten)selfr*   namer%   r$   s   &*   r   __init__SocketSync.__init__.   s     
!!"%*"
 	
  &-- 2 2V5H5H H  	
 68
'v.UTJ,,,,.JD,-WTF%@K+,,		+& -IIk"KKM /
 -,s   AD*$D//D?c                    < V ^8  d   QhRS[ /# )r   r0   r	   )r   r+   s   "r   r   r,   O   s      c r   c                N    WP                   9  d   \        RV 24      hWn        V # )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
zInvalid stage name: )r5   
ValueErrorr0   )r=   r0   s   &&r   __call__SocketSync.__call__O   s+     $3E7;<<
r   c                   \         P                  ! \        P                  P	                  4       4      '       d   \
        P                  R4       R# ^ V n        \        RV P                   R24       V P                  V P                  ,          p\        P                  ! RV P                   24      ;_uu_ 4        VP                  4       w  r#VP                  ^4      w  rCW P                  V P                  &   RRR4       RX8w  d,   V P!                  RRR4       \#        R\%        V4       R24      h\        R	V P                   R
24       V #   + '       g   i     L]; i)zwWait 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 protocolNzDSTATUS=Waiting on external services to complete before starting the z stage.zWaiting to start stage s   startzReceived invalid message: []zSTATUS=Running (z stage))r   isattysysstdinfilenor   r    r2   r&   r0   r5   r   Timedacceptrecvfromr6   __exit__rC   r
   )r=   r%   
connection_chunks   &    r   	__enter__SocketSync.__enter__c   s   
 99SYY%%'((HHL !",,0JJ<w@	
 ||DJJ'!8EFF KKMMJ!**1-HE+5TZZ( G
 uMM$d+:3u:,aHII$TZZL89 GFs   8>EE	c                   \         P                  ! \        P                  P	                  4       4      '       d   R# RV P
                   2pV'       df   ^V n        RV n        \        V4       RVP                   2pRpV P                  '       g   WPn
        \        P                  V4       \        RV 24       V P                  ;'       g    \        V P                  4      V n        V P                  V P
                  ,          pVP!                  RV RV P                   R	2P#                  4       4       VP%                  4        R# )
z.Notify the socket that this stage is complete.Nz,Completed socket interaction for boot stage Tz in zkfatal error, run "systemctl status cloud-init-main.service" and "cloud-init status --long" for more detailszSTATUS=zecho 'z'; exit ;)r   rH   rI   rJ   rK   r0   r2   r3   reprtb_framer1   r   fatalr&   boolr6   r"   r#   close)r=   exc_typeexc_valexc_tbr   statusr%   s   &&&&   r   rO   SocketSync.__exit__   s   99SYY%%'((@M%&D")-D&Wd6??*;<FB  ''''-$IIfx()%)%?%? &
 &
4""D
" 

+
 	WIXd&<&<%=Q?FFH	
 	

 r   )r6   r3   r1   r5   r0   r2   N)__name__
__module____qualname____firstlineno____doc__r?   rD   rS   rO   __static_attributes____classdictcell__)r+   s   @r   r(   r(   +   s-     F B ( D% %r   r(   )re   loggingr   r   rI   
contextlibr   typingr   	cloudinitr   cloudinit.settingsr   	getLoggerra   r   r&   r(    r   r   <module>ro      sA    )  	  
   ! .!.6 r   