Add python methods for checking pending signals from rpmsqCaught.
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 20 Jul 2007 07:41:15 +0000 (10:41 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 20 Jul 2007 07:41:15 +0000 (10:41 +0300)
- 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)
(transplanted from c0237c16e2e35d108db2bbb2bf3c18cd95db9ad7)

python/rpmmodule.c

index 41e14c7..307ec99 100644 (file)
@@ -7,6 +7,7 @@
 #include <rpmio_internal.h>
 #include <rpmcli.h>    /* XXX for rpmCheckSig */
 #include <rpmdb.h>
+#include <rpmsq.h>
 
 #include "legacy.h"
 #include "misc.h"
@@ -58,6 +59,50 @@ static PyObject * archScore(PyObject * self, PyObject * args, PyObject * kwds)
 }
 
 /**
+ *  */
+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 },
     { "rhnLoad", (PyCFunction) rhnLoad, METH_VARARGS|METH_KEYWORDS,