MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: machen (1008)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/extensionprocessutil.pyo
�
d�bc@s~ddlZddlZddlZddlmZmZmZddlmZdZ	d�Z
d�Zd�Zd�Z
dS(	i����N(tExtensionErrorCodestExtensionOperationErrortExtensionError(tustri�cCs�x9|dkr;|j�dkr;tjd�|d8}qWd}|dkrptjtj|j�tj	�ntjd�|j
�}|dk|fS(s�
    Utility function that waits for the process to complete within the given time frame. This function will terminate
    the process if when the given time frame elapses.
    :param process: Reference to a running process
    :param timeout: Number of seconds to wait for the process to complete before killing it
    :return: Two parameters: boolean for if the process timed out and the return code of the process (None if timed out)
    iiN(tpolltNonettimetsleeptostkillpgtgetpgidtpidtsignaltSIGKILLtwait(tprocessttimeouttreturn_code((sU/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/extensionprocessutil.pyt&wait_for_process_completion_or_timeouts!
"
c	Cs�t||�\}}t||�}|rQtdj|||�dtj��n|dkr�tdj|||�d|d|��n|S(s�
    Utility function that waits for process completion and retrieves its output (stdout and stderr) if it completed
    before the timeout period. Otherwise, the process will get killed and an ExtensionError will be raised.
    In case the return code is non-zero, ExtensionError will be raised.
    :param process: Reference to a running process
    :param command: The extension command to run
    :param timeout: Number of seconds to wait before killing the process
    :param stdout: Must be a file since we seek on it when parsing the subprocess output
    :param stderr: Must be a file since we seek on it when parsing the subprocess outputs
    :param error_code: The error code to set if we raise an ExtensionError
    :return:
    sTimeout({0}): {1}
{2}tcodeis Non-zero exit code: {0}, {1}
{2}t	exit_code(Rtread_outputRtformatRtPluginHandlerScriptTimedoutR(	RtcommandRtstdouttstderrt
error_codet	timed_outRtprocess_output((sU/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/extensionprocessutil.pythandle_process_completion6scCs�ym|jd�|jd�t|jt�dddd�}t|jt�dddd�}t||�SWn,tk
r�}tddjt|���SXdS(	s:
    Read the output of the process sent to stdout and stderr and trim them to the max appropriate length.
    :param stdout: File containing the stdout of the process
    :param stderr: File containing the stderr of the process
    :return: Returns the formatted concatenated stdout and stderr of the process
    itencodingsutf-8terrorstbackslashreplacetsCannot read stdout/stderr: {0}N(tseekRtreadtTELEMETRY_MESSAGE_MAX_LENtformat_stdout_stderrt	ExceptionR(RRte((sU/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/extensionprocessutil.pyRRs

		cs;d�t}t|t��dd�}|dkr:dS�fd�}t|�t|�|krx||d|d�St|�|kr�|t|�}t||t|��}||d|d|�St|�|kr|t|�}t||t|��}||d||d�S||d||d|�SdS(	s1
    Format stdout and stderr's output to make it suitable in telemetry.
    The goal is to maximize the amount of output given the constraints
    of telemetry.

    For example, if there is more stderr output than stdout output give
    more buffer space to stderr.

    :param str stdout: characters captured from stdout
    :param str stderr: characters captured from stderr
    :param int max_len: maximum length of the string to return

    :return: a string formatted with stdout and stderr that is less than
    or equal to max_len.
    :rtype: str
    s[stdout]
{0}

[stderr]
{1}iiiR"cs�j||||�}|S(N(R(tcaptured_stdoutt
stdout_offsettcaptured_stderrt
stderr_offsetts(ttemplate(sU/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/extensionprocessutil.pytto_s�si����N(R%tinttlentmin(RRtmax_lentmax_len_eachR/tbonust
stderr_lent
stdout_len((R.sU/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/extensionprocessutil.pyR&gs"(RRRt azurelinuxagent.common.exceptionRRRtazurelinuxagent.common.futureRR%RRRR&(((sU/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/extensionprocessutil.pyt<module>s