JFIF$        dd7 

Viewing File: /usr/lib/python3.9/site-packages/dnf-plugins/__pycache__/needs_restarting.cpython-39.pyc

a

�i6�@sddlmZddlmZddlmZddlmZddlmZmZddlZddl	Zddl
Z
ddlZddlZddl
Z
ddlZddlZgd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZGdd�de�ZGdd�de�ZejjGdd�dejj ��Z!dS) �)�absolute_import)�division)�print_function)�unicode_literals)�logger�_N)	Zkernelz	kernel-rtZglibczlinux-firmwareZsystemd�dbuszdbus-brokerzdbus-daemonZ
microcode_ctlc	s�tj�|�st�St�}t�|�D]j}tj�|�s"|�d�s>q"ttj�||���,}|D]}|�	|�
�|f�qVWd�q"1s�0Yq"t��|j���
�jdd�|D�d�D]}��	|j�q��fdd�|D�D] \}}t�tdj||d���q؈S)	z�
    Provide filepath as string if single dir or list of strings
    Return set of package names contained in files under filepath
    z.confNcSsh|]}|d�qS�r���.0�xr
r
�@/usr/lib/python3.9/site-packages/dnf-plugins/needs_restarting.py�	<setcomp>@�z'get_options_from_dir.<locals>.<setcomp>��namecsh|]}|d�vr|�qSr	r
r�Zpackagesr
rrBrz`No installed package found for package name "{pkg}" specified in needs-restarting file "{file}".)�pkg�file)�os�path�exists�set�listdir�isdir�endswith�open�join�add�rstrip�sack�query�	installed�filterrr�warningr�format)�filepath�base�optionsr�fp�linerrr
rr�get_options_from_dir.s&4$��r,c	cs�t�D]�\}}zR|dur(|t|�kr(Wqt|ddd��}|��}Wd�n1sT0YWn"ty�t�d|�YqYn0|D]}t||�}|dur�|Vq�qdS)N�r�replace)�errorszFailed to read PID %d's smaps.)�
list_smaps�	owner_uidr�	readlines�EnvironmentErrorrr%�smap2opened_file)�uid�pid�smapsZ
smaps_file�linesr+�ofiler
r
r�list_opened_filesIs*

r:c	csJt�d�D]:}zt|�}Wnty0Yq
Yn0d|}||fVq
dS)Nz/procz/proc/%d/smaps)rr�int�
ValueError)Zdir_r6r7r
r
rr0Zs
r0cst��i����fdd�}|S)Ncs,��|��}|�ur|S�|�}|�|<|S�N)�get)Zparam�val��cache�func�sentinelr
r�wrappergszmemoize.<locals>.wrapper)�object)rBrDr
r@r�memoizedsrFcCst�|�tjSr=)r�stat�ST_UID)�fnamer
r
rr1qsr1cCs$|��j|d���}|r |dSdS)N)rr)r"r$�run)r!rI�matchesr
r
r�owning_packageusrLcCsdd|}t|�� }tj�|���}Wd�n1s60Yd�|�d��}td||f�dS)Nz/proc/%d/cmdline� �z%d : %s)r�dnfZi18nZucd�readr�split�print)r6ZcmdlineZcmdline_fileZcommandr
r
r�	print_cmd|s

.rSc	
Cs�t��}|�dd�}t�|d�}d}z|�d|�|��}WnBtjy|}z(t|�}t�d�	||��WYd}~dSd}~00tj|dd�}|�
dd�}|�d	�r�|SdS)
N�org.freedesktop.systemd1�/org/freedesktop/systemd1� org.freedesktop.systemd1.Managerz)Failed to get systemd unit for PID {}: {}zorg.freedesktop.DBus.Properties)Zdbus_interfacezorg.freedesktop.systemd1.UnitZIdz.service)r�	SystemBus�
get_object�	InterfaceZGetUnitByPID�
DBusException�strrr%r&�Getr)	r6�busZsystemd_manager_objectZsystemd_manager_interfaceZ
service_proxy�e�msgZservice_propertiesrr
r
r�get_service_dbus�s:�����
r`cCsn|�d�}|dkrdS|�d�dkr(dS||d���}|�d�}|dkrVt||d�St||d|�d�SdS)N�/rz00:z
 (deleted)FT)�find�strip�rfind�
