Path: utzoo!attcan!uunet!wuarchive!julius.cs.uiuc.edu!psuvax1!rutgers!cmcl2!adm!news From: stanonik@nprdc.navy.mil (Ron Stanonik) Newsgroups: comp.unix.internals Subject: gets() during signal Message-ID: <25232@adm.brl.mil> Date: 10 Dec 90 18:09:53 GMT Sender: news@adm.brl.mil Lines: 59 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. Here's an example program. It use SIGINT to confirm that the user wants to exit. If the user answers "n", it returns to the main program, but that answer fouls up the gets() in the main program. Is this a bug or a feature? Putting a rewind(stdin) at the end of the handler seems to fix it, but that seems like voodoo programming. Thanks, Ron Stanonik stanonik@nprdc.navy.mil #include #include void onint(); main() { char buf[1024]; signal(SIGINT, onint); puts("first"); gets(buf); puts(buf); puts("second"); gets(buf); puts(buf); puts("third"); gets(buf); puts(buf); } void onint() { char buf[1024]; puts("exit?"); gets(buf); if (!strcmp(buf, "y")) exit(0); /*rewind(stdin);*/ } Here's a sample run arctic[1] ./sig first hello hello second ^Cexit? n arf f third o arctic[2] exit