gets() during signal

Ron Stanonik stanonik at nprdc.navy.mil
Wed Dec 12 04:05:46 AEST 1990


In article <RANG.90Dec10164915 at nexus.cs.wisc.edu> rang at cs.wisc.edu (Anton Rang) writes:
>In article <25232 at adm.brl.mil> stanonik at 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 at nprdc.navy.mil
ucsd!nprdc!stanonik



More information about the Comp.unix.programmer mailing list