+
    jHàjŒ  ã                  óÖ   € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 R R lt
R R ltR R	 ltR
 R ltRR R lltR R lt]R8X  d   ]P"                  ! ]! 4       4       R# R# )aí  SIGKILL any process left in this systemd unit's cgroup.

Runs as ``ExecStopPost=`` after the gateway's main process has exited: the
safety net for long-lived helpers the gateway doesn't track (``adb``, platform
bridges) that would otherwise be orphaned in the cgroup and block
``Restart=always``.  Per-PID SIGKILLs over ``cgroup.procs`` are used instead of
writing ``1`` to ``cgroup.kill``: the kernel has returned ``EINVAL`` on the
cgroup-wide kill while per-PID signal delivery still works.
)ÚannotationsN)ÚPathc               ó   € V ^8„  d   QhRR/# )é   Úreturnú
str | None© )Úformats   "Ú;/home/ubuntu/.hermes/hermes-agent/gateway/cgroup_cleanup.pyÚ__annotate__r      s   € ÷ 5ñ 5˜*ñ 5ó    c                 óü   €  \        R4      P                  RR7      p \        P                  ! RT \        P
                  4      pT'       d    TP                  ^4      P                  4       # R#   \         d     R# i ; i)z;Return the cgroup v2 path for the calling process, or None.z/proc/self/cgroupúutf-8©ÚencodingNz	^0::(.+)$)r   Ú	read_textÚOSErrorÚreÚsearchÚ	MULTILINEÚgroupÚstrip)ÚtextÚmatchs     r
   Ú_own_cgroup_pathr      sj   € ðÜÐ'Ó(×2Ñ2¸GÐ2ÓDˆô �IŠI�l D¬"¯,©,Ó7€Eß%*ˆ5�;‰;�q‹>×ÑÓ!Ð4°Ð4øô ô Úðús   ‚A, Á,A;Á:A;c               ó    € V ^8„  d   QhRRRR/# )r   Úcgroup_pathÚstrr   ú	list[int]r   )r	   s   "r
   r   r      s   € ÷ 	ñ 	 3ð 	¨9ñ 	r   c           	     ól  €  \        R V  R24      P                  RR7      p. pTP                  4        FV  p\        P
                  ! \        4      ;_uu_ 4        TP                  \        TP                  4       4      4       RRR4       KX  	  T#   \         d    . u # i ; i  + '       g   i     K€  ; i)z/sys/fs/cgroupz/cgroup.procsr   r   N)
r   r   r   Ú
splitlinesÚ
contextlibÚsuppressÚ
ValueErrorÚappendÚintr   )r   ÚrawÚpidsÚlines   &   r
   Ú_read_cgroup_pidsr)      sš   € ðÜ�^ K =°Ð>Ó?×IÑIÐSZÐIÓ[ˆð €DØ—‘Ö ˆÜ× Ò ¤×,Õ,Ø�K‰Kœ˜DŸJ™J›LÓ)Ô*÷ -Ñ,ñ !ð €Køô ô ØŠ	ðú÷ -×,Ð,ús   ‚B Á)B"ÂBÂBÂ"B3c               ó   € V ^8„  d   QhRR/# )r   r   Úboolr   )r	   s   "r
   r   r   +   s   € ÷ ñ ˜Dñ r   c                 ó²   € \         P                  ! 4       p  \        RV  R24      P                  RR7      P	                  4       R8H  #   \
         d     R# i ; i)a…  True when this process was spawned by a systemd manager (ExecStopPost etc.).

Any other parent (an agent terminal tool, a shell) shares a *live*
process's cgroup, so reaping there would SIGKILL that process. No PID-1
shortcut: in a container the gateway itself can be PID 1 (or init can be
``tini``), so PID 1 must present as systemd too; an unreadable
``/proc/<ppid>/comm`` fails closed.
z/proc/z/commr   r   ÚsystemdF)ÚosÚgetppidr   r   r   r   )Úppids    r
   Ú_parent_is_systemdr1   +   sW   € ô �:Š:‹<€DðÜ�f˜T˜F %Ð(Ó)×3Ñ3¸WÐ3ÓE×KÑKÓMÐQZÑZÐZøÜô Úðús   —/A ÁAÁAc               ó    € V ^8„  d   QhRRRR/# )r   r'   r   r   r+   r   )r	   s   "r
   r   r   ;   s   € ÷ ñ ˜ið ¨Dñ r   c                ón   € ^ RI HpHp V  F&  pV! V4      pV'       g   K  V! V4      '       g   K%   R# 	  R# )u‡  True when one of ``pids`` is a live Hermes gateway runtime.

