<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
f`.              	   @   s$  d dl mZ d dl mZ d dl mZ d dl mZ d dlmZmZ d dlZd dl	Zd dl
Z
d dlZd dlZd dlZd dlZd dlZddd	d
dddddg	ZdgZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" ZG d#d$ d$eZG d%d& d&eZejjG d'd( d(ej j!Z"dS ))    )absolute_import)division)print_function)unicode_literals)logger_NZkernelz	kernel-rtZglibczlinux-firmwareZsystemddbuszdbus-brokerzdbus-daemonZmicrocode_ctlzlibc                s   t jj| st S t }xjt j| D ]\}t jj|s$|jd rBq$tt jj| |&}x|D ]}|j	|j
 |f q\W W dQ R X q$W t  x4|jj j jdd |D dD ]} j	|j qW x6 fdd|D D ] \}}tjtdj||d qW  S )	z
    Provide filepath as string if single dir or list of strings
    Return set of package names contained in files under filepath
    z.confNc             S   s   h | ]}|d  qS )r    ).0xr
   r
   &/usr/lib/python3.6/needs_restarting.py	<setcomp>B   s    z'get_options_from_dir.<locals>.<setcomp>)namec                s   h | ]}|d   kr|qS )r   r
   )r   r   )packagesr
   r   r   D   s    z`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filterr   r   warningr   format)filepathbaseZoptionsr   fpliner   r   r
   )r   r   get_options_from_dir0   s"    
$&r(   c             c   s   xt  D ]\}}y<| d k	r(| t|kr(wt|ddd}|j }W d Q R X W n" tk
rn   tjd| wY nX x$|D ]}t||}|d k	rv|V  qvW qW d S )Nrreplace)errorszFailed to read PID %d's smaps.)
list_smaps	owner_uidr   	readlinesEnvironmentErrorr   r"   smap2opened_file)uidpidsmapsZ
smaps_filelinesr'   ofiler
   r
   r   list_opened_filesK   s    

r6   c              c   sN   xHt jdD ]:} yt| }W n tk
r2   wY nX d| }||fV  qW d S )Nz/procz/proc/%d/smaps)r   r   int
ValueError)Zdir_r2   r3   r
   r
   r   r,   \   s    r,   c                s   t  i   fdd}|S )Nc                s,    j | }|k	r|S | }| | < |S )N)get)Zparamval)cachefuncsentinelr
   r   wrapperi   s    zmemoize.<locals>.wrapper)object)r<   r>   r
   )r;   r<   r=   r   memoizef   s    r@   c             C   s   t j| tj S )N)r   statST_UID)fnamer
   r
   r   r-   s   s    r-   c             C   s$   | j  j|dj }|r |d S d S )N)r   r   )r   r!   run)r   rC   Zmatchesr
   r
   r   owning_packagew   s    rE   c             C   sP   d|  }t |}tjj|j }W d Q R X dj|jd}td| |f  d S )Nz/proc/%d/cmdline  z%d : %s)r   dnfZi18nZucdreadr   splitprint)r2   ZcmdlineZcmdline_fileZcommandr
   r
   r   	print_cmd~   s
    
rL   c       	      C   s   t j }|jdd}t j|d}d }y|jd|j| }W n< t jk
rv } zt|}tjdj	| | d S d }~X nX t j|dd}|j
dd}|jd	r|S d S )
Nzorg.freedesktop.systemd1z/org/freedesktop/systemd1z org.freedesktop.systemd1.Managerz)Failed to get systemd unit for PID {}: {}zorg.freedesktop.DBus.Properties)Zdbus_interfacezorg.freedesktop.systemd1.UnitZIdz.service)r   Z	SystemBusZ
get_objectZ	InterfaceZGetUnitByPIDZDBusExceptionstrr   r"   r#   ZGetr   )	r2   ZbusZsystemd_manager_objectZsystemd_manager_interfaceZservice_proxyemsgZservice_propertiesr   r
   r
   r   get_service_dbus   s0    

rP   c             C   sn   |j d}|dk rd S |j ddkr(d S ||d  j }|jd}|dk rVt| |dS t| |d | dS d S )N/r   z00:z
 (deleted)FT)findstriprfind
OpenedFile)r2   r'   ZslashfnZsuffix_indexr
   r
   r   r0      s    

