[9659] in Athena Bugs

home help back first fref pref prev next nref lref last post

libss.a: POSIX patches

daemon@ATHENA.MIT.EDU (Richard Basch)
Sun Jul 19 11:44:00 1992

Date: Sun, 19 Jul 92 11:43:41 -0400
To: bugs@MIT.EDU
From: "Richard Basch" <basch@MIT.EDU>


The following patches will make "mrtest" function properly on a
RISC/6000; the patches are to make the ss library more POSIX compliant
(with respect to signal handling).  I made one slight functionality
change because read() will return EINTR if interrupted by a signal,
unless the SA_RESTART flag is set (but this flag is not portable
to any other architecture, so I worked around it by using the other
interrupt handler).

If we decide to take on any more POSIX architectures, we are going to
have to do this, in turn, to everything.

I also have patches for "attach" to make that POSIX compliant (mostly).

-Richard


*** /tmp/,RCSt1a08453	Sun Jul 19 11:34:09 1992
--- list_rqs.c	Sun Jul 19 03:20:24 1992
***************
*** 34,45 ****
      char buffer[BUFSIZ];
      FILE *output;
      int fd;
-     int mask;
  #ifdef POSIX
!     void (*func)();
      int waitb;
  #else
      int (*func)();
      union wait waitb;
  #endif
  
--- 34,46 ----
      char buffer[BUFSIZ];
      FILE *output;
      int fd;
  #ifdef POSIX
!     struct sigaction nsig, osig;
!     sigset_t nmask, omask;
      int waitb;
  #else
      int (*func)();
+     int mask;
      union wait waitb;
  #endif
  
***************
*** 46,56 ****
--- 47,72 ----
      DONT_USE(argc);
      DONT_USE(argv);
  
+ #ifdef POSIX
+     sigemptyset(&nmask);
+     sigaddset(&nmask, SIGINT);
+     sigprocmask(SIG_BLOCK, &nmask, &omask);
+     
+     nsig.sa_handler = SIG_IGN;
+     sigemptyset(&nsig.sa_mask);
+     nsig.sa_flags = 0;
+     sigaction(SIGINT, &nsig, &osig);
+ #else
      mask = sigblock(sigmask(SIGINT));
      func = signal(SIGINT, SIG_IGN);
+ #endif
      fd = ss_pager_create();
      output = fdopen(fd, "w");
+ #ifdef POSIX
+     sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
+ #else
      sigsetmask(mask);
+ #endif
  
      fprintf (output, "Available %s requests:\n\n",
  	     ss_info (sci_idx) -> subsystem_name);
***************
*** 86,90 ****
--- 102,110 ----
  #ifndef NO_FORK
      wait(&waitb);
  #endif
+ #ifdef POSIX
+     sigaction(SIGINT, &osig, (struct sigaction *)0);
+ #else
      (void) signal(SIGINT, func);
+ #endif
  }
*** /tmp/,RCSt1a08453	Sun Jul 19 11:34:13 1992
--- listen.c	Sun Jul 19 11:31:50 1992
***************
*** 28,34 ****
  #define sigtype void
  #else
  #define sigtype int
! #endif POSIX
  
  extern char *index();
  
--- 28,34 ----
  #define sigtype void
  #else
  #define sigtype int
! #endif
  
  extern char *index();
  