A PID whose command line can't be read has already exited (or is a
zombie) â€” exactly what the reaper clears â€” so only a readable,
gateway-shaped command line blocks. Uses the *runtime* matcher (``run``
or ``restart``): without a service manager, ``gateway restart`` runs the
gateway in-process and is itself the live runtime.
)Ú_read_process_cmdlineÚ'looks_like_gateway_runtime_command_lineTF)Úgateway.statusr4   r5   )r'   r4   r5   ÚpidÚcmdlines   &    r
   Ú_live_gateway_amongr9   ;   s4   € ÷ ^ãˆÙ'¨Ó,ˆß‰7Ñ>¸w×GÔGÚñ ñ r   c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   z
int | Noner   )r	   s   "r
   r   r   M   s   € ÷ "ñ "˜Zð "°:ñ "r   c                óè  € V f   \        4       MT p V '       g   ^ # \        P                  ! 4       p\        V 4       Uu. uF  q"V8w  g   K  VNK  	  ppV'       g   ^ # \	        V4      '       d   \        R\        P                  R7       R# ^ p\        V 4       F:  pW!8X  d   K   \        P                  ! V\        P                  4       V^,          pK<  	  V# u upi   \        \        3 d     KY  i ; i)uã   SIGKILL every PID in the cgroup other than the caller. Returns the count killed.

Returns None (no signals) when a live gateway process is still in the
cgroup â€” the reaper must never signal the live gateway, however invoked.
Nuâ   cgroup_cleanup: refusing â€” a live gateway process is still in the cgroup; reaping would SIGKILL it. Stop the service first (then ExecStopPost reaps its orphans), or call reap_cgroup(path) once the gateway process has exited.©Úfile)r   r.   Úgetpidr)   r9   ÚprintÚsysÚstderrÚkillÚsignalÚSIGKILLÚProcessLookupErrorÚPermissionError)r   Úmer7   ÚothersÚkilleds   &    r
   Úreap_cgrouprJ   M   sÖ   € ð )4Ò(;Ô"Ô$À€KßÙÜ	�Š‹€BÜ.¨{Ô;ÓIÑ;�cÀb¹y�cˆcÑ;€FÐIßÙÜ˜6×"Ò"Üð.ô —‘õ	
ñ Ø€Fô ! Ö-ˆØŒ9Ùð	Ü�GŠG�CœŸ™Ô(Ø�a�KŠFñ .ð €Mùò1 Jøô, #¤OÐ4ô 	Úð	ús   ½CÁ
CÂ#.CÃC1Ã0C1c               ó   € V ^8„  d   QhRR/# )r   r   r%   r   )r	   s   "r
   r   r   r   s   € ÷ 
-ñ 
-ˆcñ 
-r   c                 ó|   € \        4       '       g   \        R \        P                  R7       ^# \	        4       f   ^# ^ # )uð   cgroup_cleanup: refusing â€” not spawned by systemd. Running this inside a live process's cgroup would SIGKILL that process. Run it via the systemd unit's ExecStopPost, or call reap_cgroup(cgroup_path) with an explicit stopped-service path.r<   )r1   r?   r@   rA   rJ   r   r   r
   ÚmainrM   r   s9   € Ü×ÒÜðNô —‘õ	
ñ Ü“Ò%ˆ1Ð,¨1Ð,r   Ú__main__)N)Ú__doc__Ú
__future__r   r!   r.   r   rC   r@   Úpathlibr   r   r)   r1   r9   rJ   rM   Ú__name__Úexitr   r   r
   Ú<module>rT      s]   ðñõ #ã Û 	Û 	Û Û 
Ý õ5õ	õõ ÷$"õJ
-ð ˆzÔØ‡H‚H‰T‹VÖñ r   