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

3

�f`.�	@s$ddlmZddlmZddlmZddlmZddlmZmZddlZddl	Zddl
Z
ddlZddlZddl
Z
ddlZddlZddd	d
ddd
ddg	ZdgZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�ZGd#d$�d$e�ZGd%d&�d&e�ZejjGd'd(�d(ej j!��Z"dS))�)�absolute_import)�division)�print_function)�unicode_literals)�logger�_NZkernelz	kernel-rtZglibczlinux-firmwareZsystemd�dbuszdbus-brokerzdbus-daemonZ
microcode_ctl�zlibcs�tjj|�st�St�}xjtj|�D]\}tjj|�s$|jd�rBq$ttjj||���&}x|D]}|j	|j
�|f�q\WWdQRXq$Wt��x4|jj�j
�jdd�|D�d�D]}�j	|j�q�Wx6�fdd�|D�D] \}}tjtdj||d���q�W�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.6/needs_restarting.py�	<setcomp>Bsz'get_options_from_dir.<locals>.<setcomp>)�namecsh|]}|d�kr|�qS)rr
)rr)�packagesr
r
rDsz`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�baseZoptionsr�fp�linerrr
)rr
�get_options_from_dir0s"
$&r(ccs�x�t�D]�\}}y<|dk	r(|t|�kr(wt|ddd��}|j�}WdQRXWn"tk
rntjd|�wYnXx$|D]}t||�}|dk	rv|VqvWqWdS)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_filesKs

r6ccsNxHtjd�D]:}yt|�}Wntk
r2wYnXd|}||fVqWdS)Nz/procz/proc/%d/smaps)rr�int�
ValueError)Zdir_r2r3r
r
r
r,\sr,cst��i����fdd�}|S)Ncs,�j|��}|�k	r|S�|�}|�|<|S)N)�get)Zparam�val)�cache�func�sentinelr
r
�wrapperiszmemoize.<locals>.wrapper)�object)r<r>r
)r;r<r=r
�memoizefsr@cCstj|�tjS)N)r�stat�ST_UID)�fnamer
r
r
r-ssr-cCs$|j�j|d�j�}|r |dSdS)N)rr)rr!�run)rrCZmatchesr
r
r
�owning_packagewsrEcCsPd|}t|��}tjj|j��}WdQRXdj|jd��}td||f�dS)Nz/proc/%d/cmdline� �z%d : %s)r�dnfZi18nZucd�readr�split�print)r2ZcmdlineZcmdline_fileZcommandr
r
r
�	print_cmd~s

rLc	Cs�tj�}|jdd�}tj|d�}d}y|jd|j|��}Wn<tjk
rv}zt|�}tjdj	||��dSd}~XnXtj|dd�}|j
dd�}|jd	�r�|SdS)
Nzorg.freedesktop.systemd1z/org/freedesktop/systemd1z org.freedesktop.systemd1.Managerz)Failed to get systemd unit for PID {}: {}zorg.freedesktop.DBus.Properties)Zdbus_interfacezorg.freedesktop.systemd1.UnitZIdz.service)rZ	SystemBusZ
get_objectZ	InterfaceZGetUnitByPIDZ
DBusException�strrr"r#ZGetr)	r2ZbusZsystemd_manager_objectZsystemd_manager_interfaceZ
service_proxy�e�msgZservice_propertiesrr
r
r
�get_service_dbus�s0

rPcCsn|jd�}|dkrdS|jd�dkr(dS||d�j�}|jd�}|dkrVt||d�St||d|�d�SdS)N�/rz00:z
 (deleted)FT)�find�strip�rfind�
OpenedFile)r2r'Zslash�fnZsuffix_indexr
r
r
r0�s

r0c@s*eZdZejd�Zdd�Zedd��ZdS)rUz^(.+);[0-9A-Fa-f]{8,}$cCs||_||_||_dS)N)�deletedrr2)�selfr2rrWr
r
r
�__init__�szOpenedFile.__init__cCs(|jr"|jj|j�}|r"|jd�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.

        �)rW�RE_TRANSACTION_FILE�matchr�group)rXr\r
r
r
�
presumed_name�s

