From 17b615eeb63e76bf0ee0f5fe26ff9401892b9265 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 20 Jul 2007 10:41:15 +0300 Subject: Add python methods for checking pending signals from rpmsqCaught. - a thin wrapper for rpmdbCheckSignals() from rpm5.org / Jeff Johnson - a function taking a list of signals to check and returning list caught signals (python doesn't know about signal sets so rpmsqCaught needs wrapping) --- python/rpmmodule.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/python/rpmmodule.c b/python/rpmmodule.c index 624dc2cf9..85b6db257 100644 --- a/python/rpmmodule.c +++ b/python/rpmmodule.c @@ -7,6 +7,7 @@ #include #include /* XXX for rpmCheckSig */ #include +#include #include "legacy.h" #include "misc.h" @@ -57,6 +58,50 @@ static PyObject * archScore(PyObject * self, PyObject * args, PyObject * kwds) return Py_BuildValue("i", score); } +/** + * */ +static PyObject * signalsCaught(PyObject * self, PyObject * check) +{ + PyObject *caught, *o; + Py_ssize_t llen; + int signum, i; + sigset_t newMask, oldMask; + + if (!PyList_Check(check)) { + PyErr_SetString(PyExc_TypeError, "list expected"); + return NULL; + } + + llen = PyList_Size(check); + caught = PyList_New(0); + + /* block signals while checking for them */ + (void) sigfillset(&newMask); + (void) sigprocmask(SIG_BLOCK, &newMask, &oldMask); + + for (i = 0; i < llen; i++) { + o = PyList_GetItem(check, i); + signum = PyInt_AsLong(o); + if (sigismember(&rpmsqCaught, signum)) { + PyList_Append(caught, o); + } + } + (void) sigprocmask(SIG_SETMASK, &oldMask, NULL); + + return caught; +} + +/** + * */ +static PyObject * checkSignals(PyObject * self, PyObject * args) +{ + if (!PyArg_ParseTuple(args, ":checkSignals")) return NULL; + rpmdbCheckSignals(); + Py_INCREF(Py_None); + return Py_None; +} + + /** */ static PyObject * setLogFile (PyObject * self, PyObject * args, PyObject *kwds) @@ -146,6 +191,11 @@ static PyMethodDef rpmModuleMethods[] = { { "archscore", (PyCFunction) archScore, METH_VARARGS|METH_KEYWORDS, NULL }, + { "signalsCaught", (PyCFunction) signalsCaught, METH_O, + NULL }, + { "checkSignals", (PyCFunction) checkSignals, METH_VARARGS, + NULL }, + { "headerLoad", (PyCFunction) hdrLoad, METH_VARARGS|METH_KEYWORDS, NULL }, { "mergeHeaderListFromFD", (PyCFunction) rpmMergeHeadersFromFD, METH_VARARGS|METH_KEYWORDS, -- cgit v1.2.3