HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/sos/policies/distros/__pycache__/__init__.cpython-310.pyc
o

([Qh�>�@s�ddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZdd	lmZdd
lmZmZmZmZdZdZd
ZGdd�de�ZGdd�de�ZdS)�N)�_sos)�Policy)�
InitSystem)�SystemdInit)�CrioContainerRuntime)�PodmanContainerRuntime)�DockerContainerRuntime)�LxdContainerRuntime)�	shell_out�
is_executable�bold�sos_get_command_outputz/etc/os-release�	container�HOSTcs2eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZdZd	ZdZdZ	
	d9�fdd�	Zed
d��Zed:dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zedd��Zedd ��Z ed!d"��Z!d#d$�Z"d%d&�Z#d'd(�Z$d)d*�Z%d+d,�Z&d-d.�Z'd/d0�Z(d1d2�Z)d;d3d4�Z*d5d6�Z+d7d8�Z,�Z-S)<�LinuxPolicyzfThis policy is meant to be an abc class that provides common
    implementations used in Linux distros�Nonez/bin:/sbin:/usr/bin:/usr/sbinN��dockerFz/usr/binzsos-collector-tmpTcs&t�j|||d�|r||_n|��pd|_|��|dur"||_ntj�d�r0t	|jd�|_nt
�|_i|_|jr�t
|d�t|d�t|d�t|d�g}|D]#}|��rq||j|j<|j|jkri|j|j|jd<|j|j��qN|jr�d|jvr�t|j���}|j|d|jd<dSdSdSdS)N)�sysroot�
probe_runtime�remote_exec�/z/run/systemd/system/)�chroot)�policy�defaultr)�super�__init__r�_container_init�init_kernel_modules�init_system�os�path�isdirrr�runtimesrrrrr	�check_is_active�name�default_container_runtime�load_container_info�list�keys)�selfr�initrr�_crun�runtime�idx��	__class__��?/usr/lib/python3/dist-packages/sos/policies/distros/__init__.pyr;s@����zLinuxPolicy.__init__cCsddgS)Nz/etc/passwdz/etc/shadowr1��clsr1r1r2�set_forbidden_pathsds�zLinuxPolicy.set_forbidden_pathscs��fdd�}|r||�Stj��j�r'tj��j�tj�tj��j��kr'dSttddd��}||���Wd�S1s?wYdS)�|
        This function is responsible for determining if the underlying system
        is supported by this policy.
        cs`�jg}�jr
|��j�|��D]}|�d�r-|�d�dd�d�d�}||vr-dSqdS)N)zNAME=zID=�=�rz"'TF)�os_release_name�
os_release_id�append�
splitlines�
startswith�split�strip)�content�_matches�line�_distror3r1r2�_check_releaseqs
�z)LinuxPolicy.check.<locals>._check_releaseT�r�utf-8��encodingN)	r r!�isfile�os_release_file�basename�realpath�open�
OS_RELEASE�read)r4�remoterD�fr1r3r2�checkks�
$�zLinuxPolicy.checkcC�|jS�N)�release�r*r1r1r2�kernel_version��zLinuxPolicy.kernel_versioncCrSrT)�hostnamerVr1r1r2�	host_name�rXzLinuxPolicy.host_namecCrSrT)�smprVr1r1r2�
is_kernel_smp�rXzLinuxPolicy.is_kernel_smpcCrSrT)�machinerVr1r1r2�get_arch�rXzLinuxPolicy.get_archcCs|��S)z)Returns the name usd in the pre_work step)rZrVr1r1r2�get_local_name�szLinuxPolicy.get_local_namecCst�dd|�S)Nz[^-a-z,A-Z.0-9]r)�re�sub)r*r%r1r1r2�sanitize_filename�szLinuxPolicy.sanitize_filenamecCs6|tkr|�|�dS|�|j�d��|�|�dS)Nz Distribution Policy)r�display_self_help�	set_titler9�display_distro_help�r4�sectionr1r1r2�display_help�szLinuxPolicy.display_helpcCs|�d�|�d�dS)NzSoS Distribution Policiesz�Distributions supported by SoS will each have a specific policy defined for them, to ensure proper operation of SoS on those systems.)rd�add_textrfr1r1r2rc�s
�zLinuxPolicy.display_self_helpc	Cs6|jr|jtjur|�|j�n|�d�|ddd�}|�d|j���|jd|j��dd�|jd|j��dd�|�d�}|jD]}|jdd	�|d
d�|dd
��dd�qB|�d�}|jtdd	�dd�dd�dd���dd�|j	�
�D] \}}d�|j�
��}|jdd	�|d�|jd�|d��dd�qxdS)Nz;
Detailed help information for this policy is not availableFzDefault --upload location: zDefault container runtime: )�newlinez $PATH used when running report: zReference URLs� z>8rz<30r8z<40z#Presets Available With This Policy
zPreset Namez<20�Descriptionz<45zEnabled Options)�__doc__rri�_upload_urlr&�PATH�add_section�vendor_urlsr�presets�items�join�opts�to_args�desc)	r4rg�_pol�refsec�url�presec�preset�value�_optsr1r1r2re�sH�
�
�
�

*
�����zLinuxPolicy.display_distro_helpcCs^ttjvr-tjtdvr-d|_ttjvr-tjtsdStj�tjt|j�|_tjtSdS)z�Check if sos is running in a container and perform container
        specific initialisation based on ENV_HOST_SYSROOT.
        )r�oci�podmanTN)�
ENV_CONTAINERr �environ�
_in_container�ENV_HOST_SYSROOTr!�abspath�_tmp_dirrVr1r1r2r�s


�
zLinuxPolicy._container_initc
Csg|_t��j}tdd|jd���}|j�dd�|dd�D��|�d|�d	��}z0t	|d
dd��}|D]}|�
d
�d�
d�d}|j�|�q5Wd�n1sTwYWntyu}z|j
�d|���WYd}~nd}~wwddd�}d|��d|�d�f}	|	D]}
|�|
�}
tj�|
�r�|
}n	q�|j
�d�dSg}	z,t	|d
dd��}|D]}d|vr�|	�|�
d�d�q�Wd�n1s�wYWnty�}z|j
�d|���WYd}~nd}~ww|��D]\}
}||	vr�|j�|
�q�dS)zxObtain a list of loaded kernel modules to reference later for plugin
        enablement and SoSPredicate checks
        �lsmodr)�timeoutrcSsg|]
}|��d���qS)r)r>r?)�.0rBr1r1r2�
<listcomp>�s�z3LinuxPolicy.init_kernel_modules.<locals>.<listcomp>r8Nz/usr/lib/modules/z/modules.builtinrErFrGr���z.koz Unable to read kernel builtins: �CONFIG_NET_DEVLINK�CONFIG_BLK_DEV_DM)�devlink�dm_modz
/boot/config-z
/lib/modules/z/configz#Unable to find booted kernel configz=yz%Unable to read booted kernel config: )�kernel_modsr �unamerUr
rr<�extend�join_sysrootrMr>r;�IOError�soslog�warningr!�existsrs)r*rU�lines�builtins�mfilerB�kmod�err�config_strings�kconfigs�kconfig�
booted_config�kfile�builtinr}r1r1r2r�sl

�
�������
�
���������zLinuxPolicy.init_kernel_modulescCs*|jr|jdkrtj�|j|�d��}|S)Nr)rr r!rt�lstrip)r*r!r1r1r2r�#szLinuxPolicy.join_sysrootcCs(|jd}|jr|��|�|�|_dS)N�cmdlineopts)�commons�low_priority�_configure_low_priority�prompt_for_case_id�case_id�r*�cmdline_optsr1r1r2�pre_work(s
zLinuxPolicy.pre_workcCs8|js|js|jsttd��|_|jr|jnd|_|jS)NzNOptionally, please enter the case id that you are generating this report for: r)�batch�quietr��input�_r�r1r1r2r�3s����zLinuxPolicy.prompt_for_case_idc
Cs�t��}td�r2td|��dd�}|ddkr|j�d�nd|d	�d
|d�d�}|j�|�n|j�d�zt�	d
�|j�d�WdSt
yb}z|j�d|���WYd}~dSd}~ww)ayUsed to constrain sos to a 'low priority' execution, potentially
        letting individual policies set their own definition of what that is.

        By default, this will attempt to assign sos to an idle io class via
        ionice if available. We will also renice our own pid to 19 in order to
        not cause competition with other host processes for CPU time.
        �ionicezionice -c3 -p �)r��statusrzSet IO class to idlez Error setting IO class to idle: �outputz (exit code �)zNWarning: unable to constrain report to idle IO class: ionice is not available.�zSet niceness of report to 19z%Error setting report niceness to 19: N)r �getpidrr
r��info�error�ui_logr��nice�	Exception)r*�_pid�ret�msgr�r1r1r2r�@s*
���
 ��z#LinuxPolicy._configure_low_prioritycC�dS)z�If sos report commands need to always be prefixed with something,
        for example running in a specific container image, then it should be
        defined here.

        If no prefix should be set, return an empty string instead of None.
        rr1rVr1r1r2�set_sos_prefix_szLinuxPolicy.set_sos_prefixcCr�)zcIf a host requires additional cleanup, the command should be set and
        returned here
        rr1rVr1r1r2�set_cleanup_cmdhszLinuxPolicy.set_cleanup_cmdcCr�)aIReturns the command that will create the container that will be
        used for running commands inside a container on hosts that require it.

        This will use the container runtime defined for the host type to
        launch a container. From there, we use the defined runtime to exec into
        the container's namespace.

        :param image:   The name of the image if not using the policy default
        :type image:    ``str`` or ``None``

        :param auth:    The auth string required by the runtime to pull an
                        image from the registry
        :type auth:     ``str`` or ``None``

        :param force_pull:  Should the runtime forcibly pull the image
        :type force_pull:   ``bool``

        :returns:   The command to execute to launch the temp container
        :rtype:     ``str``
        rr1)r*�image�auth�
force_pullr1r1r2�create_sos_containerosz LinuxPolicy.create_sos_containercCs|j�d|j��S)a�Restarts the container created for sos collect if it has stopped.

        This is called immediately after create_sos_container() as the command
        to create the container will exit and the container will stop. For
        current container runtimes, subsequently starting the container will
        default to opening a bash shell in the container to keep it running,
        thus allowing us to exec into it again.
        z start ��container_runtime�sos_container_namerVr1r1r2�restart_sos_container�s
z!LinuxPolicy.restart_sos_containercCs"|jr|j�d|j�d|��S|S)aReturns the command that allows us to exec into the created
        container for sos collect.

        :param cmd: The command to run in the sos container
        :type cmd: ``str``

        :returns: The command to execute to run `cmd` in the container
        :rtype: ``str``
        z exec rkr�)r*�cmdr1r1r2�format_container_command�s
�z$LinuxPolicy.format_container_command)NNTN�r)NNF).�__name__�
__module__�__qualname__rm�vendorror+rJr9r:rnr&�_preferred_hash_name�
containerized�container_image�sos_path_strip�sos_pkg_name�sos_bin_pathr��container_version_command�container_authfiler�classmethodr5rRrWrZr\r^r_rbrhrcrerrr�r�r�r�r�r�r�r�r��
__classcell__r1r1r/r2r#sb�)



*;
	
rc@s,eZdZdZdgZdZdZed	dd��ZdS)
�GenericLinuxPolicyz�This Policy will be returned if no other policy can be loaded. This
    should allow for IndependentPlugins to be executed on any system)zUpstream Projectz https://github.com/sosreport/sos�SoSaSoS was unable to determine that the distribution of this system is supported, and has loaded a generic configuration. This may not provide desired behavior, and users are encouraged to request a new distribution-specifc policy at the GitHub project above.
rcCst�)r6)�NotImplementedError)r4rPr1r1r2rR�szGenericLinuxPolicy.checkNr�)	r�r�r�rmrqr��vendor_textr�rRr1r1r1r2r��sr�)r r`�sosrr��sos.policiesr�sos.policies.init_systemsr�!sos.policies.init_systems.systemdr�sos.policies.runtimes.crior�sos.policies.runtimes.podmanr�sos.policies.runtimes.dockerr�sos.policies.runtimes.lxdr	�
sos.utilitiesr
rrr
rNr�r�rr�r1r1r1r2�<module>s&