delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/09/06/00:20:21

From: Ian AT kiwiplan DOT co DOT nz (Ian Collins)
Subject: Signal handling - HELP!
6 Sep 1997 00:20:21 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <07551A47EAD6D01186430060B025C6F40A6CAE.cygnus.gnu-win32@ntserver.kiwiplan2.co.nz>
Mime-Version: 1.0
Original-To: "'Gnu win32 mailer'" <gnu-win32 AT cygnus DOT com>
X-Priority: 3
X-Mailer: Internet Mail Service (5.0.1457.3)
Original-Sender: owner-gnu-win32 AT cygnus DOT com

HELP!
Signal handling is not functioning as expected under gnu-win32. 

When a signal (e.g. SIGALRM) is triggored while in certain system calls
(e.g, read), the POSIX signal definition states that after completion of
the signal handler, the system call can be made to continue (SA_RESTART)
or to return with an error status set.

In my application, I require the read system call to RETURN after a
SIGALRM. This same code is running as required on many flavours of UNIX,
but under GNU-WIN32 (b18), the read system call ALWAYS restarts (i.e,
does not return).

Following is a small program that illustrates the problem:

#include <stdio.h>
#include <signal.h>
 
main()
{
  extern void callme();
  int c;
  int tm = 2;
  while (1) {
    (void) fexec_signal(SIGALRM, tm, callme);
    if (read(0, c, 1) >0) {
      printf("Read returned %c\n", c);
    }
    else {
      printf("Read returned negative\n");
    }
    alarm(0);
  }
}

int fexec_signal(sig, tm, routine_name)
     int sig;
     int tm;
     void (*routine_name)();
{
  struct sigaction vec;
  vec.sa_handler = routine_name;
  if (sigemptyset(&vec.sa_mask) == -1) return -1;
  vec.sa_flags = 0;
  if (sigaction(sig, &vec, NULL) == -1) return -1;
  if (sig == SIGALRM) alarm(tm);
  return 0;
}

void callme()
{
  printf("Timed out\n");
}
 

Many Regards,
Ian Collins

-
For help on using this list (especially unsubscribing), send a message
to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019