[net.unix] Curses signal handling question

lorien@dartvax.UUCP (Lorien Y. Pratt) (04/16/84)

I have a program that uses the curses package.  I am attempting
to implement a feature where, after a certain amount of user idle
time, the program disconnects itself.

The section of code that I've written to implement this feature
looks like the following:

  signal(SIGALRM,hangup); 	/* If the alarm sounds, log user off */
  alarm(NUMSEC);  		/* Call the alarm clock */
  wgetstr( window, line );	/* Get a line from the screen */
  signal(SIGALRM,SIG_IGN);  	/* If we returned from input routine, ignore 
				   alarm */

(`hangup()' is my own disconnect routine)

This does not work.  When not using curses, however, it works like a
dream.  So I strongly suspect that curses is ignoring SIGALRM calls.
I've been through the curses source, however, and can't find any code
that looks like an alarm-ignorer.  I'm running under 4.2BSD.  Help!


      --Lorien Y. Pratt
	Dartmouth College Library
	Hanover, NH  03755

	decvax!dartvax!lorien

laman@sdcsvax.UUCP (04/17/84)

Execute the following program...  See if you can still generate the problem.
The only "problem" I had was that I had to type a line feed to get wgetstr()
to return; otherwise it kept reading and the alarm went off.  If you still
have the missing alarm problem, then let me know (And the net too... someone
else may have encoutered this bug).  If this works then I would suggest going
over your program.  I tried to change as little as possible of the code you
sent.

Program begins:...
#include	<curses.h>
#include	<signal.h>

#define		NUMSEC		10

WINDOW *window;

main() {
	register i;
	int hangup();
	char line[80];

	initscr();
	window = stdscr;
	mvaddstr(3, 5, "Here we go...\n");
	refresh();
/* Original code from the net */
  signal(SIGALRM,hangup); 	/* If the alarm sounds, log user off */
  alarm(NUMSEC);  		/* Call the alarm clock */
  /* I added the return value check and the following line for debuging */
  i = wgetstr( window, line );	/* Get a line from the screen */
  fprintf(stderr, "wgetstr returned %d.\n", i); fflush(stderr); /* Mike Added */
  signal(SIGALRM,SIG_IGN);  	/* If we returned from input routine, ignore 
				   alarm */
/* End of original code from network */
	mvaddstr(5, 5, "No problem...\n");
	refresh();
	goodbye(0);
}

hangup() {
	write(2, "HANGUP\n", 7);
	goodbye(1);
}

goodbye(retval)
int retval;
{
	endwin();
	exit(retval);
}
End of program...

			Mike Laman
			UUCP: {ucbvax,philabs,sdccsu3,sdcsla}!sdcsvax!laman