[comp.os.minix] problems with signals under 1.5.0

bill@chinet.chi.il.us (Bill Mitchell) (02/09/90)

I recently posted a hodgepodge of comments on de and elvis mixed
in with remarks about problems with signals.  I had hoped for some
reaction to the signals part, but have seen none.

My posting included a test program which failed on my minix 1.5.0
system.  I've now tried the test program on a Sun system at work,
and it runs just fine there.

Am I the only one with this problem?  If not, is there a known fix?

/*----------------- signals test program ------------------------*/

/*
** This program was put together from modules borrowed from
** the de disk editor program to test restoring of changed
** tty settings before exit by intercepting sigint and sigquit.
**
** I did this because I noticed my terminal being left in raw mode
** on some exits from de and from elvis.  This program restores tty
** settings just fine for normal exit, but either leaves me in raw
** mode or crashes my machine altogether for anything else.
**
** The program works just fine when tested on a Sun system at work,
** and restores tty settings nicely in all cases.
**
** This is pretty much unchanged from the original code borrowed from
** the de program except for a new main() and except for using memcpy
** in Set_Term() instead of saying struct_1 = struct_2.
**
*/

#include <sgtty.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>

void Save_Term(), Set_Term(), Reset_Term(), Sigint();

static struct sgttyb saved_mode;
static struct tchars saved_chars;

main() {
	Save_Term();
	Set_Term();
	signal( SIGINT,  Sigint );
 	signal( SIGQUIT, Sigint );
	printf("\
press 'i' for SIGINT\r\n\
press 'q' for SIGQUIT\r\n\
press 'o' for output test\r\n\
press anything else for normal exit:  ");
	if (getchar() == 'o')
		for(;;)
			printf("\r\npress 'i' or 'q'");
	Reset_Term();
	printf("\nNormal exit\n");
	exit(0);
}

void Save_Term()
  {
  ioctl( 0, TIOCGETP, &saved_mode  );
  ioctl( 0, TIOCGETC, &saved_chars );
  }

void Set_Term()
  {
  struct sgttyb mode;
  struct tchars chars;

  memcpy(&mode, &saved_mode, sizeof(struct sgttyb));
  memcpy(&chars, &saved_chars, sizeof(struct tchars));

  /*  No tab expansion, no echo, don't map ^M to ^J, cbreak mode  */
  mode.sg_flags = mode.sg_flags & ~XTABS & ~ECHO & ~CRMOD  |  CBREAK;

  /*  Change the interrupt and quit character */
  chars.t_intrc  = 'i';
  chars.t_quitc  = 'q';

  ioctl( 0, TIOCSETP, &mode  );
  ioctl( 0, TIOCSETC, &chars );
  }

void Reset_Term()
  {
  ioctl( 0, TIOCSETP, &saved_mode  );
  ioctl( 0, TIOCSETC, &saved_chars );
  }

void Sigint()
  {
  Reset_Term();		/*  Restore terminal characteristics	*/
  printf("\nSigint ran\n");
  exit( 1 );
  }