관리-도구
편집 파일: application.cpython-39.opt-1.pyc
a ����,�g�����������������������@���s����d�dl�mZmZmZmZmZmZmZ�d�dlm Z �d�dl Z�d�dlZ�ddlm Z �ddlmZ�d�dlZd�dlZd�dlZd�dlZd�dlZd�dlmZ�d�dlmZ�e�j���ZdgZG�d d��de�ZdS�) �����)�storage�units�monitors�plugins�profiles�exports�hardware)�TunedExceptionN����)� controller)�daemon)�GlobalConfig�Applicationc�������������������@���s����e�Zd�Zddd�Zdd��Zdd��Zdd ��Zd d��Zdd ��Zdd��Z e jfdd�Zdd��Z dd��Ze jfdd�Zedd���Zedd���Zdd��ZdS�)r���Nc�������������� ���C���s|��t��dtjjt���d�f���d�|�_d�|�_t � ��}t �|�}|d�u�rJt��n||�_ |�j �tj�rjt��d��n t��d��t���}|�j �dtj�}tj|d�}t���}t���} tj���} tj���|�_t�||||| | |�j |�j�}t|�j �tj tj!��}t"�#|||||�j �} t���}t�$��}t�%|�j �&tj'tj(��}t�)||||�j |�j�}t*�+| |||�j |��|�_,t-�.|�j,|�j �|�_/|��0���d�|�_1d�S�)NzTuneD: %s, kernel: %s����z8dynamic tuning is enabled (can be overridden in plugins)z#dynamic tuning is globally disabled�udev_buffer_size)Zbuffer_size)2�log�info�tuned�versionZTUNED_VERSION_STR�os�uname�_dbus_exporter�_unix_socket_exporterr���ZPickleProviderZFactoryr ����config�get_bool�constsZCFG_DYNAMIC_TUNINGr���Z RepositoryZget_sizeZCFG_DEF_UDEV_BUFFER_SIZEr���Z InventoryZ DeviceMatcherZDeviceMatcherUdevr����instancer���Z variablesZ Variables�int�getZCFG_DEFAULT_INSTANCE_PRIORITYZ!CFG_DEF_DEFAULT_INSTANCE_PRIORITYr���ZManagerZMergerZLocator�get_listZCFG_PROFILE_DIRSZCFG_DEF_PROFILE_DIRS�Loaderr���ZDaemon�_daemonr���Z Controller�_controller� _init_signals� _pid_file)�selfZprofile_namer���Zstorage_providerZstorage_factoryZmonitors_repositoryr���Zhardware_inventoryZdevice_matcherZdevice_matcher_udevZplugin_instance_factoryZplugins_repositoryZdef_instance_priorityZunit_managerZprofile_factoryZprofile_mergerZprofile_locatorZprofile_loader��r&����</usr/lib/python3.9/site-packages/tuned/daemon/application.py�__init__���s@���� ��zApplication.__init__c��������������������s������fdd�}t����|��d�S�)Nc��������������������s����|�kr�����d�S��Nr&���)Z_signal_numberZ_frame��handler� signal_numberr&���r'����handler_wrapper@���s����z3Application._handle_signal.<locals>.handler_wrapper)�signal)r%���r,���r+���r-���r&���r*���r'����_handle_signal?���s����zApplication._handle_signalc�����������������C���s:���|���tj|�jj��|���tj|�jj��|���tj|�jj��d�S�r)���)r/���r.����SIGHUPr"���Zsighup�SIGINTZ terminate�SIGTERM�r%���r&���r&���r'���r#���E���s����zApplication._init_signalsc�����������������C���s6���|�j�d�urtd��tj�||||�|�_�t�|�j���d�S�)Nz&DBus interface is already initialized.)r���r ���r���ZdbusZDBusExporter�register_exporter)r%���Zbus_nameZobject_nameZinterface_name� namespacer&���r&���r'����attach_to_dbusJ���s���� zApplication.attach_to_dbusc�������������� ���C���sj���|�j�d�urtd��tj�|�j�tj�|�j� tj �|�j�tj�|�j�tj �|�j�tj��|�_�t�|�j���d�S�)Nz-Unix socket interface is already initialized.)r���r ���r���Zunix_socketZUnixSocketExporterr���r���r���ZCFG_UNIX_SOCKET_PATHr���ZCFG_UNIX_SOCKET_SIGNAL_PATHSZCFG_UNIX_SOCKET_OWNERSHIPZget_intZCFG_UNIX_SOCKET_PERMISIONSZ#CFG_UNIX_SOCKET_CONNECTIONS_BACKLOGr4���r3���r&���r&���r'����attach_to_unix_socketQ���s���� �z!Application.attach_to_unix_socketc�����������������C���s���t��|�j��d�S�r)���)r���Zregister_objectr"���r3���r&���r&���r'����register_controller\���s����zApplication.register_controllerc�����������������C���s����t��|��t�|gg�g�tj�\}}}t|�dkrBt��|��td��t��|d�}t��|��t|�dkrltd��zt� d|�d�}W�n�tj y����td��Y�n0�|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.����r���z: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�selectr���ZDAEMONIZE_PARENT_TIMEOUT�lenr ����read�struct�unpack�error)r%����parent_in_fd�child_out_fdZ read_readyZdropZresponse�valr&���r&���r'����_daemonize_parent_���s���� zApplication._daemonize_parentc�������������� ���C���s����||�_�|�����z�tj�|�j��}tj�|�s4t�|��t�t�|�j�tj tj B�tjB�d�d��"}|�dt� �����W�d�����n1�s�0����Y��W�n@�ttfy��}�z$t�d|�j�t|�f���W�Y�d�}~n d�}~0�0�d�S�)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�frA���r&���r&���r'����write_pid_filex���s���� (4zApplication.write_pid_filec�������������� ���C���s`���t�j�|�j�r\zt��|�j��W�n<�tyZ�}�z$t�d|�jt|�f���W�Y�d�}~n d�}~0�0�d�S�)Nz&cannot remove existing PID file %s, %s) r���rH���rJ���r$����unlinkrS���r����warningrV���)r%���rA���r&���r&���r'���rG�������s ����zApplication._delete_pid_filec�������������� ���C���s,��t��|��t��d��t�����t��d��zt����}|dkrBt�d��W�n`�ty��}�zHt � dt|����t� dd�}t��||��t��|��td��W�Y�d}~n d}~0�0�tdd �}t��|���tj�����t��|���tj�����t��|���tj�����|��|��t �d ��t� dd�}t��||��t��|��dS�)zy Finishes daemonizing process, writes a PID file and signalizes to the parent that the initialization is complete. �/r���z"cannot daemonize, fork() error: %sr:���Fz'Cannot daemonize, second fork() failed.Nz /dev/nullzw+zsuccessfully daemonizedT)r���r;����chdir�setsid�umask�fork�sys�exitrS���r���rU���rV���r?����packrQ���r ���rM����dup2�fileno�stdin�stdout�stderrrY����debug)r%���rW���rB���rC����pidrA���rD����fdr&���r&���r'����_daemonize_child����s.���� zApplication._daemonize_childc�������������� ���C���s����t����}zt����}W�nH�ty\�}�z0t��|d���t��|d���td��W�Y�d}~n d}~0�0�z4|dkr~|�j|���t�d��n|�j |g|�R����W�n"���|dkr���n t�d��Y�n0�dS�)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. r���r ���z Cannot daemonize, fork() failed.N) r����piper`���rS���r;���r ���rE���ra���rb���rl���)r%���rW���Zparent_child_fdsZ child_pidrA���r&���r&���r'���� daemonize����s ���� zApplication.daemonizec�����������������C���s���|�j�S�r)���)r!���r3���r&���r&���r'���r�������s����zApplication.daemonc�����������������C���s���|�j�S�r)���)r"���r3���r&���r&���r'���r�������s����zApplication.controllerc�����������������C���sj���|r|�j��tjd��|�j��tjtj�s0t�d��|�j� ��}|�j��tjtj�rTt ����|�jd�urf|�� ���|S�)NTzrUsing one shot no daemon mode, most of the functionality will be not available, it can be changed in global config)r����setr���Z CFG_DAEMONr���ZCFG_DEF_DAEMONr���r[���r"����runr����stopr$���rG���)r%���r����resultr&���r&���r'���rp�������s���� zApplication.run)NN)�__name__� __module__�__qualname__r(���r/���r#���r6���r7���r8���rE���r���ZPID_FILErY���rG���rl���rn����propertyr���r���rp���r&���r&���r&���r'���r������s ��� + " )r���r���r���r���r���r���r���r���Ztuned.exceptionsr ���Z tuned.logsZ tuned.version��r���r���r.���r���ra���r<���r?���Ztuned.constsr���Ztuned.utils.global_configr ���Zlogsr���r����__all__�objectr���r&���r&���r&���r'����<module>���s���$