***************
*** 61,100 ****
      int sci_idx;
  {
      register char *cp;
-     register sigtype (*sig_cont)();
      register ss_data *info;
-     sigtype (*sig_int)(), (*old_sig_cont)();
      char input[BUFSIZ];
      char expanded_input[BUFSIZ];
      char buffer[BUFSIZ];
      char *end = buffer;
-     int mask;
      int code;
      jmp_buf old_jmpb;
      ss_data *old_info = current_info;
      static sigtype print_prompt();
  
      current_info = info = ss_info(sci_idx);
-     sig_cont = (sigtype (*)())0;
      info->abort = 0;
      mask = sigblock(sigmask(SIGINT));
      bcopy(listen_jmpb, old_jmpb, sizeof(jmp_buf));
      sig_int = signal(SIGINT, listen_int_handler);
      setjmp(listen_jmpb);
      (void) sigsetmask(mask);
      while(!info->abort) {
  	print_prompt();
  	*end = '\0';
  	old_sig_cont = sig_cont;
  	sig_cont = signal(SIGCONT, print_prompt);
  #ifdef mips
! 	/* The mips compiler breaks on determining the types,
! 	   we help */
  	if ( (sigtype *) sig_cont == (sigtype *) print_prompt)
  #else
! 	if ( sig_cont == print_prompt)
! #endif
  	    sig_cont = old_sig_cont;
  	if (fgets(input, BUFSIZ, stdin) != input) {
  	    code = SS_ET_EOF;
  	    goto egress;
--- 61,136 ----
      int sci_idx;
  {
      register char *cp;
      register ss_data *info;
      char input[BUFSIZ];
      char expanded_input[BUFSIZ];
      char buffer[BUFSIZ];
      char *end = buffer;
      int code;
      jmp_buf old_jmpb;
      ss_data *old_info = current_info;
      static sigtype print_prompt();
+ #ifdef POSIX
+     struct sigaction isig, csig, nsig, osig;
+     sigset_t nmask, omask;
+ #else
+     register sigtype (*sig_cont)();
+     sigtype (*sig_int)(), (*old_sig_cont)();
+     int mask;
+ #endif
  
      current_info = info = ss_info(sci_idx);
      info->abort = 0;
+ #ifdef POSIX
+     csig.sa_handler = (sigtype (*)())0;
+     
+     sigemptyset(&nmask);
+     sigaddset(&nmask, SIGINT);
+     sigprocmask(SIG_BLOCK, &nmask, &omask);
+ #else
+     sig_cont = (sigtype (*)())0;
      mask = sigblock(sigmask(SIGINT));
+ #endif
+ 
      bcopy(listen_jmpb, old_jmpb, sizeof(jmp_buf));
+ 
+ #ifdef POSIX    
+     nsig.sa_handler = listen_int_handler;
+     sigemptyset(&nsig.sa_mask);
+     nsig.sa_flags = 0;
+     sigaction(SIGINT, &nsig, &isig);
+ #else
      sig_int = signal(SIGINT, listen_int_handler);
+ #endif
+ 
      setjmp(listen_jmpb);
+ 
+ #ifdef POSIX
+     sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
+ #else
      (void) sigsetmask(mask);
+ #endif
      while(!info->abort) {
  	print_prompt();
  	*end = '\0';
+ #ifdef POSIX
+ 	nsig.sa_handler = listen_int_handler;	/* fgets is not signal-safe */
+ 	osig = csig;
+ 	sigaction(SIGCONT, &nsig, &csig);
+ 	if ((sigtype (*)())csig.sa_handler==(sigtype (*)())listen_int_handler)
+ 	    csig = osig;
+ #else
  	old_sig_cont = sig_cont;
  	sig_cont = signal(SIGCONT, print_prompt);
  #ifdef mips
! 	/* The mips compiler breaks on determining the types, we help */
  	if ( (sigtype *) sig_cont == (sigtype *) print_prompt)
+ 	    sig_cont = old_sig_cont;
  #else
! 	if (sig_cont == print_prompt)
  	    sig_cont = old_sig_cont;
+ #endif
+ #endif
  	if (fgets(input, BUFSIZ, stdin) != input) {
  	    code = SS_ET_EOF;
  	    goto egress;
***************
*** 105,111 ****
--- 141,151 ----
  	    if (cp == input)
  		continue;
  	}
+ #ifdef POSIX
+ 	sigaction(SIGCONT, &csig, (struct sigaction *)0);
+ #else
  	(void) signal(SIGCONT, sig_cont);
+ #endif
  	for (end = input; *end; end++)
  	    ;
  
***************
*** 127,133 ****
--- 167,177 ----
      }
      code = 0;
  egress:
+ #ifdef POSIX
+     sigaction(SIGINT, &isig, (struct sigaction *)0);
+ #else
      (void) signal(SIGINT, sig_int);
+ #endif
      bcopy(old_jmpb, listen_jmpb, sizeof(jmp_buf));
      current_info = old_info;
      return code;
*** /tmp/,RCSt1a08453	Sun Jul 19 11:34:14 1992
--- pager.c	Sun Jul 19 03:31:08 1992
***************
*** 67,79 ****
--- 67,97 ----
  void ss_page_stdin()
  {
  	int i;
+ #ifdef POSIX
+ 	struct sigaction sa;
+ 	sigset_t mask;
+ #endif
+ 	
  	for (i = 3; i < 32; i++)
  		(void) close(i);
+ #ifdef POSIX
+ 	sa.sa_handler = SIG_DFL;
+ 	sigemptyset(&sa.sa_mask);
+ 	sa.sa_flags = 0;
+ 	sigaction(SIGINT, &sa, (struct sigaction *)0);
+ #else
  	(void) signal(SIGINT, SIG_DFL);
+ #endif
  	{
+ #ifdef POSIX
+ 		sigemptyset(&mask);
+ 		sigaddset(&mask, SIGINT);
+ 		sigprocmask(SIG_UNBLOCK, &mask, (sigset_t *)0);
+ #else
  		register int mask = sigblock(0);
  		mask &= ~sigmask(SIGINT);
  		sigsetmask(mask);
+ #endif
  	}
  	if (_ss_pager_name == (char *)NULL) {
  		if ((_ss_pager_name = getenv("PAGER")) == (char *)NULL)

home help back first fref pref prev next nref lref last post