ok

Mini Shell

Direktori : /lib/python3.6/site-packages/tuned/daemon/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/tuned/daemon/__pycache__/application.cpython-36.pyc

3

�<�e��@s�ddlmZmZmZmZmZmZmZddlm	Z	ddl
ZddlZddlm
Z
ddlmZddlZddlZddlZddlZddlZddljZddlmZejj�ZdgZGd	d�de�ZdS)
�)�storage�units�monitors�plugins�profiles�exports�hardware)�TunedExceptionN�)�
controller)�daemon)�GlobalConfig�Applicationc@s�eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	e
jfdd�Zdd�Z
dd�Ze
jfdd�Zedd��Zedd��Zdd�ZdS)rNc	Csptjdtjjtj�df�d|_d|_t	j
�}t	j|�}|dkrJt�n||_
|j
jtj�rjtjd�n
tjd�tj�}|j
jdtj�}tj|d�}tj�}tj�}	tjj�}
tjj�|_tj|||||	|
|j
|j�}t|j
jtj tj!��}t"j#|||||j
�}
tj�}tj$�}tj%tj&�}tj'||||j
|j�}t(j)|
|||j
|�|_*t+j,|j*|j
�|_-|j.�d|_/dS)NzTuneD: %s, kernel: %s�z8dynamic tuning is enabled (can be overridden in plugins)z#dynamic tuning is globally disabled�udev_buffer_size)�buffer_size)0�log�info�tuned�versionZTUNED_VERSION_STR�os�uname�_dbus_exporter�_unix_socket_exporterrZPickleProviderZFactoryr
�config�get_bool�constsZCFG_DYNAMIC_TUNINGrZ
RepositoryZget_sizeZCFG_DEF_UDEV_BUFFER_SIZErZ	InventoryZ
DeviceMatcherZDeviceMatcherUdevr�instancer�	variables�	Variables�int�getZCFG_DEFAULT_INSTANCE_PRIORITYZ!CFG_DEF_DEFAULT_INSTANCE_PRIORITYrZManagerZMergerZLocatorZLOAD_DIRECTORIES�LoaderrZDaemon�_daemonrZ
Controller�_controller�
_init_signals�	_pid_file)�selfZprofile_namerZstorage_providerZstorage_factoryZmonitors_repositoryrZhardware_inventoryZdevice_matcherZdevice_matcher_udevZplugin_instance_factoryZplugins_repositoryZdef_instance_priorityZunit_managerZprofile_factoryZprofile_mergerZprofile_locatorZprofile_loader�r(�!/usr/lib/python3.6/application.py�__init__s<



zApplication.__init__cs��fdd�}tj�|�dS)Ncs�|kr��dS)Nr()Z_signal_numberZ_frame)�handler�
signal_numberr(r)�handler_wrapper@sz3Application._handle_signal.<locals>.handler_wrapper)�signal)r'r,r+r-r()r+r,r)�_handle_signal?szApplication._handle_signalcCs:|jtj|jj�|jtj|jj�|jtj|jj�dS)N)r/r.�SIGHUPr$Zsighup�SIGINTZ	terminate�SIGTERM)r'r(r(r)r%EszApplication._init_signalscCs6|jdk	rtd��tjj||||�|_tj|j�dS)Nz&DBus interface is already initialized.)rr	rZdbusZDBusExporter�register_exporter)r'Zbus_nameZobject_nameZinterface_name�	namespacer(r(r)�attach_to_dbusJs
zApplication.attach_to_dbuscCsj|jdk	rtd��tjj|jjtj�|jjtj	�|jjtj
�|jjtj�|jjtj
��|_tj|j�dS)Nz-Unix socket interface is already initialized.)rr	rZunix_socketZUnixSocketExporterrr!rZCFG_UNIX_SOCKET_PATHZCFG_UNIX_SOCKET_SIGNAL_PATHSZCFG_UNIX_SOCKET_OWNERSHIPZget_intZCFG_UNIX_SOCKET_PERMISIONSZ#CFG_UNIX_SOCKET_CONNECTIONS_BACKLOGr3)r'r(r(r)�attach_to_unix_socketQs
z!Application.attach_to_unix_socketcCstj|j�dS)N)rZregister_objectr$)r'r(r(r)�register_controller\szApplication.register_controllercCs�tj|�tj|gggtj�\}}}t|�dkrBtj|�td��tj|d�}tj|�t|�dkrltd��ytj	d|�d}Wntj
k
r�td��YnX|dkr�td	��d
S)z|
		Wait till the child signalizes that the initialization is complete by writing
		some uninteresting data into the pipe.
		r
