diff --git a/src/python.c b/src/python.c
index a1e6a7e260f6eba8034b23a2bae1da62987e20a5..6be727efb1305601a853bb6c16a4e281dc845ba2 100644 (file)
--- a/src/python.c
+++ b/src/python.c
@@ -259,7 +259,7 @@ static void cpy_build_name(char *buf, size_t size, PyObject *callback, const cha
PyErr_Clear();
}
PyErr_Clear();
}
-static void cpy_log_exception(const char *context) {
+void cpy_log_exception(const char *context) {
int l = 0, i;
const char *typename = NULL, *message = NULL;
PyObject *type, *value, *traceback, *tn, *m, *list;
int l = 0, i;
const char *typename = NULL, *message = NULL;
PyObject *type, *value, *traceback, *tn, *m, *list;
@@ -371,6 +371,7 @@ 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");
}
if (PyErr_Occurred() != NULL) {
cpy_log_exception("value building for write callback");
+ Py_DECREF(list);
CPY_RETURN_FROM_THREADS 0;
}
}
CPY_RETURN_FROM_THREADS 0;
}
}
@@ -400,13 +401,13 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li
} else if (type == MD_TYPE_SIGNED_INT) {
if (meta_data_get_signed_int(meta, table[i], &si))
continue;
} else if (type == MD_TYPE_SIGNED_INT) {
if (meta_data_get_signed_int(meta, table[i], &si))
continue;
- temp = PyLong_FromLongLong(si);
+ temp = PyObject_CallFunctionObjArgs((void *) &SignedType, PyLong_FromLongLong(si), (void *) 0);
PyDict_SetItemString(dict, table[i], temp);
Py_XDECREF(temp);
} else if (type == MD_TYPE_UNSIGNED_INT) {
if (meta_data_get_unsigned_int(meta, table[i], &ui))
continue;
PyDict_SetItemString(dict, table[i], temp);
Py_XDECREF(temp);
} else if (type == MD_TYPE_UNSIGNED_INT) {
if (meta_data_get_unsigned_int(meta, table[i], &ui))
continue;
- temp = PyLong_FromUnsignedLongLong(ui);
+ temp = PyObject_CallFunctionObjArgs((void *) &UnsignedType, PyLong_FromUnsignedLongLong(ui), (void *) 0);
PyDict_SetItemString(dict, table[i], temp);
Py_XDECREF(temp);
} else if (type == MD_TYPE_DOUBLE) {
PyDict_SetItemString(dict, table[i], temp);
Py_XDECREF(temp);
} else if (type == MD_TYPE_DOUBLE) {
@@ -419,16 +420,15 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li
if (meta_data_get_boolean(meta, table[i], &b))
continue;
if (b)
if (meta_data_get_boolean(meta, table[i], &b))
continue;
if (b)
- temp = Py_True;
+ PyDict_SetItemString(dict, table[i], Py_True);
else
else
- temp = Py_False;
- PyDict_SetItemString(dict, table[i], temp);
+ PyDict_SetItemString(dict, table[i], Py_False);
}
free(table[i]);
}
free(table);
}
}
free(table[i]);
}
free(table);
}
- v = PyObject_New(Values, (void *) &ValuesType);
+ v = PyObject_New(Values, (void *) &ValuesType); /* New reference. */
sstrncpy(v->data.host, value_list->host, sizeof(v->data.host));
sstrncpy(v->data.type, value_list->type, sizeof(v->data.type));
sstrncpy(v->data.type_instance, value_list->type_instance, sizeof(v->data.type_instance));
sstrncpy(v->data.host, value_list->host, sizeof(v->data.host));
sstrncpy(v->data.type, value_list->type, sizeof(v->data.type));
sstrncpy(v->data.type_instance, value_list->type_instance, sizeof(v->data.type_instance));
@@ -439,6 +439,7 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li
v->values = list;
v->meta = dict;
ret = PyObject_CallFunctionObjArgs(c->callback, v, c->data, (void *) 0); /* New reference. */
v->values = list;
v->meta = dict;
ret = PyObject_CallFunctionObjArgs(c->callback, v, c->data, (void *) 0); /* New reference. */
+ Py_XDECREF(v);
if (ret == NULL) {
cpy_log_exception("write callback");
} else {
if (ret == NULL) {
cpy_log_exception("write callback");
} else {
@@ -454,7 +455,7 @@ static int cpy_notification_callback(const notification_t *notification, user_da
Notification *n;
CPY_LOCK_THREADS
Notification *n;
CPY_LOCK_THREADS
- n = PyObject_New(Notification, (void *) &NotificationType);
+ n = PyObject_New(Notification, (void *) &NotificationType); /* New reference. */
sstrncpy(n->data.host, notification->host, sizeof(n->data.host));
sstrncpy(n->data.type, notification->type, sizeof(n->data.type));
sstrncpy(n->data.type_instance, notification->type_instance, sizeof(n->data.type_instance));
sstrncpy(n->data.host, notification->host, sizeof(n->data.host));
sstrncpy(n->data.type, notification->type, sizeof(n->data.type));
sstrncpy(n->data.type_instance, notification->type_instance, sizeof(n->data.type_instance));
@@ -464,6 +465,7 @@ static int cpy_notification_callback(const notification_t *notification, user_da
sstrncpy(n->message, notification->message, sizeof(n->message));
n->severity = notification->severity;
ret = PyObject_CallFunctionObjArgs(c->callback, n, c->data, (void *) 0); /* New reference. */
sstrncpy(n->message, notification->message, sizeof(n->message));
n->severity = notification->severity;
ret = PyObject_CallFunctionObjArgs(c->callback, n, c->data, (void *) 0); /* New reference. */
+ Py_XDECREF(n);
if (ret == NULL) {
cpy_log_exception("notification callback");
} else {
if (ret == NULL) {
cpy_log_exception("notification callback");
} else {
@@ -623,7 +625,8 @@ static PyObject *cpy_register_read(PyObject *self, PyObject *args, PyObject *kwd
user_data->data = c;
ts.tv_sec = interval;
ts.tv_nsec = (interval - ts.tv_sec) * 1000000000;
user_data->data = c;
ts.tv_sec = interval;
ts.tv_nsec = (interval - ts.tv_sec) * 1000000000;
- plugin_register_complex_read(buf, cpy_read_callback, &ts, user_data);
+ plugin_register_complex_read(/* group = */ NULL, buf,
+ cpy_read_callback, &ts, user_data);
return cpy_string_to_unicode_or_bytes(buf);
}
return cpy_string_to_unicode_or_bytes(buf);
}
static pthread_t thread;
sigset_t sigset;
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) {
PyEval_InitThreads();
/* Now it's finally OK to use python threads. */
for (c = cpy_init_callbacks; c; c = c->next) {
PyType_Ready(&ValuesType);
NotificationType.tp_base = &PluginDataType;
PyType_Ready(&NotificationType);
PyType_Ready(&ValuesType);
NotificationType.tp_base = &PluginDataType;
PyType_Ready(&NotificationType);
+ SignedType.tp_base = &PyLong_Type;
+ PyType_Ready(&SignedType);
+ UnsignedType.tp_base = &PyLong_Type;
+ PyType_Ready(&UnsignedType);
sys = PyImport_ImportModule("sys"); /* New reference. */
if (sys == NULL) {
cpy_log_exception("python initialization");
sys = PyImport_ImportModule("sys"); /* New reference. */
if (sys == NULL) {
cpy_log_exception("python initialization");
PyModule_AddObject(module, "Config", (void *) &ConfigType); /* Steals a reference. */
PyModule_AddObject(module, "Values", (void *) &ValuesType); /* Steals a reference. */
PyModule_AddObject(module, "Notification", (void *) &NotificationType); /* Steals a reference. */
PyModule_AddObject(module, "Config", (void *) &ConfigType); /* Steals a reference. */
PyModule_AddObject(module, "Values", (void *) &ValuesType); /* Steals a reference. */
PyModule_AddObject(module, "Notification", (void *) &NotificationType); /* Steals a reference. */
+ PyModule_AddObject(module, "Signed", (void *) &SignedType); /* Steals a reference. */
+ PyModule_AddObject(module, "Unsigned", (void *) &UnsignedType); /* Steals a reference. */
PyModule_AddIntConstant(module, "LOG_DEBUG", LOG_DEBUG);
PyModule_AddIntConstant(module, "LOG_INFO", LOG_INFO);
PyModule_AddIntConstant(module, "LOG_NOTICE", LOG_NOTICE);
PyModule_AddIntConstant(module, "LOG_DEBUG", LOG_DEBUG);
PyModule_AddIntConstant(module, "LOG_INFO", LOG_INFO);
PyModule_AddIntConstant(module, "LOG_NOTICE", LOG_NOTICE);