[net.bugs.usg] fcntl can cause grief to your parent process

bco@istbt.UUCP (Brian Collins) (02/08/85)

The following little program when run from the shell (Sys V)
causes you to be logged off!

	#include <fcntl.h>
	main ()
	{
		int flag = fcntl( 0, F_GETFL);
		fcntl( 0, F_SETFL, flag | O_NDELAY);
		exit(0);
	}

The reason is that that setting the O_NDELAY flag affects all
processes using the open file, including (in that case) your
login shell.  When the program exits, the flag remains,
causing sh to see EOF (0 characters from a non-blocking read)
& logging you off.

There is no easy fix without adding to kernel tables.

It is easily avoided by ensuring that the flag is always reset
before a program exits/crashes.  It is importtant to take care
when repeatedly changing the flag for typeahead detection as I
was!
-- 
Brian Collins		...{mcvax,qtlon,ist,root44}!ist!bco
Imperial Software Technology, London