Force rpmdb clean termination on exit from python.
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 20 Jul 2007 08:23:11 +0000 (11:23 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 20 Jul 2007 08:23:11 +0000 (11:23 +0300)
Python process tracebacking with active iterators can and will otherwise leave
stale locks around (as is presumably the reason for rhbz#235389 and various
other locking issues)
(transplanted from e9ced408b17fb48b660b309f3a7b4c67586421cd)

python/rpmmodule.c

index 307ec99..5b4c6d3 100644 (file)
@@ -229,6 +229,16 @@ static PyMethodDef rpmModuleMethods[] = {
     { NULL }
 } ;
 
+/*
+* Force clean up of open iterators and dbs on exit.
+* This ends up calling exit() while we're already exiting but exit
+* handlers will only get called once so it wont loop.
+*/
+static void rpm_exithook(void)
+{
+   rpmdbCheckTerminate(1);
+}
+
 /**
  */
 static char rpm__doc__[] =
@@ -267,6 +277,13 @@ void init_rpm(void)
     if (m == NULL)
        return;
 
+    /* 
+     * treat error to register rpm cleanup hook as fatal, tracebacks
+     * can and will leave stale locks around if we can't clean up
+     */
+    if (Py_AtExit(rpm_exithook) == -1)
+       return;
+
     rpmReadConfigFiles(NULL, NULL);
 
     d = PyModule_GetDict(m);