From 2207bea6ebaf554a4efe76659bf2bb795883151d Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 2 Feb 2021 12:57:16 +0000 Subject: [PATCH] issue #754: support MITOGEN_UNIX_DIR environment variable --- ansible_mitogen/process.py | 5 ++++- docs/ansible_detailed.rst | 12 ++++++++++++ mitogen/unix.py | 8 ++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ansible_mitogen/process.py b/ansible_mitogen/process.py index 1fc7bf80..2d1a6358 100644 --- a/ansible_mitogen/process.py +++ b/ansible_mitogen/process.py @@ -627,7 +627,10 @@ class MuxProcess(object): #: MuxProcess CPU index. self.index = index #: Individual path of this process. - self.path = mitogen.unix.make_socket_path() + self.path = mitogen.unix.make_socket_path( + # issue #754: overlong temp paths may easily overflow sockaddr_un + dir=os.environ.get('MITOGEN_UNIX_DIR'), + ) def start(self): self.pid = os.fork() diff --git a/docs/ansible_detailed.rst b/docs/ansible_detailed.rst index c9bbcf51..1dc1093d 100644 --- a/docs/ansible_detailed.rst +++ b/docs/ansible_detailed.rst @@ -515,6 +515,18 @@ In summary, for each task Ansible may create one or more of: * ``$TMPDIR/ansible__payload_.../`` owned by the become user, * ``$TMPDIR/ansible-module-tmp-.../`` owned by the become user. +Temporary Files (Controller) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To create UNIX sockets used for inter-process communication on the Ansible +controller host, Mitogen normally uses a temporary directory selected +by the :mod:`tempfile` module, however is possible the selected directory +cannot be used as its name its path exceeds the system-defined 108 byte limit +on UNIX socket paths. + +In this case, the ``MITOGEN_UNIX_DIR`` environment variable may be used to +define an alternative directory. + Mitogen for Ansible ^^^^^^^^^^^^^^^^^^^ diff --git a/mitogen/unix.py b/mitogen/unix.py index 1af1c0ec..a0c07ad4 100644 --- a/mitogen/unix.py +++ b/mitogen/unix.py @@ -79,8 +79,12 @@ def is_path_dead(path): return False -def make_socket_path(): - return tempfile.mktemp(prefix='mitogen_unix_', suffix='.sock') +def make_socket_path(dir=None): + return tempfile.mktemp( + prefix='mitogen_unix_', + suffix='.sock', + dir=dir, + ) class ListenerStream(mitogen.core.Stream):