zOpenedFile.presumed_nameN)	�__name__�
__module__�__qualname__�re�compiler[rY�propertyr^r
r
r
r
rU�s
rUc@s4eZdZdd�Zedd��Zedd��Zdd�Zd	S)
�ProcessStartcCs|j�|_|j�|_dS)N)�
get_boot_time�	boot_time�get_sc_clk_tck�
sc_clk_tck)rXr
r
r
rY�s
zProcessStart.__init__cCshttjd�j�}tjjd�rdtdd��8}|j�j�j	�dj�}tt
j
�t|��}t||�SQRX|S)a	
        We have two sources from which to derive the boot time. These values vary
        depending on containerization, existence of a Real Time Clock, etc.
        For our purposes we want the latest derived value.
        - 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.
        - /proc/uptime
             Seconds field of /proc/uptime subtracted from the current time
             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
        z/proc/1z/proc/uptime�rbrN)
r7rrA�st_mtimer�isfiler�readlinerSrJ�time�float�max)Zproc_1_boot_time�fZuptimeZproc_uptime_boot_timer
r
r
rf�szProcessStart.get_boot_timecCstjtjd�S)N�
SC_CLK_TCK)r�sysconf�
sysconf_namesr
r
r
r
rh�szProcessStart.get_sc_clk_tckc
CsLd|}t|��}|j�j�j�}WdQRXt|d�}||j}|j|S)Nz
/proc/%d/stat�)rrIrSrJr7rirg)rXr2Zstat_fnZ	stat_fileZstatsZticks_after_bootZsecs_after_bootr
r
r
�__call__�s

zProcessStart.__call__N)r_r`rarY�staticmethodrfrhrvr
r
r
r
re�srec@s4eZdZd
Zed�Zedd��Zdd�Zdd�Z	d	S)�NeedsRestartingCommand�needs-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_argparsers


z$NeedsRestartingCommand.set_argparsercCs|jj}d|_dS)NT)�cli�demandsZsack_activation)rXr�r
r
r
�	configuresz NeedsRestartingCommand.configurecCsNt�}tjt|jj�}t|�}ttj	j
|jjjd�|j�}t
j|�|jj�r�t�}t�}|jjj�j�}x,|jt
d�D]}|j|jkrx|j|j�qxW|jdddgd�}t|�dkr�x,|jtd�D]}|j|jkr�|j|j�q�W|s�|�rfttd��xt|�D]}	td|	��qWxt|�D]}	td	|	��q$Wt�ttd
��ttd�d�tjj ��nttd
��ttd��dSt�}
|jj!�r�tj"�nd}xHt#|�D]<}||j$�}|dk�rĐq�|j||j%�k�r�|
j|j%��q�W|jj&�r.tdd�t|
�D��}
x |
D]}	|	dk	�rt|	��qWdSxt|
�D]}t'|��q8WdS)Nz#etc/dnf/plugins/needs-restarting.d/)rrzdbus-daemonzdbus-brokerrz;Core libraries or services have been updated since boot-up:z  * %sz8  * %s (dependency of dbus. Recommending reboot of dbus)z2Reboot 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
)rP)rr2r
r
r
�
<listcomp>Bsz.NeedsRestartingCommand.run.<locals>.<listcomp>)(re�	functools�partialrEr%rr@r(rrrZconfZinstallroot�NEED_REBOOT�extendZoptsZ
reboothintrrr r!Zinstalltimergrr�len�NEED_REBOOT_DEPENDS_ON_DBUSrKr�sortedrH�
exceptions�ErrorZuseronly�geteuidr6r^r2ZservicesrL)rXZ
process_startZ
owning_pkg_fn�optZneed_rebootZneed_reboot_depends_on_dbusr rZdbus_installedrZ
stale_pidsr1r5�namesr2r
r
r
rDsd







zNeedsRestartingCommand.runN)ry)
r_r`ra�aliasesrZsummaryrwrr�rDr
r
r
r
rx�s

rx)#Z
__future__rrrrZdnfpluginscorerrrHZdnf.clirr�rrbrArnr�r�r(r6r,r@r-rErLrPr0r?rUreZpluginZregister_commandr�ZCommandrxr
r
r
r
�<module>s:

"+
Back to Directory File Manager
<