Path: utzoo!mnetor!uunet!husc6!m2c!jjmhome!cloud9!bob From: bob@cloud9.UUCP (Bob Toxen) Newsgroups: comp.unix.wizards Subject: Re: Redirect Output in the Middle of a Program?? Message-ID: <342@cloud9.UUCP> Date: 29 Apr 88 22:10:27 GMT References: <13085@brl-adm.ARPA> <3571@gryphon.CTS.COM> <2841@cvl.umd.edu> <11257@mimsy.UUCP> Organization: Stratus Computer, Inc., Marlboro, MA Lines: 18 Summary: Use close/open for the shell game In article <11257@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > In article <62@denali.UUCP> karish@denali.UUCP writes: > >... The user's program can catch the SIGHUP. This handler can use > >fopen() to open outfiles, and freopen() to reassign the output streams. > This is quite dangerous. > In-Real-Life: Chris Torek uunet!mimsy!chris (Edited to satisfy inews.) The safe way is to do a close and then an open on the desired file descriptors. This will work even while executing stdio code. System calls are internally consistent (except in some non-native UNIXes). If you want to be ultra-safe, have your interrupt ignore signals before doing this and then restore them afterwards. -- Bob Toxen {ucbvax!ihnp4,harvard,cloud9!es}!anvil!cavu!bob Stratus Computer, Marlboro, MA Pilot to Copilot: What's a mountain goat doing way up here in a cloud bank?