1994-05-11 16:59:13 +08:00
|
|
|
/***********************************************************
|
|
|
|
Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
|
|
|
|
Amsterdam, The Netherlands.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/* Signal module -- many thanks to Lance Ellinghouse */
|
|
|
|
|
1994-09-14 21:32:22 +08:00
|
|
|
#include "Python.h"
|
1994-05-11 16:59:13 +08:00
|
|
|
#include "intrcheck.h"
|
|
|
|
|
|
|
|
#include <signal.h>
|
1994-05-31 20:51:13 +08:00
|
|
|
#include <errno.h>
|
1994-05-11 16:59:13 +08:00
|
|
|
|
1994-06-23 19:25:45 +08:00
|
|
|
#ifndef SIG_ERR
|
|
|
|
#define SIG_ERR ((RETSIGTYPE (*)())-1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
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
|
|
|
|
be to deliver it to the main thread -- POSIX???). For now, we have
|
|
|
|
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 22:32:49 +08:00
|
|
|
struct PySignal_SignalArrayStruct {
|
1994-05-11 16:59:13 +08:00
|
|
|
int tripped;
|
1994-09-07 22:32:49 +08:00
|
|
|
PyObject *func;
|
1994-05-11 16:59:13 +08:00
|
|
|
};
|
|
|
|
|
1994-09-07 22:32:49 +08:00
|
|
|
static struct PySignal_SignalArrayStruct PySignal_SignalHandlerArray[NSIG];
|
|
|
|
static int PySignal_IsTripped = 0; /* Speed up sigcheck() when none tripped */
|
1994-05-11 16:59:13 +08:00
|
|
|
|
1994-09-07 22:32:49 +08:00
|
|
|
static PyObject *PySignal_SignalDefaultHandler;
|
|
|
|
static PyObject *PySignal_SignalIgnoreHandler;
|
|
|
|
static PyObject *PySignal_DefaultIntHandler;
|
1994-05-11 16:59:13 +08:00
|
|
|
|
1994-09-07 22:32:49 +08:00
|
|
|
static PyObject *
|
|
|
|
PySignal_CDefaultIntHandler(self, arg)
|
|
|
|
PyObject *self;
|
|
|
|
PyObject *arg;
|
1994-05-11 16:59:13 +08:00
|
|
|
{
|
1994-09-07 22:32:49 +08:00
|
|
|
PyErr_SetNone(PyExc_KeyboardInterrupt);
|
|
|
|
return (PyObject *)NULL;
|
1994-05-11 16:59:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static RETSIGTYPE
|
1994-09-07 22:32:49 +08:00
|
|
|
PySignal_Handler(sig_num)
|
|
|
|
int sig_num;
|
1994-05-11 16:59:13 +08:00
|
|
|
{
|
1994-06-23 19:25:45 +08:00
|
|
|
#ifdef WITH_THREAD
|
|
|
|
/* See NOTES section above */
|
|
|
|
if (getpid() == main_pid) {
|
|
|
|
#endif
|
1994-09-07 22:32:49 +08:00
|
|
|
PySignal_IsTripped++;
|
|
|
|
PySignal_SignalHandlerArray[sig_num].tripped = 1;
|
1994-06-23 19:25:45 +08:00
|
|
|
#ifdef WITH_THREAD
|
|
|
|
}
|
1994-09-14 21:32:22 +08: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 19:25:45 +08:00
|
|
|
#endif
|
1994-09-07 22:32:49 +08:00
|
|
|
(void *)signal(sig_num, &PySignal_Handler);
|
1994-05-11 16:59:13 +08:00
|
|
|
}
|
|
|
|
|
1994-09-07 22:32:49 +08:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
PySignal_Alarm(self, args)
|
|
|
|
PyObject *self; /* Not used */
|
|
|
|
PyObject *args;
|
1994-08-01 19:34:53 +08:00
|
|
|
{
|
|
|
|
int t;
|
1994-09-07 22:32:49 +08:00
|
|
|
int rtn;
|
|
|
|
if (!PyArg_Parse(args, "i", &t))
|
|
|
|
return (PyObject *)NULL;
|
|
|
|
/* alarm() returns the number of seconds remaining */
|
|
|
|
return PyInt_FromLong(alarm(t));
|
1994-08-01 19:34:53 +08:00
|
|
|
}
|
1994-09-07 22:32:49 +08:00
|
|
|
|
1994-08-23 21:49:37 +08:00
|
|
|
static object *
|
1994-09-07 22:32:49 +08:00
|
|
|
PySignal_Pause(self, args)
|
|
|
|
PyObject *self; /* Not used */
|
|
|
|
PyObject *args;
|
1994-08-23 21:49:37 +08:00
|
|
|
{
|
1994-09-07 22:32:49 +08:00
|
|
|
if (!PyArg_NoArgs(args))
|
1994-08-23 21:49:37 +08:00
|
|
|
return NULL;
|
1994-09-07 22:32:49 +08:00
|
|
|
BGN_SAVE
|
1994-08-23 21:49:37 +08:00
|
|
|
pause();
|
1994-09-07 22:32:49 +08:00
|
|
|
END_SAVE
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-08-23 21:49:37 +08:00
|
|
|
}
|
1994-08-01 19:34:53 +08:00
|
|
|
|
1994-09-07 22:32:49 +08:00
|
|
|
static PyObject *
|
|
|
|
PySignal_Signal(self, args)
|
|
|
|
PyObject *self; /* Not used */
|
|
|
|
PyObject *args;
|
1994-05-11 16:59:13 +08:00
|
|
|
{
|
1994-09-07 22:32:49 +08:00
|
|
|
PyObject *obj;
|
1994-05-11 16:59:13 +08:00
|
|
|
int sig_num;
|
1994-09-07 22:32:49 +08:00
|
|
|
PyObject *old_handler;
|
1994-05-11 16:59:13 +08:00
|
|
|
RETSIGTYPE (*func)();
|
1994-09-07 22:32:49 +08:00
|
|
|
if (!PyArg_Parse(args, "(iO)", &sig_num, &obj))
|
|
|
|
return (PyObject *)NULL;
|
1994-06-23 19:25:45 +08:00
|
|
|
#ifdef WITH_THREAD
|
|
|
|
if (get_thread_ident() != main_thread) {
|
1994-09-07 22:32:49 +08:00
|
|
|
PyErr_SetString(PyExc_ValueError, "signal only works in main thread");
|
|
|
|
return (PyObject *)NULL;
|
1994-06-23 19:25:45 +08:00
|
|
|
}
|
|
|
|
#endif
|
1994-05-11 16:59:13 +08:00
|
|
|
if (sig_num < 1 || sig_num >= NSIG) {
|
1994-09-07 22:32:49 +08:00
|
|
|
PyErr_SetString(PyExc_ValueError, "signal number out of range");
|
|
|
|
return (PyObject *)NULL;
|
1994-05-11 16:59:13 +08:00
|
|
|
}
|
1994-09-07 22:32:49 +08:00
|
|
|
if (obj == PySignal_SignalIgnoreHandler)
|
1994-05-11 16:59:13 +08:00
|
|
|
func = SIG_IGN;
|
1994-09-07 22:32:49 +08:00
|
|
|
else if (obj == PySignal_SignalDefaultHandler)
|
1994-05-11 16:59:13 +08:00
|
|
|
func = SIG_DFL;
|
1994-09-07 22:32:49 +08:00
|
|
|
else if (!PyCFunction_Check(obj) &&
|
|
|
|
!PyFunction_Check(obj) &&
|
|
|
|
!PyMethod_Check(obj)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
1994-05-11 16:59:13 +08:00
|
|
|
"signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object");
|
1994-09-07 22:32:49 +08:00
|
|
|
return (PyObject *)NULL;
|
1994-05-11 16:59:13 +08:00
|
|
|
}
|
|
|
|
else
|
1994-09-07 22:32:49 +08:00
|
|
|
func = PySignal_Handler;
|
1994-06-23 19:25:45 +08:00
|
|
|
if (signal(sig_num, func) == SIG_ERR) {
|
1994-09-07 22:32:49 +08:00
|
|
|
PyErr_SetFromErrno(PyExc_RuntimeError);
|
|
|
|
return (PyObject *)NULL;
|
1994-06-23 19:25:45 +08:00
|
|
|
}
|
1994-09-07 22:32:49 +08: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 16:59:13 +08:00
|
|
|
return old_handler;
|
|
|
|
}
|
|
|
|
|
1994-09-07 22:32:49 +08:00
|
|
|
static PyObject *
|
|
|
|
PySignal_GetSignal(self, args)
|
|
|
|
PyObject *self; /* Not used */
|
|
|
|
PyObject *args;
|
1994-05-11 16:59:13 +08:00
|
|
|
{
|
|
|
|
int sig_num;
|
1994-09-07 22:32:49 +08:00
|
|
|
PyObject *old_handler;
|
|
|
|
if (!PyArg_Parse(args, "i", &sig_num))
|
|
|
|
return (PyObject *)NULL;
|
1994-05-11 16:59:13 +08:00
|
|
|
if (sig_num < 1 || sig_num >= NSIG) {
|
1994-09-07 22:32:49 +08:00
|
|
|
PyErr_SetString(PyExc_ValueError, "signal number out of range");
|
|
|
|
return (PyObject *)NULL;
|
1994-05-11 16:59:13 +08:00
|
|
|
}
|
1994-09-07 22:32:49 +08:00
|
|
|
old_handler = PySignal_SignalHandlerArray[sig_num].func;
|
|
|
|
Py_INCREF(old_handler);
|
1994-05-11 16:59:13 +08:00
|
|
|
return old_handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* List of functions defined in the module */
|
|
|
|
|
1994-09-07 22:32:49 +08:00
|
|
|
static PyMethodDef PySignal_methods[] = {
|
|
|
|
{"alarm", PySignal_Alarm},
|
|
|
|
{"signal", PySignal_Signal},
|
|
|
|
{"getsignal", PySignal_GetSignal},
|
|
|
|
{"pause", PySignal_Pause},
|
1994-05-11 16:59:13 +08:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
initsignal()
|
|
|
|
{
|
1994-09-07 22:32:49 +08:00
|
|
|
PyObject *m, *d, *x;
|
|
|
|
PyObject *b_dict;
|
1994-05-11 16:59:13 +08:00
|
|
|
int i;
|
1994-06-23 19:25:45 +08:00
|
|
|
|
|
|
|
#ifdef WITH_THREAD
|
|
|
|
main_thread = get_thread_ident();
|
|
|
|
main_pid = getpid();
|
|
|
|
#endif
|
|
|
|
|
1994-05-11 16:59:13 +08:00
|
|
|
/* Create the module and add the functions */
|
1994-09-07 22:32:49 +08:00
|
|
|
m = Py_InitModule("signal", PySignal_methods);
|
1994-05-11 16:59:13 +08:00
|
|
|
|
|
|
|
/* Add some symbolic constants to the module */
|
1994-09-07 22:32:49 +08: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));
|
|
|
|
PySignal_DefaultIntHandler = PyCFunction_New("default_int_handler",
|
|
|
|
PySignal_CDefaultIntHandler,
|
|
|
|
(PyObject *)NULL,
|
1994-06-23 19:25:45 +08:00
|
|
|
0);
|
1994-09-07 22:32:49 +08:00
|
|
|
PyDict_SetItemString(d, "default_int_handler", PySignal_DefaultIntHandler);
|
1994-05-11 16:59:13 +08:00
|
|
|
|
1994-09-07 22:32:49 +08:00
|
|
|
PySignal_SignalHandlerArray[0].tripped = 0;
|
1994-05-11 16:59:13 +08:00
|
|
|
for (i = 1; i < NSIG; i++) {
|
1994-05-31 20:51:13 +08:00
|
|
|
RETSIGTYPE (*t)();
|
1994-05-11 16:59:13 +08:00
|
|
|
t = signal(i, SIG_IGN);
|
|
|
|
signal(i, t);
|
1994-09-07 22:32:49 +08:00
|
|
|
PySignal_SignalHandlerArray[i].tripped = 0;
|
1994-05-11 16:59:13 +08:00
|
|
|
if (t == SIG_DFL)
|
1994-09-07 22:32:49 +08:00
|
|
|
PySignal_SignalHandlerArray[i].func = PySignal_SignalDefaultHandler;
|
1994-05-11 16:59:13 +08:00
|
|
|
else if (t == SIG_IGN)
|
1994-09-07 22:32:49 +08:00
|
|
|
PySignal_SignalHandlerArray[i].func = PySignal_SignalIgnoreHandler;
|
1994-05-11 16:59:13 +08:00
|
|
|
else
|
1994-09-07 22:32:49 +08:00
|
|
|
PySignal_SignalHandlerArray[i].func = Py_None; /* None of our business */
|
|
|
|
Py_INCREF(PySignal_SignalHandlerArray[i].func);
|
1994-05-11 16:59:13 +08:00
|
|
|
}
|
1994-09-07 22:32:49 +08:00
|
|
|
if (PySignal_SignalHandlerArray[SIGINT].func == PySignal_SignalDefaultHandler) {
|
1994-05-11 16:59:13 +08:00
|
|
|
/* Install default int handler */
|
1994-09-07 22:32:49 +08:00
|
|
|
Py_DECREF(PySignal_SignalHandlerArray[SIGINT].func);
|
|
|
|
PySignal_SignalHandlerArray[SIGINT].func = PySignal_DefaultIntHandler;
|
|
|
|
Py_INCREF(PySignal_DefaultIntHandler);
|
|
|
|
signal(SIGINT, &PySignal_Handler);
|
1994-05-11 16:59:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SIGHUP
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGHUP);
|
|
|
|
PyDict_SetItemString(d, "SIGHUP", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGINT
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGINT);
|
|
|
|
PyDict_SetItemString(d, "SIGINT", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGQUIT);
|
|
|
|
PyDict_SetItemString(d, "SIGQUIT", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGILL
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGILL);
|
|
|
|
PyDict_SetItemString(d, "SIGILL", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTRAP
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGTRAP);
|
|
|
|
PyDict_SetItemString(d, "SIGTRAP", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIOT
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGIOT);
|
|
|
|
PyDict_SetItemString(d, "SIGIOT", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGABRT
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGABRT);
|
|
|
|
PyDict_SetItemString(d, "SIGABRT", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGEMT
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGEMT);
|
|
|
|
PyDict_SetItemString(d, "SIGEMT", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGFPE);
|
|
|
|
PyDict_SetItemString(d, "SIGFPE", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGKILL
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGKILL);
|
|
|
|
PyDict_SetItemString(d, "SIGKILL", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGBUS
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGBUS);
|
|
|
|
PyDict_SetItemString(d, "SIGBUS", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGSEGV);
|
|
|
|
PyDict_SetItemString(d, "SIGSEGV", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSYS
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGSYS);
|
|
|
|
PyDict_SetItemString(d, "SIGSYS", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGPIPE);
|
|
|
|
PyDict_SetItemString(d, "SIGPIPE", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGALRM
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGALRM);
|
|
|
|
PyDict_SetItemString(d, "SIGALRM", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGTERM);
|
|
|
|
PyDict_SetItemString(d, "SIGTERM", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGUSR1);
|
|
|
|
PyDict_SetItemString(d, "SIGUSR1", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGUSR2);
|
|
|
|
PyDict_SetItemString(d, "SIGUSR2", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCLD
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGCLD);
|
|
|
|
PyDict_SetItemString(d, "SIGCLD", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCHLD
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGCHLD);
|
|
|
|
PyDict_SetItemString(d, "SIGCHLD", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPWR
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGPWR);
|
|
|
|
PyDict_SetItemString(d, "SIGPWR", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIO
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGIO);
|
|
|
|
PyDict_SetItemString(d, "SIGIO", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGURG
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGURG);
|
|
|
|
PyDict_SetItemString(d, "SIGURG", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGWINCH);
|
|
|
|
PyDict_SetItemString(d, "SIGWINCH", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPOLL
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGPOLL);
|
|
|
|
PyDict_SetItemString(d, "SIGPOLL", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSTOP
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGSTOP);
|
|
|
|
PyDict_SetItemString(d, "SIGSTOP", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTSTP
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGTSTP);
|
|
|
|
PyDict_SetItemString(d, "SIGTSTP", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCONT
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGCONT);
|
|
|
|
PyDict_SetItemString(d, "SIGCONT", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTIN
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGTTIN);
|
|
|
|
PyDict_SetItemString(d, "SIGTTIN", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGTTOU
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGTTOU);
|
|
|
|
PyDict_SetItemString(d, "SIGTTOU", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGVTALRM
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGVTALRM);
|
|
|
|
PyDict_SetItemString(d, "SIGVTALRM", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGPROF
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGPROF);
|
|
|
|
PyDict_SetItemString(d, "SIGPROF", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCPU
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGCPU);
|
|
|
|
PyDict_SetItemString(d, "SIGCPU", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGFSZ
|
1994-09-07 22:32:49 +08:00
|
|
|
x = PyInt_FromLong(SIGFSZ);
|
|
|
|
PyDict_SetItemString(d, "SIGFSZ", x);
|
1994-05-11 16:59:13 +08:00
|
|
|
#endif
|
|
|
|
/* Check for errors */
|
1994-09-07 22:32:49 +08:00
|
|
|
if (PyErr_Occurred())
|
|
|
|
Py_FatalError("can't initialize module signal");
|
1994-05-11 16:59:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sigcheck()
|
|
|
|
{
|
|
|
|
int i;
|
1994-09-07 22:32:49 +08:00
|
|
|
PyObject *f;
|
|
|
|
if (!PySignal_IsTripped)
|
1994-05-31 20:51:13 +08:00
|
|
|
return 0;
|
1994-06-23 19:25:45 +08:00
|
|
|
#ifdef WITH_THREAD
|
|
|
|
if (get_thread_ident() != main_thread)
|
|
|
|
return 0;
|
|
|
|
#endif
|
1994-05-31 20:51:13 +08:00
|
|
|
f = getframe();
|
1994-09-07 22:32:49 +08:00
|
|
|
if (f == (PyObject *)NULL)
|
|
|
|
f = Py_None;
|
1994-05-11 16:59:13 +08:00
|
|
|
for (i = 1; i < NSIG; i++) {
|
1994-09-07 22:32:49 +08: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 16:59:13 +08:00
|
|
|
else {
|
1994-09-07 22:32:49 +08:00
|
|
|
result = PyEval_CallObject(PySignal_SignalHandlerArray[i].func,arglist);
|
|
|
|
Py_DECREF(arglist);
|
1994-05-11 16:59:13 +08:00
|
|
|
}
|
1994-09-07 22:32:49 +08:00
|
|
|
if (result == (PyObject *)NULL) {
|
1994-05-11 16:59:13 +08:00
|
|
|
return 1;
|
|
|
|
} else {
|
1994-09-07 22:32:49 +08:00
|
|
|
Py_DECREF(result);
|
1994-05-11 16:59:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-09-07 22:32:49 +08:00
|
|
|
PySignal_IsTripped = 0;
|
1994-05-11 16:59:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Replacement for intrcheck.c functionality */
|
|
|
|
|
|
|
|
void
|
|
|
|
initintr()
|
|
|
|
{
|
|
|
|
initsignal();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
intrcheck()
|
|
|
|
{
|
1994-09-07 22:32:49 +08:00
|
|
|
if (PySignal_SignalHandlerArray[SIGINT].tripped) {
|
1994-06-23 19:25:45 +08:00
|
|
|
#ifdef WITH_THREAD
|
|
|
|
if (get_thread_ident() != main_thread)
|
|
|
|
return 0;
|
|
|
|
#endif
|
1994-09-07 22:32:49 +08:00
|
|
|
PySignal_SignalHandlerArray[SIGINT].tripped = 0;
|
1994-05-31 20:51:13 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
1994-05-11 16:59:13 +08:00
|
|
|
}
|