add mutex around log to db
pull/2077/head
Isaac Connor 2018-03-23 14:34:50 -04:00
parent 2107e5b223
commit 161a0c81f3
2 changed files with 3 additions and 1 deletions

View File

@ -760,7 +760,7 @@ bool Image::ReadRaw( const char *filename ) {
return false;
}
if ( statbuf.st_size != size ) {
if ( (unsigned int)statbuf.st_size != size ) {
fclose(infile);
Error("Raw file size mismatch, expected %d bytes, found %ld", size, statbuf.st_size);
return false;

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];