HEX
Server: LiteSpeed
System: Linux us-phx-web629.main-hosting.eu 5.14.0-503.23.2.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Feb 12 05:52:18 EST 2025 x86_64
User: u756937133 (756937133)
PHP: 8.2.30
Disabled: passthru,chgrp
Upload Files
File: //lib/python3.9/site-packages/tuned/plugins/__pycache__/plugin_systemd.cpython-39.pyc
a

�Գf4�@spddlmZddlTddlZddlmZddlmZddlm	Z	ddl
Z
ddlZej�
�ZGdd�dej�ZdS)	�)�base)�*�N)�
exceptions)�commandscs�eZdZdZ�fdd�Zdd�Zdd�Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zejfdd�Zdd�Zeddd�dd ��Z�ZS)!�
SystemdPlugina<
	`systemd`::
	
	Plug-in for tuning systemd options.
	+
	The [option]`cpu_affinity` option allows setting CPUAffinity in
	`/etc/systemd/system.conf`. This configures the CPU affinity for the
	service manager as well as the default CPU affinity for all forked
	off processes. The option takes a comma-separated list of CPUs with
	optional CPU ranges specified by the minus sign (`-`).
	+
	.Set the CPUAffinity for `systemd` to `0 1 2 3`
	====
	----
	[systemd]
	cpu_affinity=0-3
	----
	====
	+
	NOTE: These tunings are unloaded only on profile change followed by a reboot.
	cs@tj�tj�st�dtj��tt|�j	|i|��t
�|_dS)NzERequired systemd '%s' configuration file not found, disabling plugin.)�os�path�isfile�consts�SYSTEMD_SYSTEM_CONF_FILErZNotSupportedPluginException�superr�__init__r�_cmd)�self�args�kwargs��	__class__��@/usr/lib/python3.9/site-packages/tuned/plugins/plugin_systemd.pyr$szSystemdPlugin.__init__cCsd|_d|_dS)NFT)Z_has_dynamic_tuningZ_has_static_tuning�r�instancerrr�_instance_init*szSystemdPlugin._instance_initcCsdS�Nrrrrr�_instance_cleanup.szSystemdPlugin._instance_cleanupcCsddiS)N�cpu_affinityr)�clsrrr�_get_config_options1s�z!SystemdPlugin._get_config_optionscCsB|dur>tjd|d|tjd�}|dur>|jdkr>|�d�SdS)N�^\s*z\s*=\s*(.*)$��flagsr)�re�search�	MULTILINE�	lastindex�group)r�conf�key�morrr�_get_keyval7s

zSystemdPlugin._get_keyvalcCs|tjd|ddt|�|tjd�\}}|dkrxz|ddkrF|d7}WntyZYn0||dt|�d7}|S|S)	Nz^(\s*z\s*=).*$z\g<1>r r����
�=)r"�subn�strr$�
IndexError)rr'r(�valZconf_newZnsubsrrr�_add_keyval?s(zSystemdPlugin._add_keyvalcCstjd|dd|tjd�S)Nrz\s*=.*\n�r )r"�subr$)rr'r(rrr�_del_keyKszSystemdPlugin._del_keycCs,|jjtjdd�}|dur(t�d�dS|S)N)�err_retz(error reading systemd configuration file)r�	read_filerr�log�error)rZsystemd_system_confrrr�_read_systemd_system_confNs

z'SystemdPlugin._read_systemd_system_confcCsptjtj}|j�||�s8t�d�|jj|dd�dS|j�|tj�slt�dtj�|jj|dd�dSdS)Nz(error writing systemd configuration fileT)�no_errorFz/error replacing systemd configuration file '%s')	rrZTMP_FILE_SUFFIXr�
write_to_filer8r9�unlink�rename)rr'Ztmpfilerrr�_write_systemd_system_confUs
z(SystemdPlugin._write_systemd_system_confcCstj�tj|j�Sr)rr	�joinrZPERSISTENT_STORAGE_DIR�name)rrrr�_get_storage_filenamecsz#SystemdPlugin._get_storage_filenamecCsl|��}|durh|��}|jj|ddd�}|j�|�|durN|�|tj�}n|�|tj|�}|�	|�dS)NT�r6r;)
r:rBrr7r=r5r�SYSTEMD_CPUAFFINITY_VARr2r?)rr'�fname�cpu_affinity_savedrrr�_remove_systemd_tuningfsz$SystemdPlugin._remove_systemd_tuningcCs0|tjkr,t�dtj�|��t�d�dS)Nz6removing '%s' systemd tuning previously added by TuneDz[you may need to manualy run 'dracut -f' to update the systemd configuration in initrd image)rZ
ROLLBACK_FULLr8�inforDrGZconsole)rrZrollbackrrr�_instance_unapply_staticrs
z&SystemdPlugin._instance_unapply_staticcCs<|durdSd�dd�|j�t�ddt�dd|���D��S)Nr3� css|]}t|�VqdSr�r/��.0�vrrr�	<genexpr>|�z8SystemdPlugin._cpulist_convert_unpack.<locals>.<genexpr>z\s+�,z,\s+)r@r�cpulist_unpackr"r4)rZcpulistrrr�_cpulist_convert_unpackysz%SystemdPlugin._cpulist_convert_unpackrF)Z
per_devicecCs�d}d}|j�|j�|j�|���}d�dd�|j�|�D��}|��}	|	durh|�|	t	j
�}|�|�}|r||�d|||�S|r�|�
�}
|jj|
ddd�}|dur�|dur�||kr�|jj|
|dd�t�dt	j
|t	jf�|�|�|	t	j
|��dS)	NrJcss|]}t|�VqdSrrKrLrrrrO�rPz)SystemdPlugin._cmdline.<locals>.<genexpr>rTrC)Zmakedirz setting '%s' to '%s' in the '%s')rZunescapeZ
_variables�expand�unquoter@rRr:r*rrDrSZ
_verify_valuerBr7r<r8rHrr?r2)rZenabling�valueZverifyZignore_missingZ
conf_affinityZconf_affinity_unpackedrNZ
v_unpackedr'rErFrrr�_cmdline~s"
zSystemdPlugin._cmdline)�__name__�
__module__�__qualname__�__doc__rrr�classmethodrr*r2r5r:r?rBrGrZ
ROLLBACK_SOFTrIrSZcommand_customrW�
__classcell__rrrrr
s"

r)r3rZ
decoratorsZ
tuned.logsZtunedrZtuned.utils.commandsrZtuned.constsrrr"Zlogs�getr8ZPluginrrrrr�<module>s