add a mutex around logging to db

pull/2077/head
Isaac Connor 2018-03-23 14:18:41 -04:00
parent 01f159c20e
commit fd9c93d3e2
1 changed files with 2 additions and 0 deletions

View File

@ -538,6 +538,7 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co
char sql[ZM_SQL_MED_BUFSIZ];
char escapedString[(strlen(syslogStart)*2)+1];
db_mutex.lock();
mysql_real_escape_string( &dbconn, escapedString, syslogStart, strlen(syslogStart) );
snprintf( sql, sizeof(sql), "insert into Logs ( TimeKey, Component, ServerId, Pid, Level, Code, Message, File, Line ) values ( %ld.%06ld, '%s', %d, %d, %d, '%s', '%s', '%s', %d )", timeVal.tv_sec, timeVal.tv_usec, mId.c_str(), staticConfig.SERVER_ID, tid, level, classString, escapedString, file, line );
@ -547,6 +548,7 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co
Error( "Can't insert log entry: sql(%s) error(%s)", sql, mysql_error( &dbconn ) );
databaseLevel(tempDatabaseLevel);
}
db_mutex.unlock();
}
if ( level <= mSyslogLevel ) {
int priority = smSyslogPriorities[level];