rang@cs.wisc.edu (Anton Rang) (12/11/90)
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. I've moved followups to comp.unix.programmer, which is probably where this really belongs... (?) Anton +---------------------------+------------------+-------------+ | Anton Rang (grad student) | rang@cs.wisc.edu | UW--Madison | +---------------------------+------------------+-------------+
stanonik@nprdc.navy.mil (Ron Stanonik) (12/12/90)
In article <RANG.90Dec10164915@nexus.cs.wisc.edu> 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
boutell@freezer.it.udel.edu (Tom Boutell) (12/12/90)
Your last two proposed solutions, both of which involve creating an independent stream writing to stdout/ reading from stdin, are actually reasonably intuitive. I would recommend using them since they incorporate the concept of not stepping on the toes of the main program. -- THE TECHNOLOGY HOUSE: An idea whose time has come! My girlfriend is a pseudo- aardvark. She is quite insistent on this point. And remember- when all else fails- and no one else can help- boutell@freezer.it.udel.edu
avalon@phoenix.pub.uu.oz.au (Darren Reed) (12/15/90)
Can someone tell me how signals work inside C on unix ? I've seen an alarm() used to timeout a write() call in something like this: alarm(15); write(fd, buf, num); which caused the write to exit if it wasnt successful after 15 seconds. I'm looking for a way of using 'HOT' keys in a program and I'd like to use the keyboard to interrupt the program (cease whatever its doing) and then go on to process the new keypress. I noticed there is a SIGIO, but from what I've read in the odd post, that needs some ioctl() or similar calls to setup. any info would be greatly appreciated.