%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.9/site-packages/tuned/daemon/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.9/site-packages/tuned/daemon/__pycache__/controller.cpython-39.opt-1.pyc

a

���h�J�@s�ddlmZddlZddlZddlmZddlZddlmZddlm	Z	ddl
mZddlZddl
Z
dgZej��ZGdd�de�ZGd	d�dejjj�ZdS)
�)�exportsN)�TunedException)�commands)�hotplug�
Controllerc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
TimerStorecCst�|_t��|_dS�N)�dict�_timers�	threading�Lock�_timers_lock��self�r�;/usr/lib/python3.9/site-packages/tuned/daemon/controller.py�__init__szTimerStore.__init__cCs4|j�||j|<Wd�n1s&0YdSr)r
r
�r�token�timerrrr�store_timerszTimerStore.store_timercCsV|j�<z|j|}|��|j|=WnYn0Wd�n1sH0YdSr)r
r
�cancelrrrr�
drop_timers
zTimerStore.drop_timercCsL|j�2|j��D]}|��q|j��Wd�n1s>0YdSr)r
r
�valuesr�clear)rrrrr�
cancel_all"s
zTimerStore.cancel_allN)�__name__�
__module__�__qualname__rrrrrrrrrs	rcs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Ze�	d
�dd��Z
d
d�Ze�dd�dZdd��Z
e�dd�d[dd��Ze�dd�d\dd��Zd]dd�Ze�dd�d^dd��Ze�dd�d_dd ��Zd!d"�Ze�dd#�d`d$d%��Ze�dd#�dad&d'��Ze�dd�dbd(d)��Ze�dd*�dcd+d,��Ze�dd�ddd-d.��Ze�dd�ded/d0��Ze�dd�dfd1d2��Ze�dd3�dgd4d5��Ze�dd6�dhd7d8��Ze�dd9�did:d;��Ze�dd�djd<d=��Ze�dd�dkd>d?��Ze�dd�dld@dA��Z e�ddB�dmdCdD��Z!e�dd�dndEdF��Z"e�ddG�dodHdI��Z#e�dd�dpdJdK��Z$e�dLd#�dqdMdN��Z%e�ddO�drdPdQ��Z&e�ddR�dsdSdT��Z'e�dUd#�dtdVdW��Z(e�dd#�dudXdY��Z)�Z*S)vrz�
	Controller's purpose is to keep the program running, start/stop the tuning,
	and export the controller interface (currently only over D-Bus).
	cs8tt|���||_||_t��|_t�|_	t
�|_dSr)�superrr�_daemon�_global_configr�Event�
_terminater�_cmdr�_timer_store)r�daemonZ
global_config��	__class__rrr.s
zController.__init__c	
Cs�t�d�|j��|j�tjtj�}|dk�r"t�d�t	j
�t	���}|j�
dtj�}z|�|�Wnty�t�d�Yn0d}t��}zTt��||kr�|j��s�|r�|jdd�}q�|j��s�|r�t�d	�n
t�d
�Wn8ttf�y}zt�d|�WYd}~n
d}~00~|��}|j�tjtj�}|�sP|�rPt��|�rt|j�|jd��stt���qVt�d
�|��dS)z1
		Controller main loop. The call is blocking.
		zstarting controllerrzwaiting for udev to settle�udev_buffer_sizez�cannot set udev monitor receive buffer size, we are probably running inside container or with limited capabilites, TuneD functionality may be limitedT�)�timeoutzudev settle timed outzudev settledzudev settle failed, '%s'Nzterminating controller) �log�infor#rr!Zget_int�constsZCFG_STARTUP_UDEV_SETTLE_WAITZ CFG_DEF_STARTUP_UDEV_SETTLE_WAIT�pyudevZMonitorZfrom_netlinkZContextZget_sizeZCFG_DEF_UDEV_BUFFER_SIZEZset_receive_buffer_size�EnvironmentError�warning�time�is_setZpoll�OSError�IOError�start�get_bool�
CFG_DAEMON�CFG_DEF_DAEMONrr$�waitZperiod_check�stop)	rZwait_settleZmonitorr)�p�t�e�resr&rrr�run6sD


�


