ruff: Fix S108 Probable insecure usage of temporary file.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2023-01-06 00:09:53 -08:00
committed by Tim Abbott
parent d05f672132
commit 7e3a681f80
6 changed files with 16 additions and 11 deletions

View File

@@ -85,7 +85,8 @@ def tracemalloc_listen() -> None:
listener_pid = os.getpid()
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
path = f"/tmp/tracemalloc.{os.getpid()}"
os.makedirs(settings.TRACEMALLOC_DUMP_DIR, exist_ok=True)
path = os.path.join(settings.TRACEMALLOC_DUMP_DIR, f"tracemalloc.{os.getpid()}")
sock.bind(path)
thread = threading.Thread(target=lambda: tracemalloc_listen_sock(sock), daemon=True)
thread.start()
@@ -96,7 +97,7 @@ def maybe_tracemalloc_listen() -> None:
"""If tracemalloc tracing enabled, listen for requests to dump a snapshot.
To trigger once this is listening:
echo | socat -u stdin unix-sendto:/tmp/tracemalloc.$pid
echo | socat -u stdin unix-sendto:/var/log/zulip/tracemalloc/tracemalloc.$pid
To enable in the Zulip web server: edit /etc/zulip/uwsgi.ini ,
and add e.g. ` PYTHONTRACEMALLOC=5` to the `env=` line.