1994-05-11 08:59:13 +00:00
|
|
|
/***********************************************************
|
1995-01-04 19:10:35 +00:00
|
|
|
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
|
|
|
|
The Netherlands.
|
1994-05-11 08:59:13 +00:00
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
|
|
|
provided that the above copyright notice appear in all copies and that
|
|
|
|
both that copyright notice and this permission notice appear in
|
|
|
|
supporting documentation, and that the names of Stichting Mathematisch
|
|
|
|
Centrum or CWI not be used in advertising or publicity pertaining to
|
|
|
|
distribution of the software without specific, written prior permission.
|
|
|
|
|
|
|
|
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
|
|
|
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
|
|
|
|
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
|
|
|
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
1995-01-02 19:30:30 +00:00
|
|
|
/* Signal module -- many thanks to Lance Ellinghaus */
|
1994-05-11 08:59:13 +00:00
|
|
|
|
1994-09-14 13:32:22 +00:00
|
|
|
#include "Python.h"
|
1994-05-11 08:59:13 +00:00
|
|
|
#include "intrcheck.h"
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
1994-06-23 11:25:45 +00:00
|
|
|
#ifndef SIG_ERR
|
|
|
|
#define SIG_ERR ((RETSIGTYPE (*)())-1)
|
|
|
|
#endif
|
|
|
|
|
1995-01-02 19:30:30 +00:00
|
|
|
#ifndef NSIG
|
|
|
|
#define NSIG (_SIGMAX + 1) /* For QNX */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1994-06-23 11:25:45 +00:00
|
|
|
/*
|
|
|
|
NOTES ON THE INTERACTION BETWEEN SIGNALS AND THREADS
|
|
|
|
|
|
|
|
When threads are supported, we want the following semantics:
|
|
|
|
|
|
|
|
- only the main thread can set a signal handler
|
|
|
|
- any thread can get a signal handler
|
|
|
|
- signals are only delivered to the main thread
|
|
|
|
|
|
|
|
I.e. we don't support "synchronous signals" like SIGFPE (catching
|
|
|
|
this doesn't make much sense in Python anyway) nor do we support
|
|
|
|
signals as a means of inter-thread communication, since not all
|
|
|
|
thread implementations support that (at least our thread library
|
|
|
|
doesn't).
|
|
|
|
|
|
|
|
We still have the problem that in some implementations signals
|
|
|
|
generated by the keyboard (e.g. SIGINT) are delivered to all
|
|
|
|
threads (e.g. SGI), while in others (e.g. Solaris) such signals are
|
|
|
|
delivered to one random thread (an intermediate possibility would
|
1995-01-12 11:29:01 +00:00
|
|
|
be to deliver it to the main thread -- POSIX?). For now, we have
|
1994-06-23 11:25:45 +00:00
|
|
|
a working implementation that works in all three cases -- the
|
|
|
|
handler ignores signals if getpid() isn't the same as in the main
|
|
|
|
thread. XXX This is a hack.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef WITH_THREAD
|
|
|
|
#include "thread.h"
|
|
|
|
static long main_thread;
|
|
|
|
static pid_t main_pid;
|
|
|
|
#endif
|
|
|
|
|
1994-09-07 14:32:49 +00:00
|
|
|
struct PySignal_SignalArrayStruct {
|
1994-05-11 08:59:13 +00:00
|
|
|
int tripped;
|
1994-09-07 14:32:49 +00:00
|
|
|
PyObject *func;
|
1994-05-11 08:59:13 +00:00
|
|
|
};
|
|
|
|
|
1994-09-07 14:32:49 +00:00
|
|
|
static struct PySignal_SignalArrayStruct PySignal_SignalHandlerArray[NSIG];
|
|
|
|
static int PySignal_IsTripped = 0; /* Speed up sigcheck() when none tripped */
|
1994-05-11 08:59:13 +00:00
|
|
|
|
1994-09-07 14:32:49 +00:00
|
|
|
static PyObject *PySignal_SignalDefaultHandler;
|
|
|
|
static PyObject *PySignal_SignalIgnoreHandler;
|
|
|
|
static PyObject *PySignal_DefaultIntHandler;
|
1994-05-11 08:59:13 +00:00
|
|
|
|
1994-09-07 14:32:49 +00:00
|
|
|
static PyObject *
|
|
|
|
PySignal_CDefaultIntHandler(self, arg)
|
|
|
|
PyObject *self;
|
|
|
|
PyObject *arg;
|
1994-05-11 08:59:13 +00:00
|
|
|
{
|
1994-09-07 14:32:49 +00:00
|
|
|
PyErr_SetNone(PyExc_KeyboardInterrupt);
|
|
|
|
return (PyObject *)NULL;
|
1994-05-11 08:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static RETSIGTYPE
|
1994-09-07 14:32:49 +00:00
|
|
|
PySignal_Handler(sig_num)
|
|
|
|
int sig_num;
|
1994-05-11 08:59:13 +00:00
|
|
|
{
|
1994-06-23 11:25:45 +00:00
|
|
|
#ifdef WITH_THREAD
|
|
|
|
/* See NOTES section above */
|
|
|
|
if (getpid() == main_pid) {
|
|
|
|
#endif
|
1994-09-07 14:32:49 +00:00
|
|
|
PySignal_IsTripped++;
|
|
|
|
PySignal_SignalHandlerArray[sig_num].tripped = 1;
|
1994-06-23 11:25:45 +00:00
|
|
|
#ifdef WITH_THREAD
|
|
|
|
}
|
1994-09-14 13:32:22 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCHLD
|
|
|
|
if (sig_num == SIGCHLD) {
|
|
|
|
/* To avoid infinite recursion, this signal remains
|
|
|
|
reset until explicit re-instated.
|
|
|
|
Don't clear the 'func' field as it is our pointer
|
|
|
|
to the Python handler... */
|
|
|
|
return;
|
|
|
|
}
|
1994-06-23 11:25:45 +00:00
|
|
|
#endif
|
1994-09-07 14:32:49 +00:00
|
|
|
(void *)signal(sig_num, &PySignal_Handler);
|
1994-05-11 08:59:13 +00:00
|
|
|
}
|
|
|
|
|
1994-09-07 14:32:49 +00:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
PySignal_Alarm(self, args)
|
|
|
|
PyObject *self; /* Not used */
|
|
|
|
PyObject *args;
|
1994-08-01 11:34:53 +00:00
|
|
|
{
|
|
|
|
int t;
|
1994-09-07 14:32:49 +00:00
|
|
|
if (!PyArg_Parse(args, "i", &t))
|
|
|
|
return (PyObject *)NULL;
|
|
|
|
/* alarm() returns the number of seconds remaining */
|
|
|
|
return PyInt_FromLong(alarm(t));
|
1994-08-01 11:34:53 +00:00
|
|
|
}
|
1994-09-07 14:32:49 +00:00
|
|
|
|
1995-01-10 20:56:29 +00:00
|
|
|
static PyObject *
|
1994-09-07 14:32:49 +00:00
|
|
|
PySignal_Pause(self, args)
|
|
|
|
PyObject *self; /* Not used */
|
|
|
|
PyObject *args;
|
1994-08-23 13:49:37 +00:00
|
|
|
{
|
1994-09-07 14:32:49 +00:00
|
|
|
if (!PyArg_NoArgs(args))
|
1994-08-23 13:49:37 +00:00
|
|
|
return NULL;
|
1995-01-10 20:56:29 +00:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1994-08-23 13:49:37 +00:00
|
|
|
pause();
|
1995-01-10 20:56:29 +00:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-09-07 14:32:49 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-08-23 13:49:37 +00:00
|
|
|
}
|
1994-08-01 11:34:53 +00:00
|
|
|
|
1994-09-07 14:32:49 +00:00
|
|
|
static PyObject *
|
|
|
|
PySignal_Signal(self, args)
|
|
|
|
PyObject *self; /* Not used */
|
|
|
|
PyObject *args;
|
1994-05-11 08:59:13 +00:00
|
|
|
{
|
1994-09-07 14:32:49 +00:00
|
|
|
PyObject *obj;
|
1994-05-11 08:59:13 +00:00
|
|
|
int sig_num;
|
1994-09-07 14:32:49 +00:00
|
|
|
PyObject *old_handler;
|
1994-05-11 08:59:13 +00:00
|
|
|
RETSIGTYPE (*func)();
|
1994-09-07 14:32:49 +00:00
|
|
|
if (!PyArg_Parse(args, "(iO)", &sig_num, &obj))
|
|
|
|
return (PyObject *)NULL;
|
1994-06-23 11:25:45 +00:00
|
|
|
#ifdef WITH_THREAD
|
|
|
|
if (get_thread_ident() != main_thread) {
|
1994-09-07 14:32:49 +00:00
|
|
|
PyErr_SetString(PyExc_ValueError, "signal only works in main thread");
|
|
|
|
return (PyObject *)NULL;
|
1994-06-23 11:25:45 +00:00
|
|
|
}
|
|
|
|
#endif
|
1994-05-11 08:59:13 +00:00
|
|
|
if (sig_num < 1 || sig_num >= NSIG) {
|
1994-09-07 14:32:49 +00:00
|
|
|
PyErr_SetString(PyExc_ValueError, "signal number out of range");
|
|
|
|
return (PyObject *)NULL;
|
1994-05-11 08:59:13 +00:00
|
|
|
}
|
1994-09-07 14:32:49 +00:00
|
|
|
if (obj == PySignal_SignalIgnoreHandler)
|
1994-05-11 08:59:13 +00:00
|
|
|
func = SIG_IGN;
|
1994-09-07 14:32:49 +00:00
|
|
|
else if (obj == PySignal_SignalDefaultHandler)
|
1994-05-11 08:59:13 +00:00
|
|
|
func = SIG_DFL;
|
1994-09-07 14:32:49 +00:00
|
|
|
else if (!PyCFunction_Check(obj) &&
|
|
|
|
!PyFunction_Check(obj) &&
|
|
|
|
!PyMethod_Check(obj)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
1994-05-11 08:59:13 +00:00
|
|
|
"signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object");
|
1994-09-07 14:32:49 +00:00
|
|
|
return (PyObject *)NULL;
|
1994-05-11 08:59:13 +00:00
|
|
|
}
|
|
|
|
else
|
1994-09-07 14:32:49 +00:00
|
|
|
func = PySignal_Handler;
|
1994-06-23 11:25:45 +00:00
|
|
|
if (signal(sig_num, func) == SIG_ERR) {
|
1994-09-07 14:32:49 +00:00
|
|
|
PyErr_SetFromErrno(PyExc_RuntimeError);
|
|
|
|
return (PyObject *)NULL;
|
1994-06-23 11:25:45 +00:00
|
|
|
}
|
1994-09-07 14:32:49 +00:00
|
|
|
old_handler = PySignal_SignalHandlerArray[sig_num].func;
|
|
|
|
PySignal_SignalHandlerArray[sig_num].tripped = 0;
|
|
|
|
Py_INCREF(obj);
|
|
|
|
PySignal_SignalHandlerArray[sig_num].func = obj;
|
1994-05-11 08:59:13 +00:00
|
|
|
return old_handler;
|
|
|
|
}
|
|
|
|
|
1994-09-07 14:32:49 +00:00
|
|
|
static PyObject *
|
|
|
|
PySignal_GetSignal(self, args)
|
|
|
|
PyObject *self; /* Not used */
|
|
|
|
PyObject *args;
|
1994-05-11 08:59:13 +00:00
|
|
|
{
|
|
|
|
int sig_num;
|
1994-09-07 14:32:49 +00:00
|
|
|
PyObject *old_handler;
|
|
|
|
if (!PyArg_Parse(args, "i", &sig_num))
|
|
|
|
return (PyObject *)NULL;
|
1994-05-11 08:59:13 +00:00
|
|
|
if (sig_num < 1 || sig_num >= NSIG) {
|
1994-09-07 14:32:49 +00:00
|
|
|
PyErr_SetString(PyExc_ValueError, "signal number out of range");
|
|
|
|
return (PyObject *)NULL;
|
1994-05-11 08:59:13 +00:00
|
|
|
}
|
1994-09-07 14:32:49 +00:00
|
|
|
old_handler = PySignal_SignalHandlerArray[sig_num].func;
|
|
|
|
Py_INCREF(old_handler);
|
1994-05-11 08:59:13 +00:00
|
|
|
return old_handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* List of functions defined in the module */
|
|
|
|
|
1994-09-07 14:32:49 +00:00
|
|
|
static PyMethodDef PySignal_methods[] = {
|
|
|
|
{"alarm", PySignal_Alarm},
|
|
|
|
{"signal", PySignal_Signal},
|
|
|
|
{"getsignal", PySignal_GetSignal},
|
|
|
|
{"pause", PySignal_Pause},
|
1995-01-07 11:50:04 +00:00
|
|
|
{"default_int_handler", PySignal_CDefaultIntHandler},
|
1994-05-11 08:59:13 +00:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
initsignal()
|
|
|
|
{
|
1994-09-07 14:32:49 +00:00
|
|
|
PyObject *m, *d, *x;
|
1994-05-11 08:59:13 +00:00
|
|
|
int i;
|
1994-06-23 11:25:45 +00:00
|
|
|
|
|
|
|
#ifdef WITH_THREAD
|
|
|
|
main_thread = get_thread_ident();
|
|
|
|
main_pid = getpid();
|
|
|
|
#endif
|
|
|
|
|
1994-05-11 08:59:13 +00:00
|
|
|
/* Create the module and add the functions */
|
1994-09-07 14:32:49 +00:00
|
|
|
m = Py_InitModule("signal", PySignal_methods);
|
1994-05-11 08:59:13 +00:00
|
|
|
|
|
|
|
/* Add some symbolic constants to the module */
|
1994-09-07 14:32:49 +00:00
|
|
|
d = PyModule_GetDict(m);
|
|
|
|
|
|
|
|
PySignal_SignalDefaultHandler = PyInt_FromLong((long)SIG_DFL);
|
|
|
|
PyDict_SetItemString(d, "SIG_DFL", PySignal_SignalDefaultHandler);
|
|
|
|
PySignal_SignalIgnoreHandler = PyInt_FromLong((long)SIG_IGN);
|
|
|
|
PyDict_SetItemString(d, "SIG_IGN", PySignal_SignalIgnoreHandler);
|
|
|
|
PyDict_SetItemString(d, "NSIG", PyInt_FromLong((long)NSIG));
|
1995-01-07 11:50:04 +00:00
|
|
|
PySignal_DefaultIntHandler =
|
|
|
|
PyDict_GetItemString(d, "default_int_handler");
|
1994-05-11 08:59:13 +00:00
|
|
|
|
1994-09-07 14:32:49 +00:00
|
|
|
PySignal_SignalHandlerArray[0].tripped = 0;
|
1994-05-11 08:59:13 +00:00
|
|
|
for (i = 1; i < NSIG; i++) {
|
1994-05-31 12:51:13 +00:00
|
|
|
RETSIGTYPE (*t)();
|
1994-05-11 08:59:13 +00:00
|
|
|
t = signal(i, SIG_IGN);
|
|
|
|
signal(i, t);
|
1994-09-07 14:32:49 +00:00
|
|
|
PySignal_SignalHandlerArray[i].tripped = 0;
|
1994-05-11 08:59:13 +00:00
|
|
|
if (t == SIG_DFL)
|
1994-09-07 14:32:49 +00:00
|
|
|
PySignal_SignalHandlerArray[i].func = PySignal_SignalDefaultHandler;
|
1994-05-11 08:59:13 +00:00
|
|
|
else if (t == SIG_IGN)
|
1994-09-07 14:32:49 +00:00
|
|
|
PySignal_SignalHandlerArray[i].func = PySignal_SignalIgnoreHandler;
|
1994-05-11 08:59:13 +00:00
|
|
|
else
|
1994-09-07 14:32:49 +00:00
|
|
|
PySignal_SignalHandlerArray[i].func = Py_None; /* None of our business */
|
|
|
|
Py_INCREF(PySignal_SignalHandlerArray[i].func);
|
1994-05-11 08:59:13 +00:00
|
|
|
}
|
1994-09-07 14:32:49 +00:00
|
|
|
if (PySignal_SignalHandlerArray[SIGINT].func == PySignal_SignalDefaultHandler) {
|
1994-05-11 08:59:13 +00:00
|
|
|
/* Install default int handler */
|
1994-09-07 14:32:49 +00:00
|
|
|
Py_DECREF(PySignal_SignalHandlerArray[SIGINT].func);
|
|
|
|
PySignal_SignalHandlerArray[SIGINT].func = PySignal_DefaultIntHandler;
|
|
|
|
Py_INCREF(PySignal_DefaultIntHandler);
|
|
|
|
signal(SIGINT, &PySignal_Handler);
|
1994-05-11 08:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SIGHUP
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGHUP);
|
|
|
|
PyDict_SetItemString(d, "SIGHUP", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGINT
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGINT);
|
|
|
|
PyDict_SetItemString(d, "SIGINT", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGQUIT);
|
|
|
|
PyDict_SetItemString(d, "SIGQUIT", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGILL
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGILL);
|
|
|
|
PyDict_SetItemString(d, "SIGILL", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTRAP
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGTRAP);
|
|
|
|
PyDict_SetItemString(d, "SIGTRAP", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIOT
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGIOT);
|
|
|
|
PyDict_SetItemString(d, "SIGIOT", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGABRT
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGABRT);
|
|
|
|
PyDict_SetItemString(d, "SIGABRT", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGEMT
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGEMT);
|
|
|
|
PyDict_SetItemString(d, "SIGEMT", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGFPE);
|
|
|
|
PyDict_SetItemString(d, "SIGFPE", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGKILL
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGKILL);
|
|
|
|
PyDict_SetItemString(d, "SIGKILL", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGBUS
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGBUS);
|
|
|
|
PyDict_SetItemString(d, "SIGBUS", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGSEGV);
|
|
|
|
PyDict_SetItemString(d, "SIGSEGV", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSYS
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGSYS);
|
|
|
|
PyDict_SetItemString(d, "SIGSYS", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGPIPE);
|
|
|
|
PyDict_SetItemString(d, "SIGPIPE", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGALRM
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGALRM);
|
|
|
|
PyDict_SetItemString(d, "SIGALRM", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGTERM);
|
|
|
|
PyDict_SetItemString(d, "SIGTERM", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGUSR1);
|
|
|
|
PyDict_SetItemString(d, "SIGUSR1", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGUSR2);
|
|
|
|
PyDict_SetItemString(d, "SIGUSR2", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCLD
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGCLD);
|
|
|
|
PyDict_SetItemString(d, "SIGCLD", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCHLD
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGCHLD);
|
|
|
|
PyDict_SetItemString(d, "SIGCHLD", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPWR
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGPWR);
|
|
|
|
PyDict_SetItemString(d, "SIGPWR", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIO
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGIO);
|
|
|
|
PyDict_SetItemString(d, "SIGIO", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGURG
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGURG);
|
|
|
|
PyDict_SetItemString(d, "SIGURG", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGWINCH);
|
|
|
|
PyDict_SetItemString(d, "SIGWINCH", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPOLL
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGPOLL);
|
|
|
|
PyDict_SetItemString(d, "SIGPOLL", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSTOP
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGSTOP);
|
|
|
|
PyDict_SetItemString(d, "SIGSTOP", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTSTP
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGTSTP);
|
|
|
|
PyDict_SetItemString(d, "SIGTSTP", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCONT
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGCONT);
|
|
|
|
PyDict_SetItemString(d, "SIGCONT", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTIN
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGTTIN);
|
|
|
|
PyDict_SetItemString(d, "SIGTTIN", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTOU
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGTTOU);
|
|
|
|
PyDict_SetItemString(d, "SIGTTOU", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGVTALRM
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGVTALRM);
|
|
|
|
PyDict_SetItemString(d, "SIGVTALRM", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPROF
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGPROF);
|
|
|
|
PyDict_SetItemString(d, "SIGPROF", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCPU
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGCPU);
|
|
|
|
PyDict_SetItemString(d, "SIGCPU", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGFSZ
|
1994-09-07 14:32:49 +00:00
|
|
|
x = PyInt_FromLong(SIGFSZ);
|
|
|
|
PyDict_SetItemString(d, "SIGFSZ", x);
|
1994-05-11 08:59:13 +00:00
|
|
|
#endif
|
|
|
|
/* Check for errors */
|
1994-09-07 14:32:49 +00:00
|
|
|
if (PyErr_Occurred())
|
|
|
|
Py_FatalError("can't initialize module signal");
|
1994-05-11 08:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1995-01-22 00:46:57 +00:00
|
|
|
PyErr_CheckSignals()
|
1994-05-11 08:59:13 +00:00
|
|
|
{
|
|
|
|
int i;
|
1994-09-07 14:32:49 +00:00
|
|
|
PyObject *f;
|
|
|
|
if (!PySignal_IsTripped)
|
1994-05-31 12:51:13 +00:00
|
|
|
return 0;
|
1994-06-23 11:25:45 +00:00
|
|
|
#ifdef WITH_THREAD
|
|
|
|
if (get_thread_ident() != main_thread)
|
|
|
|
return 0;
|
|
|
|
#endif
|
1995-01-10 20:56:29 +00:00
|
|
|
f = PyEval_GetFrame();
|
1994-09-07 14:32:49 +00:00
|
|
|
if (f == (PyObject *)NULL)
|
|
|
|
f = Py_None;
|
1994-05-11 08:59:13 +00:00
|
|
|
for (i = 1; i < NSIG; i++) {
|
1994-09-07 14:32:49 +00:00
|
|
|
if (PySignal_SignalHandlerArray[i].tripped) {
|
|
|
|
PyObject *arglist, *result;
|
|
|
|
PySignal_SignalHandlerArray[i].tripped = 0;
|
|
|
|
arglist = Py_BuildValue("(iO)", i, f);
|
|
|
|
if (arglist == (PyObject *)NULL)
|
|
|
|
result = (PyObject *)NULL;
|
1994-05-11 08:59:13 +00:00
|
|
|
else {
|
1994-09-07 14:32:49 +00:00
|
|
|
result = PyEval_CallObject(PySignal_SignalHandlerArray[i].func,arglist);
|
|
|
|
Py_DECREF(arglist);
|
1994-05-11 08:59:13 +00:00
|
|
|
}
|
1994-09-07 14:32:49 +00:00
|
|
|
if (result == (PyObject *)NULL) {
|
1994-05-11 08:59:13 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
1994-09-07 14:32:49 +00:00
|
|
|
Py_DECREF(result);
|
1994-05-11 08:59:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-09-07 14:32:49 +00:00
|
|
|
PySignal_IsTripped = 0;
|
1994-05-11 08:59:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Replacement for intrcheck.c functionality */
|
|
|
|
|
|
|
|
void
|
1995-01-10 20:56:29 +00:00
|
|
|
PyOS_InitInterrupts ()
|
1994-05-11 08:59:13 +00:00
|
|
|
{
|
|
|
|
initsignal();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1995-01-10 20:56:29 +00:00
|
|
|
PyOS_InterruptOccurred ()
|
1994-05-11 08:59:13 +00:00
|
|
|
{
|
1994-09-07 14:32:49 +00:00
|
|
|
if (PySignal_SignalHandlerArray[SIGINT].tripped) {
|
1994-06-23 11:25:45 +00:00
|
|
|
#ifdef WITH_THREAD
|
|
|
|
if (get_thread_ident() != main_thread)
|
|
|
|
return 0;
|
|
|
|
#endif
|
1994-09-07 14:32:49 +00:00
|
|
|
PySignal_SignalHandlerArray[SIGINT].tripped = 0;
|
1994-05-31 12:51:13 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
1994-05-11 08:59:13 +00:00
|
|
|
}
|