INN commit: trunk/innd (python.c)

INN Commit Russ_Allbery at isc.org
Mon Jun 9 18:40:30 UTC 2008


    Date: Monday, June 9, 2008 @ 11:40:30
  Author: iulius
Revision: 7871

Fix a bug when reloading Python filters.
They might not be correctly reloaded.  They must be reimported
before being reloaded.

Modified:
  trunk/innd/python.c

----------+
 python.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Modified: python.c
===================================================================
--- python.c	2008-06-09 18:18:00 UTC (rev 7870)
+++ python.c	2008-06-09 18:40:30 UTC (rev 7871)
@@ -601,20 +601,39 @@
 	Py_XDECREF(result);
     }
 
+    /* We need to reimport the module before reloading it because otherwise,
+     * it might not be taken into account by Python.
+     * See Python API documentation:
+     *     If a module is syntactically correct but its initialization fails,
+     *     the first import statement for it does not bind its name locally,
+     *     but does store a (partially initialized) module object in
+     *     sys.modules.  To reload the module, you must first import it again
+     *     (this will bind the name to the partially initialized module object)
+     *     before you can reload() it.
+     */
+    PYFilterModule = PyImport_ImportModule((char *) INN_PATH_PYTHON_STARTUP_M);
+    if (PYFilterModule == NULL) {
+        syslog(L_ERROR, "failed to reimport external python module");
+    }
+
     if ((newmodule = PyImport_ReloadModule(PYFilterModule)) == NULL) {
 	syslog(L_ERROR, "cant reload python filter module");
 	PYfilter(false);
 	return 0;
     }
+
     Py_DECREF(PYFilterModule);
     PYFilterModule = newmodule;
+
     if (PYFilterObject == NULL) {
 	syslog(L_ERROR, "python reload error, filter object not defined");
 	PYfilter(false);
 	return 0;
     }
+
     PYfilter(true);
     PYdefmethods();
+
     return 1;
 }
 



More information about the inn-committers mailing list