Segmentation fault with libprelude Python bindings and signal handling
The following piece of python code is intended to print "Message received" everytime a new alert is received by the Prelude Manager. It works ok, but sending a signal to it (e.g. SIGINT) in order for it stop leads to a segmentation fault.
Signal handling seems to be responsible for this. Other means to stop the python process (e.g. by sending a special IDMEF message to it) work fine.
import time import prelude import sys def correlator_stop(signum, frame): prelude.prelude_client_destroy(client,prelude.PRELUDE_CLIENT_EXIT_STATUS_SUCCESS ) print "Stop" sys.exit() signal.signal(signal.SIGINT, correlator_stop) prelude.prelude_init(1, [[PythonTest]]) client = prelude.prelude_client_new("PythonTest") prelude.prelude_client_set_required_permission(client, prelude.PRELUDE_CONNECTION_PERMISSION_IDMEF_READ|prelude.PRELUDE_CONNECTION_PERMISSION_IDMEF_WRITE); prelude.prelude_client_start(client); pool = prelude.prelude_client_get_connection_pool(client) while 1 : msg = prelude.prelude_connection_pool_recv(pool, -1) print "Message received"