vim uses ./$TMPDIR (literally, not expanded) as temporary directory
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
vim (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned | ||
Bug Description
Binary package hint: vim
If the TMPDIR environment variable is *not* set, vim will attempt to create temporary files in ./$TMPDIR (a literal directory name containing a dollar sign, not an environment variable expansion). It should instead try /tmp if TMPDIR is not set.
Implications:
1. If ./$TMPDIR exists, vim may issue an error message on startup (see below);
2. If vim is started in a directory such as an autofs mountpoint in which any requested directory will exist, vim hangs forever trying to create temporary directories waiting until it finds one that does not exist.
This latter case, although quite rare, is the one which alerted me to the problem; I observed the following strace excerpt:
stat64("$TMPDIR", {st_mode=
getpid() = 15010
time(NULL) = 1200881832
umask(077) = 02
mkdir("
umask(02) = 077
umask(077) = 02
mkdir("
umask(02) = 077
umask(077) = 02
mkdir("
umask(02) = 077
umask(077) = 02
mkdir("
...and so on, indefinitely.
I have reproduced the problem in a more conventional directory:
mas90@callisto:~$ mkdir \$TMPDIR
mas90@callisto:~$ vim
Error detected while processing /usr/share/
line 58:
E484: Cannot open file /home/mas90/
Press ENTER or type command to continue
From a brief look through the source, I believe that this is due to a fault in the expand_env_esc function in src/misc1.c: as far as I can tell, when expanding a string containing "$FOO" when environment variable FOO is unset or empty, "$FOO" will remain in the string. (The call to vim_getenv on line 3609 will return NULL if the variable requested is unset/empty, and NULL in *var will cause the conditional starting on line 3739 to fail and hence $FOO will not be replaced in the string.)
expand_env_esc is called via expand_env from src/fileio.c:6762, which iterates through the tempdirs array until it finds one which exists; tempdirs is initialised from the macro TEMPDIRNAMES, which is defined (on UNIX) to be "$TMPDIR", "/tmp", ".", "$HOME".
I'm running vim 1:7.1-056+2ubuntu2 from gutsy.
Changed in vim: | |
status: | New → Confirmed |
Your second point, about Vim hanging trying to create temporary directories, is fixed as of patch 7.2.294 and will be available once 2:7.2.330-1 is synced from Debian.