r0   c               @   s*   e Zd ZejdZdd Zedd ZdS )rU   z^(.+);[0-9A-Fa-f]{8,}$c             C   s   || _ || _|| _d S )N)deletedr   r2   )selfr2   r   rW   r
   r
   r   __init__   s    zOpenedFile.__init__c             C   s(   | j r"| jj| j}|r"|jdS | jS )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)rX   r\   r
   r
   r   presumed_name   s
    
zOpenedFile.presumed_nameN)	__name__
__module____qualname__recompiler[   rY   propertyr^   r
   r
   r
   r   rU      s   
rU   c               @   s4   e Zd Zdd Zedd Zedd Zdd Zd	S )
ProcessStartc             C   s   | j  | _| j | _d S )N)get_boot_time	boot_timeget_sc_clk_tck
sc_clk_tck)rX   r
   r
   r   rY      s    
zProcessStart.__init__c              C   sh   t tjdj} tjjdrdtdd8}|j j j	 d j }t t
j
 t| }t| |S Q R X | 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rbr   N)r7   r   rA   st_mtimer   isfiler   readlinerS   rJ   timefloatmax)Zproc_1_boot_timefZuptimeZproc_uptime_boot_timer
   r
   r   rf      s    zProcessStart.get_boot_timec               C   s   t jt jd S )N
SC_CLK_TCK)r   sysconfsysconf_namesr
   r
   r
   r   rh      s    zProcessStart.get_sc_clk_tckc          
   C   sL   d| }t |}|j j j }W d Q R X t|d }|| j }| j| S )Nz/proc/%d/stat   )r   rI   rS   rJ   r7   ri   rg   )rX   r2   Zstat_fnZ	stat_fileZstatsZticks_after_bootZsecs_after_bootr
   r
   r   __call__   s    

zProcessStart.__call__N)r_   r`   ra   rY   staticmethodrf   rh   rv   r
   r
   r
   r   re      s   re   c               @   s4   e Zd Zd
ZedZedd Zdd Zdd Z	d	S )NeedsRestartingCommandneeds-restartingz/determine updated binaries that need restartingc             C   sF   | j dddtdd | j dddtdd | j d	d
dtdd d S )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_argparser  s    


z$NeedsRestartingCommand.set_argparserc             C   s   | j j}d|_d S )NT)clidemandsZsack_activation)rX   r   r
   r
   r   	configure  s    z NeedsRestartingCommand.configurec             C   sN  t  }tjt| jj}t|}ttj	j
| jjjd| j}tj| | jjrt }t }| jjj j }x,|jtdD ]}|j|jkrx|j|j qxW |jdddgd}t|dkrx,|jtdD ]}|j|jkr|j|j qW |s|rfttd xt|D ]}	td|	  qW xt|D ]}	td	|	  q$W t  ttd
 ttdd tjj  nttd ttd d S t }
| jj!rtj" nd }xHt#|D ]<}||j$}|d krĐq|j||j%kr|
j|j% qW | jj&r.tdd t|
D }x |D ]}	|	d k	rt|	 qW dS xt|
D ]}t'| q8W d S )Nz#etc/dnf/plugins/needs-restarting.d/)r   r   zdbus-daemonzdbus-brokerr   z;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.zMore information:z)https://access.redhat.com/solutions/27943z>No core libraries or services have been updated since boot-up.zReboot should not be necessary.c             S   s   g | ]}t |qS r
   )rP   )r   r2   r
   r
   r   
<listcomp>B  s    z.NeedsRestartingCommand.run.<locals>.<listcomp>)(re   	functoolspartialrE   r%   r   r@   r(   r   r   r   ZconfZinstallrootNEED_REBOOTextendZoptsZ
reboothintr   r   r    r!   Zinstalltimerg   r   r   lenNEED_REBOOT_DEPENDS_ON_DBUSrK   r   sortedrH   
exceptionsErrorZuseronlygeteuidr6   r^   r2   ZservicesrL   )rX   Zprocess_startZowning_pkg_fnoptZneed_rebootZneed_reboot_depends_on_dbusr    r   Zdbus_installedr   Z
stale_pidsr1   r5   namesr2   r
   r
   r   rD     sd    







zNeedsRestartingCommand.runN)ry   )
r_   r`   ra   aliasesr   Zsummaryrw   r   r   rD   r
   r
   r
   r   rx      s
   
rx   )#Z
__future__r   r   r   r   Zdnfpluginscorer   r   rH   Zdnf.clir   r   r   rb   rA   rn   r   r   r(   r6   r,   r@   r-   rE   rL   rP   r0   r?   rU   re   ZpluginZregister_commandr   ZCommandrx   r
   r
   r
   r   <module>   s:   
"+