OpenedFile)r6r+Zslash�fnZsuffix_indexr
r
rr4�s

r4c@s*eZdZe�d�Zdd�Zedd��ZdS)rez^(.+);[0-9A-Fa-f]{8,}$cCs||_||_||_dSr=)�deletedrr6)�selfr6rrgr
r
r�__init__�szOpenedFile.__init__cCs(|jr"|j�|j�}|r"|�d�S|jS)a;Calculate the name of the file pre-transaction.

        In case of a file that got deleted during the transactionm, possibly
        just because of an upgrade to a newer version of the same file, RPM
        renames the old file to the same name with a hexadecimal suffix just
        before delting it.

        �)rg�RE_TRANSACTION_FILE�matchr�group)rhrlr
r
r�
presumed_name�s

zOpenedFile.presumed_nameN)	�__name__�
__module__�__qualname__�re�compilerkri�propertyrnr
r
r
rre�s
rec@s@eZdZdd�Zedd��Zedd��Zedd��Zd	d
�ZdS)�ProcessStartcCs&t��|_t�|j�|_t��|_dSr=)ru�get_kernel_boot_time�kernel_boot_time�
get_boot_time�	boot_time�get_sc_clk_tck�
sc_clk_tck)rhr
r
rri�s
zProcessStart.__init__c
Cs�zjtdd��L}|D]6}|�d�r|��\}}t|�Wd�WSqWd�n1s^0YWn0ty�}zt�d|�WYd}~n
d}~00dS)Nz
/proc/statr-zbtime zCouldn't read /proc/stat: %sr)r�
startswithrQ�float�OSErrorr�debug)rr+�key�valuer^r
r
rrv�s
@"z!ProcessStart.get_kernel_boot_timec	
Csd}zTt��}|�dd�}t�|tj�}|�dd�}|dkrV|d}t�d|�|WSWn4tjj	y�}zt�d	|�WYd}~n
d}~00t�d
�zt
t�d�j
�}Wn4ty�}zt�d|�d
}WYd}~n
d}~00|}t||�}t�d|�t�d|�t�d|�|S)a0
        We have three sources from which to derive the boot time. These values vary
        depending on containerization, existence of a Real Time Clock, etc.
        - UnitsLoadStartTimestamp property on /org/freedesktop/systemd1
             The start time of the service manager, according to systemd itself.
             Seems to be more reliable than UserspaceTimestamp when the RTC is
             in local time. Works unless the system was not booted with systemd,
             such as in (most) containers.
        - st_mtime of /proc/1
             Reflects the time the first process was run after booting. This
             works for all known cases except machines without a RTC---they
             awake at the start of the epoch.
        - btime field of /proc/stat
             Reflects the time when the kernel started. Works for machines
             without RTC iff the current time is reasonably correct. Does not
             work on containers which share their kernel with the host---there,
             the host kernel uptime is returned.
        NrTrUrVZUnitsLoadStartTimestampri@BzGot boot time from systemd: %sz.D-Bus error getting boot time from systemd: %sz`Couldn't get boot time from systemd, checking st_mtime of /proc/1 and btime field of /proc/stat.z/proc/1zCouldn't stat /proc/1: %srjzst_mtime of /proc/1: %szbtime field of /proc/stat: %sz!Using %s as the system boot time.)rrWrXrYZPROPERTIES_IFACEr\rr�
exceptionsrZr}rrG�st_mtimer~�max)	rwZunits_load_start_timestampr]Zsystemd1ZpropsZsystemd_boot_timer^Zproc_1_boot_timeryr
r
rrx�sB���
"

zProcessStart.get_boot_timecCst�tjd�S)N�
SC_CLK_TCK)r�sysconf�
sysconf_namesr
r
r
rrz"szProcessStart.get_sc_clk_tckcCs\d|}t|��}|����}Wd�n1s20Yt|d�}||j}|j|S)Nz
/proc/%d/stat�)rrPrQr;r{rw)rhr6Zstat_fnZ	stat_fileZstatsZticks_after_kernel_bootZsecs_after_kernel_bootr
r
r�__call__&s
*
zProcessStart.__call__N)	rorprqri�staticmethodrvrxrzr�r
r
r
rru�s

A
ruc@s4eZdZdZed�Zedd��Zdd�Zdd�Z	d	S)
�NeedsRestartingCommand)zneeds-restartingz/determine updated binaries that need restartingcCsF|jdddtd�d�|jdddtd�d�|jd	d
dtd�d�dS)Nz-uz
--useronly�
store_truez#only consider this user's processes)�action�helpz-rz--reboothintzKonly report whether a reboot is required (exit code 1) or not (exit code 0)z-sz
--servicesz%only report affected systemd services)�add_argumentr)�parserr
r
r�
set_argparser7s
�
�
�z$NeedsRestartingCommand.set_argparsercCs|jj}d|_dS)NT)�cli�demandsZsack_activation)rhr�r
r
r�	configureAsz NeedsRestartingCommand.configurec
Cs�t�}t�t|jj�}t|�}ttj	�
|jjjd�|j�}t
�|�|jjr�t�}|jj����}|jt
d�D]}|j|jkrn|�|j�qn|r�ttd��t|�D]}td|�q�t�ttd��ttd�d�tj���nttd��ttd	��dSt�}|jj�rt� �nd}	t!|	�D]<}
||
j"�}|du�r>�q"|j||
j#�k�r"|�|
j#��q"|jj$�r�td
d�t|�D��}|D]}|du�r�t|��q�dSt|�D]}t%|��q�dS)
Nz#etc/dnf/plugins/needs-restarting.d/rz;Core libraries or services have been updated since boot-up:z  * %sz2Reboot is required to fully utilize these updates.zMore information:z)https://access.redhat.com/solutions/27943z>No core libraries or services have been updated since boot-up.zReboot should not be necessary.cSsg|]}t|��qSr
)r`)rr6r
r
r�
<listcomp>orz.NeedsRestartingCommand.run.<locals>.<listcomp>r)&ru�	functools�partialrLr(r!rFr,rrrZconfZinstallroot�NEED_REBOOT�extendZoptsZ
reboothintrr"r#r$ZinstalltimeryrrrRr�sortedrOr��ErrorZuseronly�geteuidr:rnr6ZservicesrS)
rhZ
process_startZ
owning_pkg_fn�optZneed_rebootr#rrZ
stale_pidsr5r9�namesr6r
r
rrJEsZ��
�



zNeedsRestartingCommand.runN)
rorprq�aliasesrZsummaryr�r�r�rJr
r
r
rr�2s
	r�)"Z
