Fixing some thread join bugs and a bug in db escape

This commit is contained in:
BlackLight 2010-11-23 02:31:55 +01:00
parent 44c805e829
commit cbee4cb9fa
4 changed files with 39 additions and 0 deletions

View file

@ -96,7 +96,14 @@ AI_alerts_pool_thread ( void *arg )
continue;
if ( pthread_create ( &serializer_thread, NULL, AI_serializer_thread, NULL ) != 0 )
{
AI_fatal_err ( "Failed to create the alerts' serializer thread", __FILE__, __LINE__ );
}
/* if ( pthread_join ( serializer_thread, NULL ) != 0 ) */
/* { */
/* AI_fatal_err ( "Could not join the alerts' serializer thread", __FILE__, __LINE__ ); */
/* } */
}
pthread_exit ((void*) 0);
@ -163,7 +170,9 @@ AI_file_alertparser_thread ( void* arg )
/* Initialize the thread for managing the serialization of alerts' pool */
if ( pthread_create ( &alerts_pool_thread, NULL, AI_alerts_pool_thread, NULL ) != 0 )
{
AI_fatal_err ( "Failed to create the alerts' pool management thread", __FILE__, __LINE__ );
}
while ( 1 )
{
@ -285,12 +294,21 @@ AI_file_alertparser_thread ( void* arg )
}
if ( pthread_create ( &serializer_thread, NULL, AI_serializer_thread, alert ) != 0 )
{
AI_fatal_err ( "Failed to create the alerts' serializer thread", __FILE__, __LINE__ );
}
if ( pthread_join ( serializer_thread, NULL ) != 0 )
{
AI_fatal_err ( "Failed to join the alerts' serializer thread", __FILE__, __LINE__ );
}
if ( config->outdbtype != outdb_none )
{
if ( pthread_create ( &db_thread, NULL, AI_store_alert_to_db_thread, alert ) != 0 )
{
AI_fatal_err ( "Failed to create the alert to db storing thread", __FILE__, __LINE__ );
}
}
in_alert = false;

4
db.c
View file

@ -71,7 +71,9 @@ AI_db_alertparser_thread ( void *arg )
/* Initialize the thread for managing the serialization of alerts' pool */
if ( pthread_create ( &alerts_pool_thread, NULL, AI_alerts_pool_thread, NULL ) != 0 )
{
AI_fatal_err ( "Failed to create the alerts' pool management thread", __FILE__, __LINE__ );
}
while ( 1 )
{
@ -221,7 +223,9 @@ AI_db_alertparser_thread ( void *arg )
latest_time = time ( NULL );
if ( pthread_create ( &serializer_thread, NULL, AI_serializer_thread, alert ) != 0 )
{
AI_fatal_err ( "Failed to create the alerts' serializer thread", __FILE__, __LINE__ );
}
}
DB_close();

12
mysql.c
View file

@ -130,6 +130,12 @@ mysql_do_query ( const char *query )
unsigned long
mysql_do_escape_string ( char **to, const char *from, unsigned long length )
{
if ( !from )
return 0;
if ( strlen ( from ) == 0 )
return 0;
return mysql_real_escape_string ( db, *to, from, length );
}
@ -174,6 +180,12 @@ mysql_do_out_query ( const char *query )
unsigned long
mysql_do_out_escape_string ( char **to, const char *from, unsigned long length )
{
if ( !from )
return 0;
if ( strlen ( from ) == 0 )
return 0;
return mysql_real_escape_string ( outdb, *to, from, length );
}

View file

@ -117,6 +117,7 @@ AI_store_alert_to_db_thread ( void *arg )
{
pthread_mutex_unlock ( &outdb_mutex );
pthread_exit ((void*) 0);
return (void*) 0;
}
latest_ip_hdr_id = strtoul ( row[0], NULL, 10 );
@ -147,12 +148,14 @@ AI_store_alert_to_db_thread ( void *arg )
_dpd.logMsg ( "AIPreproc: Warning: error in executing query: '%s'\n", query );
pthread_mutex_unlock ( &outdb_mutex );
pthread_exit ((void*) 0);
return (void*) 0;
}
if ( !( row = (DB_row) DB_fetch_row ( res )))
{
pthread_mutex_unlock ( &outdb_mutex );
pthread_exit ((void*) 0);
return (void*) 0;
}
latest_tcp_hdr_id = strtoul ( row[0], NULL, 10 );
@ -213,12 +216,14 @@ AI_store_alert_to_db_thread ( void *arg )
_dpd.logMsg ( "AIPreproc: Warning: error in executing query: '%s'\n", query );
pthread_mutex_unlock ( &outdb_mutex );
pthread_exit ((void*) 0);
return (void*) 0;
}
if ( !( row = (DB_row) DB_fetch_row ( res )))
{
pthread_mutex_unlock ( &outdb_mutex );
pthread_exit ((void*) 0);
return (void*) 0;
}
latest_alert_id = strtoul ( row[0], NULL, 10 );