$
zController.runcCs|j��dSr)r#�setrrrr�	terminatecszController.terminatecCs`|jj��r|jj��nBd}|r\|jj��|jj��|��sN|jj��|jj��}qdS)NT)r Z_sighup_processingr3Z_sighup_pendingrAr�reload)rZ	do_reloadrrr�sighupfszController.sighupZsbscCsdSrr)r�profile_name�resultZerrstrrrr�profile_changedrszController.profile_changedcCstj�|�|j�|�dSr��tuned�logs�log_capture_finishr%r)rrrrr�_log_capture_abort{szController._log_capture_abort�ii�sNcCsf|dkrdStj�|�}|dur$dS|dkrVtj||j|gd�}|j�||�|��|durbdS|S)N�r)�args)	rIrJ�log_capture_startr�TimerrLr%rr6)rZ	log_levelr+�callerrrrrrrQs�zController.log_capture_startcCs4|dkrdStj�|�}|j�|�|dur0dS|S�NrOrH)rrrSr?rrrrK�s
zController.log_capture_finishrO�bcCsD|dkrdS|j�tjtj�r:|j��r,dS|j��s:dS|j��S)NrOFT)	r!r7r.r8r9r �
is_running�
is_enabledr6�rrSrrrr6�s

zController.startFcCs,|j��sd}n|jj|d�}|j��|S)NT��profile_switch)r rVr;r%r)rrZr?rrr�_stop�s


zController._stopcCs|dkrdS|jdd�S)NrOFrY)r[rXrrrr;�szController.stopc
Csv|dkrdS|j��r*|jdd�}|s*dSz|j��Wn4tyl}zt�d|�WYd}~dSd}~00|��S)NrOFTrYzFailed to reload TuneD: %s)r rVr[Zreload_profile_configrr,�errorr6)rrSZstop_okr>rrrrC�s
zController.reloadc
Cs|j��}d}d}d}z�z$|r,|jjdd�|j�||�Wnhtjjy�}zLd}t|�}|r�|jjj	|kr�t
�d|�d}nt
�d|�WYd}~n
d}~00W|r�|r�t
�d|�n|s�t
�
d�|j��n6|�r|r�t
�d|�n|�st
�
d�|j��0||fS)	N�OKTFrYz@Failed to reapply profile '%s'. Did it change on disk and break?zFailed to apply profile '%s'z>Applying previously applied (possibly out-dated) profile '%s'.z$Applying previously applied profile.)r rVr;Zset_profilerI�
exceptionsr�str�profile�namer,r\r1r-r6)rrE�manualZwas_running�msg�successZreapplyr>rrr�_switch_profile�s8
&
�
zController._switch_profilez(bs)cCs(|dkrdS|j�|�sdS|�|d�S)NrO�F�Unauthorized)FzInvalid profile_nameT)r$�
is_valid_namere�rrErSrrr�switch_profile�s
zController.switch_profilecCs |dkrdS|��}|�|d�S)NrOrfF)�recommend_profilere)rrSrErrr�auto_profile�szController.auto_profilecCs*|dkrdS|jjdur"|jjjSdSdSrT)r r`rarXrrr�active_profile�s

zController.active_profilez(ss)c
Cs�|dkrdS|jj}|durxz"|j��\}}|dur<|du}Wn8tyv}z d}t|�}||fWYd}~Sd}~00|r�tjntj}|dfS)NrO)�unknownrgrn)	r rbr$Zget_active_profilerr_r.ZACTIVE_PROFILE_MANUALZACTIVE_PROFILE_AUTO)rrSrbr`r>�moder\rrr�profile_mode�szController.profile_modecCs|dkrdS|jjpdSrT)r �post_loaded_profilerXrrrrqszController.post_loaded_profilecCsB|dkrdS|j��r |j��|j��r>|jjddddd�dS)NrOFT)Zsave_instantly)r rVr;rWZset_all_profilesrXrrr�disables


