File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/restartcheck.cpython-310.pyc
Back
o ;jY` � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddl Zddl ZdZdZzddl Z dZW n ey; Y nw g d�Zdd� Zd d � Zdd� Zd d� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zddd�ZdS ) a� checkrestart functionality for Debian and Red Hat Based systems Identifies services (processes) that are linked against deleted files (for example after downloading an updated binary of a shared library). Based on checkrestart script from debian-goodies (written by Matt Zimmerman for the Debian GNU/Linux distribution, https://packages.debian.org/debian-goodies) and psdel by Sam Morris. :codeauthor: Jiri Kotlin <jiri.kotlin@ultimum.io> � N� NILinuxRTFT)z ^/var/log/z^/var/local/log/z ^/var/run/z^/var/local/run/z^/tmp/z ^/dev/shm/z^/run/z^/drmz ^/var/tmp/z^/var/local/tmp/z ^/dev/zeroz ^/dev/pts/z^/usr/lib/locale/z^/home/z^.*icon-theme.cachez^/var/cache/fontconfig/z^/var/lib/nagios3/spool/z%^/var/lib/nagios3/spool/checkresults/z^/var/lib/postgresql/z^/var/lib/vdr/z^/[aio]z^/SYSVc C s t rt S dS )z` Only run this module if the psutil python module is installed (package python-psutil). )FzMissing dependency: psutil)� HAS_PSUTIL� r r �M/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/restartcheck.py�__virtual__P s r c C sH d}| � d�r d}t�d��| �rd}t�d�t��}|�| �r"d}|S )z� Filters file path against unwanted directories and decides whether file is marked as deleted. Returns: True if file is desired deleted file, else False. Args: path: A string - path to file. Fz (deleted)Tz\(path inode=[0-9]+\)$�|)�endswith�re�compile�search�join� LIST_DIRS�match)�path�retZregexr r r �_valid_deleted_fileZ s r c c sF � g } t �� D �]}z |jddgd�}W n t jt jt jfy# Y qw z1tjj� d� |d ���}dt|d � d }t� |�}|�� }W d � n1 sOw Y W n tt jt jt jfye Y qw t�d�}|D ]9}tjj�|�}|�|�} | s~qm| �d �} | s�qmt| �}|s�qm|d |d | d d� f}|| vr�| �|� |V qmzh|D ]c} || } t�| �}g }tj�|�r�|�|� n(tj�|�r�|dkr�tjjj|d d�D ]\}}}|D ]}|�tj�||�� q�q�|D ]}t|�}|s�q�|d |d |f}|| v�r| �|� |V q�q�W q tt jt jt jf�y Y qw dS )z� Iterates over /proc/PID/maps and /proc/PID/fd links and returns list of desired deleted files. Returns: List of deleted files to analyze, False on failure. �pid�name)�attrsz /proc/{}/maps�/proc/z/fd/Nza^[\da-f]+-[\da-f]+ [r-][w-][x-][sp-] [\da-f]+ [\da-f]{2}:[\da-f]{2} (\d+) *(.+)( \(deleted\))?\n$� r i�����/T)�followlinks)�psutilZprocess_iterZas_dictZ NoSuchProcessZ ZombieProcessZAccessDenied�salt�utils�files�fopen�format�str�os�listdir� readlines�OSErrorr r �stringutils� to_unicoder �groupr �append�readlinkr �isfile�isdirZos_walkr )Z deleted_files�procZpinfo�maps�dirpathr! ZmaplinesZmapline�lineZmatchedr Zvalid�val�linkr( � filenames�rootZ dummy_dirsr r �filenamer r r �_deleted_filesp s� ��� �� �� � � �� ������r4 c C s |s|| }| r |� d� |S d}| rd}|r$|d�t|��7 }|d7 }|rc|d�t|��7 }|D ]}||d 7 }|| d D ]} || d 7 }q?q1|rV|d 7 }|d �|�7 }|rc|d7 }|d �|�7 }|r�|d�t|��7 }|D ]}||d 7 }|| d D ]} || d 7 }q~qp|S ) a Formats the output of the restartcheck module. Returns: String - formatted output. Args: kernel_restart: indicates that newer kernel is instaled. packages: list of packages that should be restarted. verbose: enables extensive output. restartable: list of restartable packages. nonrestartable: list of non-restartable packages. restartservicecommands: list of commands to restart services. restartinitcommands: list of commands to restart init.d scripts. zSystem restart required.� zSystem restart required. z9Found {} processes using old versions of upgraded files. zThese are the packages: zlOf these, {} seem to contain systemd service definitions or init scripts which can be used to restart them: z: � processes� z" These are the systemd services: z These are the initd scripts: zT These processes {} do not seem to have an associated init script to restart them: )r'