⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.30
Server IP:
45.79.8.107
Server:
Linux localhost 5.15.0-140-generic #150-Ubuntu SMP Sat Apr 12 06:00:09 UTC 2025 x86_64
Server Software:
nginx/1.18.0
PHP Version:
8.1.2-1ubuntu2.21
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
lib
/
python3
/
dist-packages
/
uaclient
/
__pycache__
/
View File Name :
lock.cpython-310.pyc
o pf @ s d dl Z d dlZd dlZd dlmZ d dlmZmZmZ d dl m Z mZmZ d dl mZ d dlmZmZ d dlmZ d dlmZ e eeZG d d d e Zeeeddd ejZdeeef fddZdd Z G dd dZ!dS ) N)Tuple) exceptionssystemutil) DataObjectFieldStringDataValue)notices)DataObjectFileDataObjectFileFormat)UAFile)Noticec @ s2 e Zd ZedeedegZdedefddZdS )LockDatalock_pidlock_holderc C s || _ || _d S Nr r )selfr r r //usr/lib/python3/dist-packages/uaclient/lock.py__init__ s zLockData.__init__N)__name__ __module____qualname__r r fieldsstrr r r r r r s r lockF)privatereturnc C s zt } W n tjy tjt jdw d}| s|S | j}| j}zt d|g t ||fW S tjy\ t sKtd|| t ||f Y S td|| tt j | Y S w )a Return lock info if lock file is present the lock is active. If process claiming the lock is no longer present, remove the lock file and log a warning. :return: A tuple (pid, string describing lock holder) If no active lock, pid will be -1. )lock_file_path) psz.Found stale lock file previously held by %s:%sz1Removing stale lock file previously held by %s:%s)lock_data_filereadr InvalidFileFormatErrorInvalidLockFilepathr r r subpintProcessExecutionErrorr we_are_currently_rootLOGdebugwarningensure_file_absent) lock_data_objno_lockr r r r r check_lock_info" s: r2 c C s t d S r )r# deleter r r r clear_lock_file_if_presentL s r4 c @ sF e Zd ZdZddddededefdd Zd d Zdd Zdd Z dS ) RetryLockah Context manager for gaining exclusive access to the lock file. Create a lock file if absent. The lock file will contain a pid of the running process, and a customer-visible description of the lock holder. The RetryLock will try several times to acquire the lock before giving up. The number of times to try and how long to sleep in between tries is configurable. :param lock_holder: String with the service name or command which is holding the lock. This lock_holder string will be customer visible in status.json. :param sleep_time: Number of seconds to sleep before retrying if the lock is already held. :param max_retries: Maximum number of times to try to grab the lock before giving up and raising a LockHeldError. :raises: LockHeldError if lock is held after (sleep_time * max_retries) ) sleep_timemax_retriesr r8 r9 c G s || _ || _|| _d S r )r r8 r9 )r r r8 r9 _argsr r r r e s zRetryLock.__init__c C sV t \}}|dkrtj| j||dtttt | jd t jtj | jd d S )Nr )lock_requestr pidr ) operation)r2 r LockHeldErrorr r# writer r osgetpidr addr OPERATION_IN_PROGRESS)r r cur_lock_holderr r r grab_lockp s zRetryLock.grab_lockc C s t d| j d} z| W d S tjy? } z!t d|d |j |d7 }|| jkr/|t | j W Y d }~nd }~ww q )Nzspin lock starting for %sr Tz%RetryLock Attempt %d. %s. Spinning... )r, r- r rE r r> msgr9 timesleepr8 )r trieser r r __enter__ s" zRetryLock.__enter__c C s t ttj d S r )r# r3 r remover rC )r _exc_type _exc_value _tracebackr r r __exit__ s zRetryLock.__exit__N) r r r __doc__r r) r rE rL rQ r r r r r5 P s r5 )"loggingr@ rH typingr uaclientr r r uaclient.data_typesr r r uaclient.filesr uaclient.files.data_typesr r uaclient.files.filesr uaclient.files.noticesr getLoggerreplace_top_level_logger_namer r, r JSONr# r) r r2 r4 r5 r r r r
s( *