diff options
author | Yury Selivanov <yury@magic.io> | 2016-10-09 16:15:08 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2016-10-09 16:15:08 (GMT) |
commit | 908d55dd7e395779ed1eb5c96664aca6297fedaa (patch) | |
tree | 7a2d08224f9a43b97aa6f37ba5cc7ea728d5b127 /Lib/asyncio | |
parent | 0aa7887f431f65f1d320c467ad9065ac2697db20 (diff) | |
download | cpython-908d55dd7e395779ed1eb5c96664aca6297fedaa.zip cpython-908d55dd7e395779ed1eb5c96664aca6297fedaa.tar.gz cpython-908d55dd7e395779ed1eb5c96664aca6297fedaa.tar.bz2 |
Issue #28399: Remove UNIX socket from FS before binding.
Patch by Коренберг Марк.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/unix_events.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 42a8b85..65b61db 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -258,6 +258,17 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + # Check for abstract socket. `str` and `bytes` paths are supported. + if path[0] not in (0, '\x00'): + try: + if stat.S_ISSOCK(os.stat(path).st_mode): + os.remove(path) + except FileNotFoundError: + pass + except OSError as err: + # Directory may have permissions only to create socket. + logger.error('Unable to check or remove stale UNIX socket %r: %r', path, err) + try: sock.bind(path) except OSError as exc: |