Redirect Output in the Middle of a Program??

Bob Toxen bob at cloud9.UUCP
Sat Apr 30 08:10:27 AEST 1988


In article <11257 at mimsy.UUCP>, chris at mimsy.UUCP (Chris Torek) writes:
> In article <62 at denali.UUCP> karish at 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?



More information about the Comp.unix.wizards mailing list