35
35
36
36
#include "cpython.h"
37
37
38
+ #ifndef PLUGIN_NAME
39
+ #define PLUGIN_NAME "python"
40
+ #endif
41
+
38
42
typedef struct cpy_callback_s {
39
43
char * name ;
40
44
PyObject * callback ;
@@ -816,7 +820,7 @@ static PyObject *cpy_register_read(PyObject *self, PyObject *args,
816
820
c -> next = NULL ;
817
821
818
822
plugin_register_complex_read (
819
- /* group = */ "python" , buf , cpy_read_callback ,
823
+ /* group = */ PLUGIN_NAME , buf , cpy_read_callback ,
820
824
DOUBLE_TO_CDTIME_T (interval ),
821
825
& (user_data_t ){
822
826
.data = c ,
@@ -1153,7 +1157,7 @@ static void *cpy_interactive(void *pipefd) {
1153
1157
PyOS_setsig (SIGINT , cur_sig );
1154
1158
PyErr_Print ();
1155
1159
state = PyEval_SaveThread ();
1156
- NOTICE ("python : Interactive interpreter exited, stopping collectd ..." );
1160
+ NOTICE (PLUGIN_NAME " : Interactive interpreter exited, stopping collectd ..." );
1157
1161
pthread_kill (main_thread , SIGINT );
1158
1162
return NULL ;
1159
1163
}
@@ -1165,20 +1169,20 @@ static int cpy_init(void) {
1165
1169
static pthread_t thread ;
1166
1170
1167
1171
if (!Py_IsInitialized ()) {
1168
- WARNING ("python : Plugin loaded but not configured." );
1169
- plugin_unregister_shutdown ("python" );
1172
+ WARNING (PLUGIN_NAME " : Plugin loaded but not configured." );
1173
+ plugin_unregister_shutdown (PLUGIN_NAME );
1170
1174
Py_Finalize ();
1171
1175
return 0 ;
1172
1176
}
1173
1177
main_thread = pthread_self ();
1174
1178
if (do_interactive ) {
1175
1179
if (pipe (pipefd )) {
1176
- ERROR ("python : Unable to create pipe." );
1180
+ ERROR (PLUGIN_NAME " : Unable to create pipe." );
1177
1181
return 1 ;
1178
1182
}
1179
1183
if (plugin_thread_create (& thread , NULL , cpy_interactive , pipefd + 1 ,
1180
- "python interpreter" )) {
1181
- ERROR ("python : Error creating thread for interactive interpreter." );
1184
+ PLUGIN_NAME " interpreter" )) {
1185
+ ERROR (PLUGIN_NAME " : Error creating thread for interactive interpreter." );
1182
1186
}
1183
1187
if (read (pipefd [0 ], & buf , 1 ))
1184
1188
;
@@ -1290,13 +1294,13 @@ static int cpy_init_python(void) {
1290
1294
CollectdError = PyErr_NewException ("collectd.CollectdError" , NULL , errordict );
1291
1295
sys = PyImport_ImportModule ("sys" ); /* New reference. */
1292
1296
if (sys == NULL ) {
1293
- cpy_log_exception ("python initialization" );
1297
+ cpy_log_exception (PLUGIN_NAME " initialization" );
1294
1298
return 1 ;
1295
1299
}
1296
1300
sys_path = PyObject_GetAttrString (sys , "path" ); /* New reference. */
1297
1301
Py_DECREF (sys );
1298
1302
if (sys_path == NULL ) {
1299
- cpy_log_exception ("python initialization" );
1303
+ cpy_log_exception (PLUGIN_NAME " initialization" );
1300
1304
return 1 ;
1301
1305
}
1302
1306
PySys_SetArgv (1 , & argv );
@@ -1368,8 +1372,8 @@ static int cpy_config(oconfig_item_t *ci) {
1368
1372
continue ;
1369
1373
}
1370
1374
#ifdef IS_PY3K
1371
- ERROR ("python : \"Encoding\" was used in the config file but Python3 was "
1372
- "used, which does not support changing encodings" );
1375
+ ERROR (PLUGIN_NAME " : \"Encoding\" was used in the config file but "
1376
+ "Python3 was used, which does not support changing encodings" );
1373
1377
status = 1 ;
1374
1378
sfree (encoding );
1375
1379
continue ;
@@ -1396,15 +1400,15 @@ static int cpy_config(oconfig_item_t *ci) {
1396
1400
continue ;
1397
1401
tb = PyImport_ImportModule ("traceback" ); /* New reference. */
1398
1402
if (tb == NULL ) {
1399
- cpy_log_exception ("python initialization" );
1403
+ cpy_log_exception (PLUGIN_NAME " initialization" );
1400
1404
status = 1 ;
1401
1405
continue ;
1402
1406
}
1403
1407
cpy_format_exception =
1404
1408
PyObject_GetAttrString (tb , "format_exception" ); /* New reference. */
1405
1409
Py_DECREF (tb );
1406
1410
if (cpy_format_exception == NULL ) {
1407
- cpy_log_exception ("python initialization" );
1411
+ cpy_log_exception (PLUGIN_NAME " initialization" );
1408
1412
status = 1 ;
1409
1413
}
1410
1414
} else if (strcasecmp (item -> key , "ModulePath" ) == 0 ) {
@@ -1417,19 +1421,19 @@ static int cpy_config(oconfig_item_t *ci) {
1417
1421
}
1418
1422
dir_object = cpy_string_to_unicode_or_bytes (dir ); /* New reference. */
1419
1423
if (dir_object == NULL ) {
1420
- ERROR ("python plugin: Unable to convert \"%s\" to "
1424
+ ERROR (PLUGIN_NAME " plugin: Unable to convert \"%s\" to "
1421
1425
"a python object." ,
1422
1426
dir );
1423
1427
free (dir );
1424
- cpy_log_exception ("python initialization" );
1428
+ cpy_log_exception (PLUGIN_NAME " initialization" );
1425
1429
status = 1 ;
1426
1430
continue ;
1427
1431
}
1428
1432
if (PyList_Insert (sys_path , 0 , dir_object ) != 0 ) {
1429
- ERROR ("python plugin: Unable to prepend \"%s\" to "
1433
+ ERROR (PLUGIN_NAME " plugin: Unable to prepend \"%s\" to "
1430
1434
"python module path." ,
1431
1435
dir );
1432
- cpy_log_exception ("python initialization" );
1436
+ cpy_log_exception (PLUGIN_NAME " initialization" );
1433
1437
status = 1 ;
1434
1438
}
1435
1439
Py_DECREF (dir_object );
@@ -1444,7 +1448,8 @@ static int cpy_config(oconfig_item_t *ci) {
1444
1448
}
1445
1449
module = PyImport_ImportModule (module_name ); /* New reference. */
1446
1450
if (module == NULL ) {
1447
- ERROR ("python plugin: Error importing module \"%s\"." , module_name );
1451
+ ERROR (PLUGIN_NAME " plugin: Error importing module \"%s\"." ,
1452
+ module_name );
1448
1453
cpy_log_exception ("importing module" );
1449
1454
status = 1 ;
1450
1455
}
@@ -1464,8 +1469,8 @@ static int cpy_config(oconfig_item_t *ci) {
1464
1469
break ;
1465
1470
}
1466
1471
if (c == NULL ) {
1467
- WARNING ("python plugin: Found a configuration for the \"%s\" plugin, "
1468
- "but the plugin isn't loaded or didn't register "
1472
+ WARNING (PLUGIN_NAME " plugin: Found a configuration for the \"%s\" "
1473
+ "plugin, but the plugin isn't loaded or didn't register "
1469
1474
"a configuration callback." ,
1470
1475
name );
1471
1476
free (name );
@@ -1486,15 +1491,15 @@ static int cpy_config(oconfig_item_t *ci) {
1486
1491
} else
1487
1492
Py_DECREF (ret );
1488
1493
} else {
1489
- ERROR ("python plugin: Unknown config key \"%s\"." , item -> key );
1494
+ ERROR (PLUGIN_NAME " plugin: Unknown config key \"%s\"." , item -> key );
1490
1495
status = 1 ;
1491
1496
}
1492
1497
}
1493
1498
return status ;
1494
1499
}
1495
1500
1496
1501
void module_register (void ) {
1497
- plugin_register_complex_config ("python" , cpy_config );
1498
- plugin_register_init ("python" , cpy_init );
1499
- plugin_register_shutdown ("python" , cpy_shutdown );
1502
+ plugin_register_complex_config (PLUGIN_NAME , cpy_config );
1503
+ plugin_register_init (PLUGIN_NAME , cpy_init );
1504
+ plugin_register_shutdown (PLUGIN_NAME , cpy_shutdown );
1500
1505
}
0 commit comments