X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fpython.c;h=16de81d414b1b8ca55867f99fb3b0f77e02e361c;hb=b26f349d681c60cdad4c4dbde0ea6adfbe7d741a;hp=d750d95b503e7fbbff9e78c375eeef3e809e79be;hpb=105c64c6f20807fa105b6aa350cc79c0d3a38488;p=collectd.git diff --git a/src/python.c b/src/python.c index d750d95b..16de81d4 100644 --- a/src/python.c +++ b/src/python.c @@ -368,14 +368,17 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li } if (PyErr_Occurred() != NULL) { cpy_log_exception("value building for write callback"); + Py_DECREF(list); CPY_RETURN_FROM_THREADS 0; } } - v = PyObject_CallFunction((void *) &ValuesType, "sOssssdi", value_list->type, list, - value_list->plugin_instance, value_list->type_instance, value_list->plugin, - value_list->host, (double) value_list->time, value_list->interval); + v = PyObject_CallFunction((void *) &ValuesType, "sOssssdi", value_list->type, + list, value_list->plugin_instance, value_list->type_instance, + value_list->plugin, value_list->host, (double) value_list->time, + value_list->interval); /* New reference. */ Py_DECREF(list); ret = PyObject_CallFunctionObjArgs(c->callback, v, c->data, (void *) 0); /* New reference. */ + Py_XDECREF(v); if (ret == NULL) { cpy_log_exception("write callback"); } else { @@ -392,8 +395,9 @@ static int cpy_notification_callback(const notification_t *notification, user_da CPY_LOCK_THREADS n = PyObject_CallFunction((void *) &NotificationType, "ssssssdi", notification->type, notification->message, notification->plugin_instance, notification->type_instance, notification->plugin, - notification->host, (double) notification->time, notification->severity); + notification->host, (double) notification->time, notification->severity); /* New reference. */ ret = PyObject_CallFunctionObjArgs(c->callback, n, c->data, (void *) 0); /* New reference. */ + Py_XDECREF(n); if (ret == NULL) { cpy_log_exception("notification callback"); } else { @@ -828,6 +832,11 @@ static int cpy_init(void) { static pthread_t thread; sigset_t sigset; + if (!Py_IsInitialized()) { + WARNING("python: Plugin loaded but not configured."); + plugin_unregister_shutdown("python"); + return 0; + } PyEval_InitThreads(); /* Now it's finally OK to use python threads. */ for (c = cpy_init_callbacks; c; c = c->next) { @@ -883,6 +892,7 @@ static PyObject *cpy_oconfig_to_pyconfig(oconfig_item_t *ci, PyObject *parent) { static int cpy_config(oconfig_item_t *ci) { int i; + char *argv = ""; PyObject *sys, *tb; PyObject *sys_path; PyObject *module; @@ -912,6 +922,9 @@ static int cpy_config(oconfig_item_t *ci) { cpy_log_exception("python initialization"); return 1; } + PySys_SetArgv(1, &argv); + PyList_SetSlice(sys_path, 0, 1, NULL); + module = Py_InitModule("collectd", cpy_methods); /* Borrowed reference. */ PyModule_AddObject(module, "Config", (void *) &ConfigType); /* Steals a reference. */ PyModule_AddObject(module, "Values", (void *) &ValuesType); /* Steals a reference. */