Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site istbt.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!mcvax!ukc!qtlon!istbt!bco From: bco@istbt.UUCP (Brian Collins) Newsgroups: net.bugs.usg Subject: fcntl can cause grief to your parent process Message-ID: <8@istbt.UUCP> Date: Fri, 8-Feb-85 08:49:20 EST Article-I.D.: istbt.8 Posted: Fri Feb 8 08:49:20 1985 Date-Received: Tue, 26-Feb-85 06:23:03 EST Organization: Imperial Software Technology, London, England Lines: 26 The following little program when run from the shell (Sys V) causes you to be logged off! #include 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