Fixed core dumps when closing unintialized mongo or sqlite log instances
Fixed a Host header bug in sinqhttpopt
This commit is contained in:
@ -29,9 +29,11 @@ static void MongoCallback(unsigned int severity, const char *timeStamp,
|
||||
static void MongoClose(void *data)
|
||||
{
|
||||
RemoveLogCallback(MongoCallback);
|
||||
if(collection != NULL){
|
||||
mongoc_collection_destroy (collection);
|
||||
mongoc_client_destroy (client);
|
||||
mongoc_cleanup ();
|
||||
}
|
||||
client = NULL;
|
||||
collection = NULL;
|
||||
}
|
||||
@ -155,7 +157,7 @@ static void QueryCallback(const bson_t *doc, void *userData)
|
||||
bson_iter_find(&iter,"severity");
|
||||
severity = bson_iter_int32(&iter);
|
||||
formatSeverity(severity,sevBuf,sizeof(sevBuf));
|
||||
DynStringConcat(result,(char *)severity);
|
||||
DynStringConcat(result,(char *)sevBuf);
|
||||
DynStringConcatChar(result,' ');
|
||||
bson_iter_find(&iter,"sub");
|
||||
sub = bson_iter_utf8(&iter,&length);
|
||||
@ -182,7 +184,7 @@ static int MongoQueryAction(SConnection * pCon, SicsInterp * pSics,
|
||||
error = sicslogGetError();
|
||||
SCPrintf(pCon,eError,"Error %s querying mongodb", error);
|
||||
} else {
|
||||
SCPureSockWrite(pCon,GetCharArray(result),eValue);
|
||||
SCPureSockWrite(pCon,GetCharArray(result),eLog);
|
||||
}
|
||||
DeleteDynString(result);
|
||||
return 1;
|
||||
|
@ -86,6 +86,7 @@ int sicslogQuery(int argc, char *argv[], ResultCallback_t func, void *userData)
|
||||
/*
|
||||
parse options
|
||||
*/
|
||||
optind = 1;
|
||||
while((c = getopt(argc,argv,"s:l:f:t:i:e:c:")) != -1) {
|
||||
switch (c){
|
||||
case 's':
|
||||
@ -151,7 +152,7 @@ int sicslogQuery(int argc, char *argv[], ResultCallback_t func, void *userData)
|
||||
/*
|
||||
build the query
|
||||
*/
|
||||
snprintf(jsonQuery, sizeof(jsonQuery),"{ \"timestamp\" : {\"$gt\": %ld, \"$lt\": %ld}, \"severity\": {\"$lt\": %d}",
|
||||
snprintf(jsonQuery, sizeof(jsonQuery),"{ \"timestamp\" : {\"$gt\": %ld, \"$lt\": %ld}, \"severity\": {\"$lte\": %d}",
|
||||
from,to,severity-1);
|
||||
if(sub != NULL){
|
||||
snprintf(subQuery,sizeof(subQuery),", \"sub\" : \"%s\"", sub);
|
||||
|
@ -168,7 +168,7 @@ static void sendGet(pHttpProt pHttp, char *path)
|
||||
char buffer[1024];
|
||||
char hostname[256];
|
||||
|
||||
gethostname(hostname,255);
|
||||
ANETinfo(pHttp->sockHandle,hostname,sizeof(hostname));
|
||||
snprintf(buffer,1024,"GET %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\n",
|
||||
path, hostname);
|
||||
ANETwrite(pHttp->sockHandle, buffer,strlen(buffer));
|
||||
@ -180,7 +180,7 @@ static void sendPost(pHttpProt pHttp, char *path, char *data)
|
||||
char buffer[1024];
|
||||
char hostname[256];
|
||||
|
||||
gethostname(hostname,255);
|
||||
ANETinfo(pHttp->sockHandle,hostname,sizeof(hostname));
|
||||
snprintf(buffer,1024,"POST %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\n",
|
||||
path, hostname);
|
||||
ANETwrite(pHttp->sockHandle, buffer,strlen(buffer));
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <sicsutil.h>
|
||||
#include <sics.h>
|
||||
|
||||
static sqlite3 *db;
|
||||
static sqlite3 *db = NULL;
|
||||
static char sqliteFile[1024];
|
||||
static unsigned int lineCount = 0;
|
||||
static unsigned int sqlActive = 0;
|
||||
@ -23,7 +23,7 @@ static void SqlFlush(void)
|
||||
{
|
||||
char *err;
|
||||
|
||||
if(sqlActive == 1){
|
||||
if(sqlActive == 1 && db != NULL){
|
||||
sqlite3_exec(db,"END TRANSACTION",NULL,NULL,&err);
|
||||
lineCount = 0;
|
||||
}
|
||||
@ -66,11 +66,13 @@ static void SqlClose(void *data)
|
||||
{
|
||||
char *err;
|
||||
|
||||
if(sqlActive == 1 && db != NULL){
|
||||
sqlite3_exec(db,"END TRANSACTION",NULL,NULL,&err);
|
||||
sqlite3_close(db);
|
||||
RemoveLogCallback(SqliteCallback);
|
||||
sqlActive = 0;
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------------------*/
|
||||
static int SQLLogConfigAction(SConnection * pCon, SicsInterp * pSics,
|
||||
void *pData, int argc, char *argv[])
|
||||
|
Reference in New Issue
Block a user