Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!usc!ucsd!nprdc!stanonik From: stanonik@nprdc.navy.mil (Ron Stanonik) Newsgroups: comp.unix.programmer Subject: Re: gets() during signal Message-ID: <11275@arctic.nprdc.navy.mil> Date: 11 Dec 90 17:05:46 GMT References: <25232@adm.brl.mil> Sender: news@nprdc.navy.mil Reply-To: stanonik@nprdc.navy.mil (Ron Stanonik) Organization: Navy Personnel R&D Center, San Diego Lines: 32 In article rang@cs.wisc.edu (Anton Rang) writes: >In article <25232@adm.brl.mil> stanonik@nprdc.navy.mil (Ron Stanonik) writes: >>I just ran into a problem while porting a program from 4.3bsd to >>sunos4.1. The problem is that gets() in signal handlers seems to >>reset stdio's write pointer, but not the read pointer. > > As far as I know, UNIX stdio packages are not re-entrant. Don't try >to use any of the input routines, in particular, inside a signal >handler. I'm not sure if the output routines are safe, but I wouldn't >count on them--I've seen implementations of printf() which used a >static buffer internally. Okay, I'm willing to believe there are routines that shouldn't be used in signal handlers, but asking the user for confirmation of exit during SIGINT seems reasonable, so the question is, how to ask? There's always read(0, buf, sizeof buf); ugh! I notice that 4.3bsd dump's SIGINT handler opens /dev/tty and fgets answers from there. Another solution comes to mind, fp = fdopen(fileno(stdin), "r"), then fgets using fp. Any other/preferred solutions? Thanks, Ron Stanonik stanonik@nprdc.navy.mil ucsd!nprdc!stanonik