z=Cannot daemonize, timeout when waiting for the child process.�rz:Cannot daemonize, no response from child process received.�?z?Cannot daemonize, invalid response from child process received.Tz0Cannot daemonize, child process reports failure.N)r�close�selectrZDAEMONIZE_PARENT_TIMEOUT�lenr	�read�struct�unpack�error)r'�parent_in_fd�child_out_fdZ
read_readyZdropZresponse�valr(r(r)�_daemonize_parent_s


zApplication._daemonize_parentcCs�||_|j�yltjj|j�}tjj|�s4tj|�tjtj|jtj	tj
BtjBd�d��}|jdtj
��WdQRXWn>ttfk
r�}ztjd|jt|�f�WYdd}~XnXdS)Ni��wz%dzcannot write the PID to %s: %s)r&�_delete_pid_filer�path�dirname�exists�makedirs�fdopen�open�O_CREAT�O_TRUNC�O_WRONLY�write�getpid�OSError�IOErrorr�critical�str)r'�pid_fileZdir_name�fr@r(r(r)�write_pid_filexs
( zApplication.write_pid_filecCs^tjj|j�rZytj|j�Wn:tk
rX}ztjd|jt|�f�WYdd}~XnXdS)Nz&cannot remove existing PID file %s, %s)	rrGrIr&�unlinkrRrZwarningrU)r'r@r(r(r)rF�s
zApplication._delete_pid_filecCs*tj|�tjd�tj�tjd�ytj�}|dkrBtjd�Wn^tk
r�}zBt	j
dt|��tj
dd�}tj||�tj|�td��WYdd}~XnXtdd	�}tj|j�tjj��tj|j�tjj��tj|j�tjj��|j|�t	jd
�tj
dd�}tj||�tj|�dS)zy
		Finishes daemonizing process, writes a PID file and signalizes to the parent
		that the initialization is complete.
		�/rz"cannot daemonize, fork() error: %sr9Fz'Cannot daemonize, second fork() failed.Nz	/dev/nullzw+zsuccessfully daemonizedT)rr:�chdir�setsid�umask�fork�sys�exitrRrrTrUr>�packrPr	rL�dup2�fileno�stdin�stdout�stderrrX�debug)r'rVrArB�pidr@rC�fdr(r(r)�_daemonize_child�s.






zApplication._daemonize_childcCs�tj�}ytj�}WnFtk
rZ}z*tj|d�tj|d�td��WYdd}~XnXy2|dkr||j|�tjd�n|j	|f|��Wn"|dkr��n
tjd�YnXdS)z�
		Daemonizes the application. In case of failure, TunedException is raised
		in the parent process. If the operation is successfull, the main process
		is terminated and only child process returns from this method.
		rr
z Cannot daemonize, fork() failed.N)
r�piper^rRr:r	rDr_r`rj)r'rVZparent_child_fdsZ	child_pidr@r(r(r)�	daemonize�s 
zApplication.daemonizecCs|jS)N)r#)r'r(r(r)r�szApplication.daemoncCs|jS)N)r$)r'r(r(r)r�szApplication.controllercCsj|r|jjtjd�|jjtjtj�s0tjd�|jj	�}|jjtjtj�rTt
j�|jdk	rf|j
�|S)NTzrUsing one shot no daemon mode, most of the functionality will be not available, it can be changed in global config)r�setrZ
CFG_DAEMONrZCFG_DEF_DAEMONr�warnr$�runr�stopr&rF)r'r�resultr(r(r)ro�s


zApplication.run)NN)�__name__�
__module__�__qualname__r*r/r%r5r6r7rDrZPID_FILErXrFrjrl�propertyrrror(r(r(r)rs
+
")rrrrrrrrZtuned.exceptionsr	Z
tuned.logsZ
tuned.version�rrr.rr_r;r>Ztuned.constsrZtuned.utils.global_configr
Zlogsr!r�__all__�objectrr(r(r(r)�<module>s$



Zerion Mini Shell 1.0