2011-01-18 09:24:57 +00:00
|
|
|
/*
|
|
|
|
* isys.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007, 2008, 2009 Red Hat, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-01-18 09:24:57 +00:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <execinfo.h>
|
2015-03-23 11:36:12 +00:00
|
|
|
#include <stdlib.h>
|
2015-05-30 11:20:59 +00:00
|
|
|
#include <string.h>
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
static PyObject * doSync(PyObject * s, PyObject * args);
|
2015-05-30 11:20:59 +00:00
|
|
|
static PyObject * doSignalHandlers(PyObject *s, PyObject *args);
|
2014-04-07 12:38:09 +00:00
|
|
|
static PyObject * doSetSystemTime(PyObject *s, PyObject *args);
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
static PyMethodDef isysModuleMethods[] = {
|
2015-05-30 11:20:59 +00:00
|
|
|
{ "sync", (PyCFunction) doSync, METH_NOARGS, NULL},
|
|
|
|
{ "installSyncSignalHandlers", (PyCFunction) doSignalHandlers, METH_NOARGS, NULL},
|
2014-04-07 12:38:09 +00:00
|
|
|
{ "set_system_time", (PyCFunction) doSetSystemTime, METH_VARARGS, NULL},
|
2011-01-18 09:24:57 +00:00
|
|
|
{ NULL, NULL, 0, NULL }
|
|
|
|
} ;
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
/* cppcheck-suppress unusedFunction */
|
2011-01-18 09:24:57 +00:00
|
|
|
void init_isys(void) {
|
2014-04-07 12:38:09 +00:00
|
|
|
Py_InitModule("_isys", isysModuleMethods);
|
2011-01-18 09:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject * doSync(PyObject * s, PyObject * args) {
|
|
|
|
sync();
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
static void sync_signal_handler(int signum) {
|
2011-01-18 09:24:57 +00:00
|
|
|
void *array[20];
|
|
|
|
size_t size;
|
|
|
|
char **strings;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
size = backtrace (array, 20);
|
|
|
|
strings = backtrace_symbols (array, size);
|
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
printf ("Anaconda received signal %d!. Backtrace:\n", signum);
|
2011-01-18 09:24:57 +00:00
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
printf ("%s\n", strings[i]);
|
|
|
|
|
|
|
|
free (strings);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
static PyObject * doSignalHandlers(PyObject *s, PyObject *args) {
|
|
|
|
/* Install a signal handler for all synchronous signals */
|
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
memset(&sa, 0, sizeof(struct sigaction));
|
|
|
|
sa.sa_handler = sync_signal_handler;
|
|
|
|
|
|
|
|
/* Use these flags to ensure that a crash within the signal handler will
|
|
|
|
* just crash anaconda and not get stuck in a loop. RESETHAND resets the
|
|
|
|
* handler to SIG_DFL when the handler is entered, so that further signals
|
|
|
|
* will exit the program, and NODEFER ensures that the signal is not blocked
|
|
|
|
* during the signal handler, so a SIGSEGV triggered by handling a SIGSEGV will
|
|
|
|
* be processed and will use the default handler. The Linux kernel forces
|
|
|
|
* both of these things during a signal handler crash, but this makes it
|
|
|
|
* explicit.
|
|
|
|
*
|
|
|
|
* These flags also mean that a SIGSEGV from a second thread could abort
|
|
|
|
* the processing of a SIGSEGV from a first, but too bad.
|
|
|
|
*/
|
|
|
|
sa.sa_flags = SA_RESETHAND | SA_NODEFER;
|
|
|
|
|
|
|
|
if (sigaction(SIGILL, &sa, NULL) != 0) {
|
|
|
|
return PyErr_SetFromErrno(PyExc_SystemError);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sigaction(SIGFPE, &sa, NULL) != 0) {
|
|
|
|
return PyErr_SetFromErrno(PyExc_SystemError);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sigaction(SIGSEGV, &sa, NULL) != 0) {
|
|
|
|
return PyErr_SetFromErrno(PyExc_SystemError);
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
static PyObject * doSetSystemTime(PyObject *s, PyObject *args) {
|
|
|
|
struct timeval tv;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "L", &(tv.tv_sec)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (settimeofday(&tv, NULL) != 0)
|
2015-05-30 11:20:59 +00:00
|
|
|
return PyErr_SetFromErrno(PyExc_SystemError);
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-18 09:24:57 +00:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4: */
|