X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fpython.c;h=70db6b6fc43a8fdd1905c4ba6eca7a64ba95e2ac;hp=64db6985ad4fa301663058c935794c9c73ba8a3a;hb=54619dc85fd308b21ed09a0271e5c7383c7921b9;hpb=7f07c55bac640c7a50d516248a3152235a14af59 diff --git a/src/python.c b/src/python.c index 64db6985..70db6b6f 100644 --- a/src/python.c +++ b/src/python.c @@ -31,7 +31,7 @@ #include "collectd.h" -#include "common.h" +#include "utils/common/common.h" #include "cpython.h" @@ -285,7 +285,7 @@ static void cpy_build_name(char *buf, size_t size, PyObject *callback, PyObject *mod = NULL; if (name != NULL) { - snprintf(buf, size, "python.%s", name); + ssnprintf(buf, size, "python.%s", name); return; } @@ -294,14 +294,14 @@ static void cpy_build_name(char *buf, size_t size, PyObject *callback, module = cpy_unicode_or_bytes_to_string(&mod); if (module != NULL) { - snprintf(buf, size, "python.%s", module); + ssnprintf(buf, size, "python.%s", module); Py_XDECREF(mod); PyErr_Clear(); return; } Py_XDECREF(mod); - snprintf(buf, size, "python.%p", callback); + ssnprintf(buf, size, "python.%p", callback); PyErr_Clear(); } @@ -367,7 +367,7 @@ void cpy_log_exception(const char *context) { continue; if (cpy[strlen(cpy) - 1] == '\n') - cpy[strlen(cpy) - 1] = 0; + cpy[strlen(cpy) - 1] = '\0'; Py_BEGIN_ALLOW_THREADS; ERROR("%s", cpy); @@ -703,8 +703,9 @@ static PyObject *cpy_get_dataset(PyObject *self, PyObject *args) { for (size_t i = 0; i < ds->ds_num; ++i) { tuple = PyTuple_New(4); PyTuple_SET_ITEM(tuple, 0, cpy_string_to_unicode_or_bytes(ds->ds[i].name)); - PyTuple_SET_ITEM(tuple, 1, cpy_string_to_unicode_or_bytes( - DS_TYPE_TO_STRING(ds->ds[i].type))); + PyTuple_SET_ITEM( + tuple, 1, + cpy_string_to_unicode_or_bytes(DS_TYPE_TO_STRING(ds->ds[i].type))); PyTuple_SET_ITEM(tuple, 2, float_or_none(ds->ds[i].min)); PyTuple_SET_ITEM(tuple, 3, float_or_none(ds->ds[i].max)); PyList_SET_ITEM(list, i, tuple); @@ -774,7 +775,8 @@ static PyObject *cpy_register_generic_userdata(void *reg, void *handler, register_function(buf, handler, &(user_data_t){ - .data = c, .free_func = cpy_destroy_user_data, + .data = c, + .free_func = cpy_destroy_user_data, }); ++cpy_num_callbacks; @@ -817,7 +819,8 @@ static PyObject *cpy_register_read(PyObject *self, PyObject *args, /* group = */ "python", buf, cpy_read_callback, DOUBLE_TO_CDTIME_T(interval), &(user_data_t){ - .data = c, .free_func = cpy_destroy_user_data, + .data = c, + .free_func = cpy_destroy_user_data, }); ++cpy_num_callbacks; return cpy_string_to_unicode_or_bytes(buf); @@ -1133,7 +1136,11 @@ static void *cpy_interactive(void *pipefd) { cpy_log_exception("interactive session init"); } cur_sig = PyOS_setsig(SIGINT, python_sigint_handler); +#if PY_VERSION_HEX < 0x03070000 PyOS_AfterFork(); +#else + PyOS_AfterFork_Child(); +#endif PyEval_InitThreads(); close(*(int *)pipefd); PyRun_InteractiveLoop(stdin, ""); @@ -1197,8 +1204,9 @@ static PyObject *cpy_oconfig_to_pyconfig(oconfig_item_t *ci, PyObject *parent) { values = PyTuple_New(ci->values_num); /* New reference. */ for (int i = 0; i < ci->values_num; ++i) { if (ci->values[i].type == OCONFIG_TYPE_STRING) { - PyTuple_SET_ITEM(values, i, cpy_string_to_unicode_or_bytes( - ci->values[i].value.string)); + PyTuple_SET_ITEM( + values, i, + cpy_string_to_unicode_or_bytes(ci->values[i].value.string)); } else if (ci->values[i].type == OCONFIG_TYPE_NUMBER) { PyTuple_SET_ITEM(values, i, PyFloat_FromDouble(ci->values[i].value.number));