/tmp gets filled up on ksh93 93u+ #1472
Description
On versions of Solaris 10/Solaris 11 that ship with ksh93, the following behavior is observed:
Version of ksh93 on system:
$ ksh --version
version sh (AT&T Research) 93u+ 2012-08-01
The issue:
ksh93 seems to fill up the /tmp filesystem under certain scenarios. when redirection/here-doc operators are involved.
Example:
ksh93 does not seem to handle here-doc correctly in scenario's such as one below: Here's an expected behavior.
$ cat << EOS
foo
EOS
foo
But if I think of canceling the here-document by doing Ctrl-C, it's process is not interrupted.
$ cat << EOS
^C^C^C^C^C^C^C^C
Now, the ksh93 cannot be killed with SIGINT although it can be killed with SIGSEGV, SIGBUS, etc. (and of course SIGKILL). And until it's killed, /tmp keeps growing !!!!
/tmp on Solaris being a memory based tempfs filesystem, the above starts to consume a lot of memory.
There have been other scenarios too where the above problem is hit - while migrating ksh88 script to ksh93.
Also, the call stack looks something like below every time we hit the issue:
libc.so.1`__write+0x8
ksh`_sfflsbuf+0x268
ksh`sfsync+0x42c
ksh`sh_subtmpfile+0x1f0
ksh`sh_exec+0x4f24
ksh`sh_exec+0x343c
ksh`sh_exec+0x1970
ksh`sh_exec+0x3404
ksh`sh_exec+0x3404
ksh`sh_subshell+0x898
ksh`comsubst+0x9e4
ksh`varsub+0x618
ksh`copyto+0xb30
ksh`sh_macexpand+0x290
ksh`sh_argbuild+0x254
ksh`sh_exec+0x350c
ksh`exfile+0xad8
ksh`sh_main+0xc44
ksh`main+0x3c
ksh`_start+0x108
And, process tree looks like below most times:
AT(live/11V)> proc tree 16522
704 /usr/lib/ssh/sshd
16508 /usr/lib/ssh/sshd -R
16512 /usr/lib/ssh/sshd -R
16513 -bash
16517 su -
16518 -bash
16522 ksh -o vi
16686 less /var/adm/messages.0
16690 ksh
OR
CAT(vmcore.14/11V)> proc tree 10198
1 /usr/sbin/init
10198 ksh
PS: I presume the above is seen with the latest version of ksh93 as well.