Article View: vmsnet.alpha
Article #5SIGINT handles only once
From: Craig Chamberlain
Date: Tue, 22 Dec 1992 16:31
Date: Tue, 22 Dec 1992 16:31
162 lines
3379 bytes
3379 bytes
Here's another signal handling problem I've discovered.
SIGINT, which is for CTRL-C, seems to want to be handled
only once, even though it is reset with a new call to signal()
each occurrence. On the VAX my test program runs fine.
CTRL-C must be hit on the main console three times. On the
Alpha, the first CTRL-C is handled, the second one isn't,
and the third one quietly terminates the program.
If anyone else has encountered these problems or can even duplicate
them, it would be very helpful to me to know that. Email replies
appreciated. (Are other people also experiencing the problems I've
been posting about or am I making a fool of myself with these posts?)
VAX:
$ cc test_sigint.c
$ link test_sigint
$ r test_sigint
ready for 1st test
Cancel
signal handled: sig 2 code -2
SIGINT
ready for 2nd test
Cancel
signal handled: sig 2 code -2
SIGINT
ready for 3rd test
Cancel
signal handled: sig 2 code -2
SIGINT
finished
ALPHA:
$ cc/standard=vaxc/float=ieee_float test_sigint.c
$ link test_sigint
$ r test_sigint
ready for 1st test
Cancel
signal handled: sig 2 code -2
SIGINT
ready for 2nd test
Cancel
Cancel
Here is the code:
/* test_sigint.c */
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <setjmp.h>
#ifndef sigmask
#define sigmask(x) (1 << ((x)-1))
#endif
static void (*save_sigint)();
static jmp_buf env;
static void
e__except()
{
longjmp(env, 1);
}
static void
e__hdwerr (sig, code, scp)
int sig;
int code;
struct sigcontext* scp;
{
/* re-enable the signal that just occurred */
sigsetmask (sigblock (0) & ~sigmask(sig));
if ((int) signal (SIGINT, (void (*)(int)) e__hdwerr) == -1)
printf("error - signal(SIGINT, ...) re-init failed\n");
printf("signal handled: sig %d code %d\n", sig, code);
if (sig == SIGINT)
printf("SIGINT\n");
e__except();
printf("error - execution should not have reached here\n");
} /* e__hdwerr */
void
initialize()
{
save_sigint = signal (SIGINT, (void (*)(int)) e__hdwerr);
if ((int) save_sigint == -1)
printf("signal(SIGINT, ...) failed");
}
int true = 1;
int
main (argc, argv)
int argc;
char *argv [];
{
initialize();
if (setjmp(env) == 0) {
printf("ready for 1st test\n");
while (true)
;
}
else {
if (setjmp(env) == 0) {
printf("ready for 2nd test\n");
while (true)
;
}
else {
if (setjmp(env) == 0) {
printf("ready for 3rd test\n");
while (true)
;
}
else
printf("finished\n");
}
}
} /* main */
--
(My opinions do not necessarily represent those of my employer.)
Craig Chamberlain, Software Engineer, Applicon Schlumberger
Ann Arbor, Michigan chamber@ann-arbor.applicon.slb.com (313) 995-6310
Technical Details
Message-ID:
<1992Dec22.163159.22768@ann-arbor.applicon.slb.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!geraldo.cc.utexas.edu!slcs.slb.com!aa.cad.slb.com!chamberShow Full Headers
Complete Article Headers
Newsgroups: vmsnet.alpha Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!geraldo.cc.utexas.edu!slcs.slb.com!aa.cad.slb.com!chamber From: chamber@mailhost.aa.cad.slb.com (Craig Chamberlain) Subject: SIGINT handles only once Message-ID: <1992Dec22.163159.22768@ann-arbor.applicon.slb.com> Sender: usenet@ann-arbor.applicon.slb.com (Usenet Administrator) Organization: Schlumberger CAD/CAM at Ann Arbor, MI Date: Tue, 22 Dec 1992 16:31:59 GMT Lines: 162