�zController.disablecCs|dkrdS|j��S)NrOF)r rVrXrrrrVszController.is_running�ascCs|dkrgS|jjj��SrT)r �profile_loader�profile_locatorZget_known_namesrXrrr�profilesszController.profilesza(ss)cCs|dkrgS|jjj��SrT)r rtruZget_known_names_summaryrXrrr�	profiles2szController.profiles2z(bsss)cCsR|dks|j�|�sdS|dus(|dkr0|��}t|jjj�|tj	tj
gdg��S)NrO)FrOrOrO)r$rhrm�tupler rtruZget_profile_attrsr.ZPROFILE_ATTR_SUMMARYZPROFILE_ATTR_DESCRIPTIONrirrr�profile_info%s
zController.profile_infocCs|dkrdS|jj��SrT)r Zprofile_recommenderZ	recommendrXrrrrk-szController.recommend_profilecCs|dkrdS|jjdd�S)NrOF�Zignore_missing�r �verify_profilerXrrrr|3szController.verify_profilecCs|dkrdS|jjdd�S)NrOFTrzr{rXrrr�verify_profile_ignore_missing9sz(Controller.verify_profile_ignore_missingz	a{sa{ss}}cCsr|dkriSi}|j��D]R}|j�d�d�dd�d}|��}i||<|��D]\}}t|�|||<qRq|S)zuReturn dictionary with accesible plugins

		Return:
		dictionary -- {plugin_name: {parameter_name: default_value}}
		rO�.����_r*)r �get_all_pluginsr�splitZ_get_config_options�itemsr_)rrS�pluginsZplugin_class�plugin_nameZconf_options�key�valrrrr�?szController.get_all_pluginscCs(|dks|j�|�sdS|j�t|��S)z"Return docstring of plugin's classrO)r$rhr �get_plugin_documentationr_�rr�rSrrrr�Qsz#Controller.get_plugin_documentationza{ss}cCs(|dks|j�|�siS|j�t|��S)z�Return dictionary with plugin's parameters and their hints

		Parameters:
		plugin_name -- name of plugin

		Return:
		dictionary -- {parameter_name: hint}
		rO)r$rhr �get_plugin_hintsr_r�rrrr�Xs
zController.get_plugin_hintscCsB|dks|j�|�sdS|jjr>|jjjr>|jjj�|�dSdS)z�Allows to dynamically add sockets to send signals to

		Parameters:
		path -- path to socket to register for sending signals

		Return:
		bool -- True on success
		rOFT)r$rhr Z_applicationZ_unix_socket_exporterZregister_signal_path)r�pathrSrrr�register_socket_signal_pathfs
z&Controller.register_socket_signal_path�ssc
Cs�|dkrdS|j�|�sdS|j�|�s,dSd}|jjjD]&}|j|kr:t�d|j�d}qbq:|s�d|}t�|�d|fSt	|j
tj�s�d	|j
j}t�|�d|fSt
|j�|��}t�d
|jt|�f�|jjjD]�}|j|@}	t|	�r�||	8}t�dt|	�|j|jf�|j
j|j
jk�rbd|j|j
jt|	�|j|j
jf}t�|�d|fS|j
�||	�|j
�||	�q�t|��r�d
t|�}t�|�d|fSdS)NrOrf)FzInvalid devices�F�Invalid instance_nameFzFound instance '%s'.T�Instance '%s' not found�>Plugin '%s' does not support hotplugging or dynamic instances.z-Instance '%s' trying to acquire devices '%s'.�8Moving devices '%s' from instance '%s' to instance '%s'.ztTarget instance '%s' is of type '%s', but devices '%s' are currently handled by instance '%s' which is of type '%s'.z2Ignoring devices not handled by any instance '%s'.�Tr])r$rhr �
_unit_manager�	instancesrar,�debugr\�
isinstance�pluginr�PluginrAZdevstr2devsr_�processed_devices�lenr-�_remove_devices_nocheck�_add_devices_nocheck)
r�devices�
instance_namerS�foundZinstance_target�retsZdevs�instance�devs_movingrrr�instance_acquire_deviceszsX



���


z#Controller.instance_acquire_devicesz	(bsa(ss))cs�|dkrddgfS|j���s(ddgfS�dkr\�|����vr\d�}t�|�d|gfStdd�|jjj	�}�dkr�t�fdd�|�}d	d
t
tdd�|��fS)aReturn a list of active instances of a plugin or all active instances

		Parameters:
		plugin_name -- name of the plugin or an empty string

		Return:
		bool -- True on success
		string -- error message or "OK"
		list of string pairs -- [(instance_name, plugin_name)]
		rOFrg�Invalid plugin_namezPlugin '%s' does not existcSs|jSr)Zactive�r�rrr�<lambda>��z*Controller.get_instances.<locals>.<lambda>cs|jj�kSr)r�rar��r�rrr��r�Tr]cSs|j|jjfSr)rar�r�rrrr��r�)r$rhr��keysr,r\�filterr r�r��list�map)rr�rSr�r�rr�r�
