Bugzilla – Bug 1174408
zsh should honour $TMPDIR or XDG_RUNTIME_DIR by default
Last modified: 2020-07-23 13:41:42 UTC
By default /tmp is going to live on tmpfs but it might not be volatile by users 's choice. zsh creates temporary/runtime files according to DEFAULT_TMPPREFIX build time constant, that can be overriden at runtime setting the TMPPREFIX variable. In my opinion: a) at the bare minimum if only minimal changes respect to upstream are desired: DEFAULT_TMPPREFIX build time definition that is set to hardcoded string "/tmp/zsh" should instead try to use standard-defined TMPDIR envirnoment variable so for example pam modules or other parts of the OS can override at will. Unfortunately this does not solve the problem of temporary files on abnormal program termination, so I believe you should go one step forward and TMPPREFIX be set to: first and foremost to $XDG_RUNTIME_DIR/zsh if $XDG_RUNTIME_DIR is set. if that is not the case, to a tmpfs-backed directory /run/zsh (mode 1777) created by tmpfiles.d snippet. since this is a shell and must work in all cases if the above fails fallback to $TMPDIR/zsh Im happy if you do this on the global zsh configuration, but it must apply to every shell invocation, interactive or non-interactive alike.
I also have some patches that make zsh use O_TMPFILE on most cases, like =(echo "foo") but Im not sure at all if that will break some assumptions or special case. Needs test. Using O_TMPFILE is the only really safe way, since the fd is closed in all kinds of program termination and the "file" is not visible to anyone other than the calling process.