o
    •Û_:  ã                   @   s\   d dl Z ddlmZ ddlT d dlZd dlmZ d dlm	Z	 ej
 ¡ ZG dd„ dejƒZdS )	é    Né   )Úbase)Ú*)Ú
exceptions)Úcommandsc                       sh   e Zd ZdZedd„ ƒZ‡ fdd„Zedd„ ƒZdd	„ Zd
d„ Z	e
dƒdd„ ƒZedƒdd„ ƒZ‡  ZS )ÚSelinuxPluginz&
	Plugin for tuning SELinux options.
	c                 C   s(   d}t j |¡sd}t j |¡sd }|S )Nz/sys/fs/selinuxz/selinux)ÚosÚpathÚexists)Úselfr	   © r   ú>/usr/lib/python3/dist-packages/tuned/plugins/plugin_selinux.pyÚ_get_selinux_path   s   zSelinuxPlugin._get_selinux_pathc                    sT   t ƒ | _|  ¡ | _| jd u rt d¡‚tj | jdd¡| _	t
t| ƒj|i |¤Ž d S )NzFSELinux is not enabled on your system or incompatible version is used.ÚavcÚcache_threshold)r   Ú_cmdr   Ú_selinux_pathr   ÚNotSupportedPluginExceptionr   r	   ÚjoinÚ_cache_threshold_pathÚsuperr   Ú__init__)r   ÚargsÚkwargs©Ú	__class__r   r   r      s   


zSelinuxPlugin.__init__c                 C   s   dd iS )NÚavc_cache_thresholdr   )r   r   r   r   Ú_get_config_options    s   ÿz!SelinuxPlugin._get_config_optionsc                 C   s   d|_ d|_d S )NTF)Ú_has_static_tuningÚ_has_dynamic_tuning©r   Úinstancer   r   r   Ú_instance_init&   s   
zSelinuxPlugin._instance_initc                 C   s   d S )Nr   r    r   r   r   Ú_instance_cleanup*   s   zSelinuxPlugin._instance_cleanupr   c                 C   s8   |d u rd S t |ƒ}|dkr|s| j | j|¡ |S d S ©Nr   )Úintr   Úwrite_to_filer   )r   ÚvalueÚsimÚ	thresholdr   r   r   Ú_set_avc_cache_threshold-   s   z&SelinuxPlugin._set_avc_cache_thresholdc                 C   s&   | j  | j¡}t|ƒdkrt|ƒS d S r$   )r   Ú	read_filer   Úlenr%   )r   r'   r   r   r   Ú_get_avc_cache_threshold9   s   z&SelinuxPlugin._get_avc_cache_threshold)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr   r   r   r"   r#   Úcommand_setr*   Úcommand_getr-   Ú__classcell__r   r   r   r   r   
   s    


r   )r   Ú r   Ú
decoratorsÚ
tuned.logsÚtunedÚtuned.pluginsr   Útuned.utils.commandsr   ÚlogsÚgetÚlogÚPluginr   r   r   r   r   Ú<module>   s    