get_instances�s



zController.get_instancesz(bsas)cCsv|dkrddgfS|j�|�s(ddgfS|jjjD]&}|j|kr2ddtt|j��fSq2d|}t	�
|�d|gfS)z�Return a list of devices assigned to an instance

		Parameters:
		instance_name -- name of the instance

		Return:
		bool -- True on success
		string -- error message or "OK"
		list of strings -- device names
		rOFrgr�Tr]r�)r$rhr r�r�ra�sortedr�r�r,r\)rr�rSr�r�rrr�instance_get_devices�s



zController.instance_get_deviceszssa{ss}c
Cs:|dkrdS|j�|�sdS|j�|�s,dS|��D]&\}}|j�|�rT|j�|�s4dSq4dd�|jjjD�}||��vr�d|}t�|�d	|fS||}	t	|	t
j�s�d
|	j}t�|�d	|fS|�
dd�}
|�
d
d�}|�
dd�}|�
dd�}
t|�
d|jjj��}z4|	�|||
|||
|�}|	�|�|jjj�|�WnHt�y�}z.d|t|�f}t�|�d	|fWYd}~Sd}~00t�d||f�|	�|�|	�|�|jjjD]z}||k�s�|j|	k�s�|j|jk�r�q�|	�||j�}t|��r�t�dt|�|j|jf�|	�||�|	�||��q�dS)aDynamically create a plugin instance

		Parameters:
		plugin_name -- name of the plugin
		instance_name -- name of the new instance
		dict of string-string -- options for the new instance

		Return:
		bool -- True on success
		string -- error message or "OK"
		rOrf)Fr�r�)FzInvalid optionscSsi|]}|j|�qSr�ra)�.0r<rrr�
<dictcomp>�r�z.Controller.instance_create.<locals>.<dictcomp>zPlugin '%s' not foundFr�r�N�devices_udev_regex�
script_pre�script_post�priorityz Error creating instance '%s': %sz,Created dynamic instance '%s' of plugin '%s'r�r�) r$rhr�r r�r�r�r,r\r�rr�ra�pop�intZ_def_instance_priorityZcreate_instanceZinitialize_instancer��append�	Exceptionr_r-Zassign_free_devicesZinstance_apply_tuningr�r�Z_get_matching_devicesr�r�r�r�)rr�r��optionsrSr��valuer�r�r�r�r�r�r�r�r�r>Zother_instancer�rrr�instance_create�sd








�
�
�zController.instance_createc	
sH|dkrdS|j���sdSz �fdd�|jjjD�d}Wn,tyhd�}t�|�d|fYS0|j}t	|t
j�s�d	|j}t�|�d|fS|j
��}z4|�||�|jjj�|�|�|�|�|�WnHt�y}z.d
�t|�f}t�|�d|fWYd}~Sd}~00t�d��|D]}|�|��q2d
S)z�Destroy a dynamically created plugin instance

		Parameters:
		instance_name -- name of the new instance

		Return:
		bool -- True on success
		string -- error message or "OK"
		rOrfr�csg|]}|j�kr|�qSrr�)r��i�r�rr�
<listcomp>&r�z/Controller.instance_destroy.<locals>.<listcomp>rr�Fr�z Error deleting instance '%s': %sNzDeleted instance '%s'r�)r$rhr r�r��
IndexErrorr,r\r�r�rr�rar��copyr��removeZinstance_unapply_tuningZdestroy_instancer�r_r-Z_add_device)	rr�rSr�r�r�r�r>Zdevicerr�r�instance_destroys: 





zController.instance_destroy)N)N)N)F)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)+rrr�__doc__rr@rBrDr�signalrGrLZexportrQrKr6r[r;rCrerjrlrmrprqrrrVrvrwryrkr|r}r�r�r�r�r�r�r�r�r��
__classcell__rrr'rr(s�-


























+


?
)rIrZ
tuned.logsZtuned.exceptionsrrZtuned.constsr.Ztuned.utils.commandsrZ
tuned.pluginsrr/r2�__all__rJ�getr,�objectrZ
interfacesZExportableInterfacerrrrr�<module>s


Zerion Mini Shell 1.0