TLDR: In Solaris, if O_NDELAY is set on stdin by a child process, bash exits. Why?
The following code causes interactive bash (v4.3.33) or tcsh (6.19.00) shells to exit after the process finishes running:
#include <fcntl.h>
int main() {
fcntl( 0, F_SETFL, O_NDELAY );
//int x = fcntl( 0, F_GETFL );
//fcntl( 0, F_SETFL, ~(x ^ (~O_NDELAY)) );
return 0;
}
The versions of ksh, csh and zsh we have aren't affected by this problem.
To investigate I ran bash & csh under truss (similar to strace on Linux) like this:
$ truss -eaf -o bash.txt -u'*' -{v,r,w}all bash --noprofile --norc
$ truss -eaf -o csh.txt -u'*' -{v,r,w}all csh -f
After csh finishes running the process it does the following:
fcntl( 0, F_GETFL ) = FWRITE|FNDELAY
fcntl( 0, F_SETFL, FWRITE) = 0
... which gave me an idea. I changed the program to the commented out code above so it would toggle the state of O_NDELAY. If I run it twice in a row bash doesn't exit.