Subject: Signal handling - HELP!
From: [email-masked] (Ian Collins)

6 Sep 1997 00:20:21 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain
Original-To: "'Gnu win32 mailer'" <[email-masked]>
X-Priority: 3
X-Mailer: Internet Mail Service (5.0.1457.3)
Original-Sender: [email-masked]

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
"[email-masked]" with one line of text: "help".

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".