Revision debed9ae lib/utils.py
b/lib/utils.py | ||
---|---|---|
840 | 840 |
return pid |
841 | 841 |
|
842 | 842 |
|
843 |
def ReadLockedPidFile(path): |
|
844 |
"""Reads a locked PID file. |
|
845 |
|
|
846 |
This can be used together with L{StartDaemon}. |
|
847 |
|
|
848 |
@type path: string |
|
849 |
@param path: Path to PID file |
|
850 |
@return: PID as integer or, if file was unlocked or couldn't be opened, None |
|
851 |
|
|
852 |
""" |
|
853 |
try: |
|
854 |
fd = os.open(path, os.O_RDONLY) |
|
855 |
except EnvironmentError, err: |
|
856 |
if err.errno == errno.ENOENT: |
|
857 |
# PID file doesn't exist |
|
858 |
return None |
|
859 |
raise |
|
860 |
|
|
861 |
try: |
|
862 |
try: |
|
863 |
# Try to acquire lock |
|
864 |
LockFile(fd) |
|
865 |
except errors.LockError: |
|
866 |
# Couldn't lock, daemon is running |
|
867 |
return int(os.read(fd, 100)) |
|
868 |
finally: |
|
869 |
os.close(fd) |
|
870 |
|
|
871 |
return None |
|
872 |
|
|
873 |
|
|
843 | 874 |
def MatchNameComponent(key, name_list, case_sensitive=True): |
844 | 875 |
"""Try to match a name against a list. |
845 | 876 |
|
Also available in: Unified diff