__future__rrrrZdnfpluginscorerrrOZdnf.clirr�rrrrG�timer�r,r:r0rFr1rLrSr`r4rEreruZpluginZregister_commandr�ZCommandr�r
r
r
r�<module>s4

"d
Back to Directory  nL+D550H?Mx ,D"v]qv;6*Zqn)ZP0!1 A "#a$2Qr D8 a Ri[f\mIykIw0cuFcRı?lO7к_f˓[C$殷WF<_W ԣsKcëIzyQy/_LKℂ;C",pFA:/]=H  ~,ls/9ć:[=/#f;)x{ٛEQ )~ =𘙲r*2~ a _V=' kumFD}KYYC)({ *g&f`툪ry`=^cJ.I](*`wq1dđ#̩͑0;H]u搂@:~וKL Nsh}OIR*8:2 !lDJVo(3=M(zȰ+i*NAr6KnSl)!JJӁ* %݉?|D}d5:eP0R;{$X'xF@.ÊB {,WJuQɲRI;9QE琯62fT.DUJ;*cP A\ILNj!J۱+O\͔]ޒS߼Jȧc%ANolՎprULZԛerE2=XDXgVQeӓk yP7U*omQIs,K`)6\G3t?pgjrmۛجwluGtfh9uyP0D;Uڽ"OXlif$)&|ML0Zrm1[HXPlPR0'G=i2N+0e2]]9VTPO׮7h(F*癈'=QVZDF,d߬~TX G[`le69CR(!S2!P <0x<!1AQ "Raq02Br#SCTb ?Ζ"]mH5WR7k.ۛ!}Q~+yԏz|@T20S~Kek *zFf^2X*(@8r?CIuI|֓>^ExLgNUY+{.RѪ τV׸YTD I62'8Y27'\TP.6d&˦@Vqi|8-OΕ]ʔ U=TL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