You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-08 14:22:09 +03:00
MCOL-892 - changed from using the flock command
This commit is contained in:
2
VERSION
2
VERSION
@@ -1,4 +1,4 @@
|
|||||||
COLUMNSTORE_VERSION_MAJOR=1
|
COLUMNSTORE_VERSION_MAJOR=1
|
||||||
COLUMNSTORE_VERSION_MINOR=0
|
COLUMNSTORE_VERSION_MINOR=0
|
||||||
COLUMNSTORE_VERSION_PATCH=11
|
COLUMNSTORE_VERSION_PATCH=11
|
||||||
COLUMNSTORE_VERSION_RELEASE=1
|
COLUMNSTORE_VERSION_RELEASE=2
|
||||||
|
@@ -2523,6 +2523,9 @@ namespace oam
|
|||||||
string Section = "AlarmConfig";
|
string Section = "AlarmConfig";
|
||||||
int returnValue;
|
int returnValue;
|
||||||
|
|
||||||
|
struct flock fl;
|
||||||
|
int fd;
|
||||||
|
|
||||||
// validate Alarm ID
|
// validate Alarm ID
|
||||||
|
|
||||||
if( alarmid > MAX_ALARM_ID )
|
if( alarmid > MAX_ALARM_ID )
|
||||||
@@ -2543,41 +2546,55 @@ namespace oam
|
|||||||
exceptionControl("setAlarmConfig", API_READONLY_PARAMETER);
|
exceptionControl("setAlarmConfig", API_READONLY_PARAMETER);
|
||||||
|
|
||||||
string fileName = AlarmConfigFile;
|
string fileName = AlarmConfigFile;
|
||||||
|
|
||||||
int fd = open(fileName.c_str(), O_RDWR|O_CREAT, 0644);
|
|
||||||
|
|
||||||
// Aquire an exclusive lock
|
memset(&fl, 0, sizeof(fl));
|
||||||
if (flock(fd,LOCK_EX) == -1) {
|
fl.l_type = F_RDLCK; // read lock
|
||||||
throw runtime_error ("Lock file error: " + fileName);
|
fl.l_whence = SEEK_SET;
|
||||||
}
|
fl.l_start = 0;
|
||||||
|
fl.l_len = 0; //lock whole file
|
||||||
|
|
||||||
// write parameter to disk
|
// open config file
|
||||||
|
if ((fd = open(fileName.c_str(), O_RDWR)) >= 0)
|
||||||
Config* alaConfig = Config::makeConfig(AlarmConfigFile.c_str());
|
{ // lock file
|
||||||
alaConfig->setConfig(Section, name, value);
|
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
alaConfig->write();
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
// Release lock
|
|
||||||
if (flock(fd,LOCK_UN)==-1)
|
|
||||||
{
|
{
|
||||||
throw runtime_error ("Release lock file error: " + fileName);
|
ostringstream oss;
|
||||||
|
oss << "Oam::setAlarmConfig: error locking file " <<
|
||||||
|
fileName <<
|
||||||
|
": " <<
|
||||||
|
strerror(errno) <<
|
||||||
|
", proceding anyway.";
|
||||||
|
cerr << oss.str() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// write parameter to disk
|
||||||
|
|
||||||
exceptionControl("setAlarmConfig", API_FAILURE);
|
Config* alaConfig = Config::makeConfig(AlarmConfigFile.c_str());
|
||||||
}
|
alaConfig->setConfig(Section, name, value);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
alaConfig->write();
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{}
|
||||||
|
|
||||||
// Release lock
|
fl.l_type = F_UNLCK; //unlock
|
||||||
if (flock(fd,LOCK_UN)==-1)
|
fcntl(fd, F_SETLK, &fl);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
throw runtime_error ("Release lock file error: " + fileName);
|
ostringstream oss;
|
||||||
|
oss << "Oam::setAlarmConfig: error opening file " <<
|
||||||
|
fileName <<
|
||||||
|
": " <<
|
||||||
|
strerror(errno);
|
||||||
|
throw runtime_error(oss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
|
@@ -97,6 +97,9 @@ ALARMManager::~ALARMManager()
|
|||||||
*****************************************************************************************/
|
*****************************************************************************************/
|
||||||
void rewriteActiveLog (const AlarmList& alarmList)
|
void rewriteActiveLog (const AlarmList& alarmList)
|
||||||
{
|
{
|
||||||
|
struct flock fl;
|
||||||
|
int fd;
|
||||||
|
|
||||||
if (ALARM_DEBUG) {
|
if (ALARM_DEBUG) {
|
||||||
LoggingID lid(11);
|
LoggingID lid(11);
|
||||||
MessageLog ml(lid);
|
MessageLog ml(lid);
|
||||||
@@ -110,30 +113,52 @@ void rewriteActiveLog (const AlarmList& alarmList)
|
|||||||
// delete the old file
|
// delete the old file
|
||||||
unlink (ACTIVE_ALARM_FILE.c_str());
|
unlink (ACTIVE_ALARM_FILE.c_str());
|
||||||
|
|
||||||
|
memset(&fl, 0, sizeof(fl));
|
||||||
|
fl.l_type = F_RDLCK; // read lock
|
||||||
|
fl.l_whence = SEEK_SET;
|
||||||
|
fl.l_start = 0;
|
||||||
|
fl.l_len = 0; //lock whole file
|
||||||
|
|
||||||
// create new file
|
// create new file
|
||||||
int fd = open(ACTIVE_ALARM_FILE.c_str(), O_RDWR|O_CREAT, 0644);
|
if ((fd = open(ACTIVE_ALARM_FILE.c_str(), O_RDWR|O_CREAT, 0664)) >= 0)
|
||||||
|
{ // lock file
|
||||||
// Aquire an exclusive lock
|
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||||
if (flock(fd,LOCK_EX) == -1) {
|
{
|
||||||
throw runtime_error ("Lock active alarm log file error");
|
ostringstream oss;
|
||||||
}
|
oss << "rewriteActiveLog: error locking file " <<
|
||||||
|
ACTIVE_ALARM_FILE <<
|
||||||
|
": " <<
|
||||||
|
strerror(errno) <<
|
||||||
|
", proceding anyway.";
|
||||||
|
cerr << oss.str() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
ofstream activeAlarmFile (ACTIVE_ALARM_FILE.c_str());
|
||||||
|
|
||||||
|
AlarmList::const_iterator i;
|
||||||
|
for (i = alarmList.begin(); i != alarmList.end(); ++i)
|
||||||
|
{
|
||||||
|
activeAlarmFile << i->second;
|
||||||
|
}
|
||||||
|
|
||||||
ofstream activeAlarmFile (ACTIVE_ALARM_FILE.c_str());
|
activeAlarmFile.close();
|
||||||
|
|
||||||
AlarmList::const_iterator i;
|
|
||||||
for (i = alarmList.begin(); i != alarmList.end(); ++i)
|
|
||||||
{
|
|
||||||
activeAlarmFile << i->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
activeAlarmFile.close();
|
fl.l_type = F_UNLCK; //unlock
|
||||||
|
fcntl(fd, F_SETLK, &fl);
|
||||||
|
|
||||||
// Release lock
|
close(fd);
|
||||||
if (flock(fd,LOCK_UN)==-1)
|
|
||||||
{
|
|
||||||
throw runtime_error ("Release lock active alarm log file error");
|
|
||||||
}
|
}
|
||||||
close(fd);
|
else
|
||||||
|
{
|
||||||
|
ostringstream oss;
|
||||||
|
oss << "rewriteActiveLog: error opening file " <<
|
||||||
|
ACTIVE_ALARM_FILE <<
|
||||||
|
": " <<
|
||||||
|
strerror(errno);
|
||||||
|
throw runtime_error(oss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************************
|
/*****************************************************************************************
|
||||||
@@ -144,6 +169,9 @@ void rewriteActiveLog (const AlarmList& alarmList)
|
|||||||
*****************************************************************************************/
|
*****************************************************************************************/
|
||||||
void logAlarm (const Alarm& calAlarm, const string& fileName)
|
void logAlarm (const Alarm& calAlarm, const string& fileName)
|
||||||
{
|
{
|
||||||
|
struct flock fl;
|
||||||
|
int fd;
|
||||||
|
|
||||||
if (ALARM_DEBUG) {
|
if (ALARM_DEBUG) {
|
||||||
LoggingID lid(11);
|
LoggingID lid(11);
|
||||||
MessageLog ml(lid);
|
MessageLog ml(lid);
|
||||||
@@ -154,24 +182,48 @@ void logAlarm (const Alarm& calAlarm, const string& fileName)
|
|||||||
ml.logDebugMessage(msg);
|
ml.logDebugMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = open(fileName.c_str(), O_RDWR|O_CREAT, 0644);
|
memset(&fl, 0, sizeof(fl));
|
||||||
ofstream AlarmFile (fileName.c_str(), ios::app);
|
fl.l_type = F_RDLCK; // read lock
|
||||||
|
fl.l_whence = SEEK_SET;
|
||||||
|
fl.l_start = 0;
|
||||||
|
fl.l_len = 0; //lock whole file
|
||||||
|
|
||||||
// Aquire an exclusive lock
|
// create new file
|
||||||
if (flock(fd,LOCK_EX) == -1) {
|
if ((fd = open(fileName.c_str(), O_RDWR|O_CREAT, 0664)) >= 0)
|
||||||
throw runtime_error ("Lock file error: " + fileName);
|
{ // lock file
|
||||||
}
|
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||||
|
{
|
||||||
|
ostringstream oss;
|
||||||
|
oss << "logAlarm: error locking file " <<
|
||||||
|
fileName <<
|
||||||
|
": " <<
|
||||||
|
strerror(errno) <<
|
||||||
|
", proceding anyway.";
|
||||||
|
cerr << oss.str() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
ofstream AlarmFile (fileName.c_str(), ios::app);
|
||||||
|
|
||||||
AlarmFile << calAlarm;
|
AlarmFile << calAlarm;
|
||||||
AlarmFile.close();
|
AlarmFile.close();
|
||||||
|
|
||||||
// Release lock
|
fl.l_type = F_UNLCK; //unlock
|
||||||
if (flock(fd,LOCK_UN)==-1)
|
fcntl(fd, F_SETLK, &fl);
|
||||||
{
|
|
||||||
throw runtime_error ("Release lock file error: " + fileName);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ostringstream oss;
|
||||||
|
oss << "logAlarm: error opening file " <<
|
||||||
|
fileName <<
|
||||||
|
": " <<
|
||||||
|
strerror(errno);
|
||||||
|
throw runtime_error(oss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
close(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************************
|
/*****************************************************************************************
|
||||||
@@ -323,7 +375,6 @@ void configAlarm (Alarm& calAlarm)
|
|||||||
oam.setAlarmConfig (alarmID, "LastIssueTime", now);
|
oam.setAlarmConfig (alarmID, "LastIssueTime", now);
|
||||||
oam.setAlarmConfig (alarmID, "Occurrences", 1);
|
oam.setAlarmConfig (alarmID, "Occurrences", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// increment counter and check the ctnThreshold
|
// increment counter and check the ctnThreshold
|
||||||
@@ -377,7 +428,7 @@ void configAlarm (Alarm& calAlarm)
|
|||||||
*
|
*
|
||||||
*****************************************************************************************/
|
*****************************************************************************************/
|
||||||
void ALARMManager::sendAlarmReport (const char* componentID, int alarmID, int state,
|
void ALARMManager::sendAlarmReport (const char* componentID, int alarmID, int state,
|
||||||
std::string repModuleName, std::string repProcessName)
|
std::string repModuleName, std::string repProcessName)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef SKIP_ALARM
|
#ifdef SKIP_ALARM
|
||||||
@@ -475,58 +526,62 @@ void ALARMManager::sendAlarmReport (const char* componentID, int alarmID, int st
|
|||||||
*****************************************************************************************/
|
*****************************************************************************************/
|
||||||
void ALARMManager::getActiveAlarm(AlarmList& alarmList) const
|
void ALARMManager::getActiveAlarm(AlarmList& alarmList) const
|
||||||
{
|
{
|
||||||
|
struct flock fl;
|
||||||
|
int fd;
|
||||||
|
|
||||||
//add-on to fileName with mount name if on non Parent Module
|
//add-on to fileName with mount name if on non Parent Module
|
||||||
Oam oam;
|
Oam oam;
|
||||||
string fileName = ACTIVE_ALARM_FILE;
|
string fileName = ACTIVE_ALARM_FILE;
|
||||||
|
|
||||||
int fd = open(fileName.c_str(),O_RDONLY);
|
memset(&fl, 0, sizeof(fl));
|
||||||
|
fl.l_type = F_RDLCK; // read lock
|
||||||
|
fl.l_whence = SEEK_SET;
|
||||||
|
fl.l_start = 0;
|
||||||
|
fl.l_len = 0; //lock whole file
|
||||||
|
|
||||||
if (fd == -1) {
|
// create new file
|
||||||
// file may being deleted temporarily by trapHandler
|
if (fd = open(fileName.c_str(),O_RDONLY) >= 0)
|
||||||
sleep (1);
|
{ // lock file
|
||||||
fd = open(fileName.c_str(),O_RDONLY);
|
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||||
if (fd == -1) {
|
|
||||||
// no active alarms, return
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ifstream activeAlarm (fileName.c_str(), ios::in);
|
|
||||||
|
|
||||||
// acquire read lock
|
|
||||||
if (flock(fd,LOCK_SH) == -1)
|
|
||||||
{
|
|
||||||
throw runtime_error ("Lock active alarm log file error");
|
|
||||||
}
|
|
||||||
|
|
||||||
Alarm alarm;
|
|
||||||
|
|
||||||
while (!activeAlarm.eof())
|
|
||||||
{
|
|
||||||
activeAlarm >> alarm;
|
|
||||||
if (alarm.getAlarmID() != INVALID_ALARM_ID)
|
|
||||||
//don't sort
|
|
||||||
// alarmList.insert (AlarmList::value_type(alarm.getAlarmID(), alarm));
|
|
||||||
alarmList.insert (AlarmList::value_type(INVALID_ALARM_ID, alarm));
|
|
||||||
}
|
|
||||||
activeAlarm.close();
|
|
||||||
|
|
||||||
// release lock
|
|
||||||
if (flock(fd,LOCK_UN) == -1)
|
|
||||||
{
|
|
||||||
throw runtime_error ("Release lock active alarm log file error");
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (ALARM_DEBUG)
|
|
||||||
{
|
|
||||||
AlarmList :: iterator i;
|
|
||||||
for (i = alarmList.begin(); i != alarmList.end(); ++i)
|
|
||||||
{
|
{
|
||||||
cout << i->second << endl;
|
ostringstream oss;
|
||||||
|
oss << "getActiveAlarm: error locking file " <<
|
||||||
|
fileName <<
|
||||||
|
": " <<
|
||||||
|
strerror(errno) <<
|
||||||
|
", proceding anyway.";
|
||||||
|
cerr << oss.str() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
ifstream activeAlarm (fileName.c_str(), ios::in);
|
||||||
|
|
||||||
|
Alarm alarm;
|
||||||
|
|
||||||
|
while (!activeAlarm.eof())
|
||||||
|
{
|
||||||
|
activeAlarm >> alarm;
|
||||||
|
if (alarm.getAlarmID() != INVALID_ALARM_ID)
|
||||||
|
//don't sort
|
||||||
|
// alarmList.insert (AlarmList::value_type(alarm.getAlarmID(), alarm));
|
||||||
|
alarmList.insert (AlarmList::value_type(INVALID_ALARM_ID, alarm));
|
||||||
|
}
|
||||||
|
activeAlarm.close();
|
||||||
|
|
||||||
|
fl.l_type = F_UNLCK; //unlock
|
||||||
|
fcntl(fd, F_SETLK, &fl);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (ALARM_DEBUG)
|
||||||
|
{
|
||||||
|
AlarmList :: iterator i;
|
||||||
|
for (i = alarmList.begin(); i != alarmList.end(); ++i)
|
||||||
|
{
|
||||||
|
cout << i->second << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,6 +595,9 @@ void ALARMManager::getActiveAlarm(AlarmList& alarmList) const
|
|||||||
*****************************************************************************************/
|
*****************************************************************************************/
|
||||||
void ALARMManager::getAlarm(std::string date, AlarmList& alarmList) const
|
void ALARMManager::getAlarm(std::string date, AlarmList& alarmList) const
|
||||||
{
|
{
|
||||||
|
struct flock fl;
|
||||||
|
int fd;
|
||||||
|
|
||||||
string alarmFile = "/tmp/alarms";
|
string alarmFile = "/tmp/alarms";
|
||||||
|
|
||||||
//make 1 alarm log file made up of archive and current alarm.log
|
//make 1 alarm log file made up of archive and current alarm.log
|
||||||
@@ -568,68 +626,79 @@ void ALARMManager::getAlarm(std::string date, AlarmList& alarmList) const
|
|||||||
cmd = "cat " + ALARM_FILE + " >> /tmp/alarms";
|
cmd = "cat " + ALARM_FILE + " >> /tmp/alarms";
|
||||||
(void)system(cmd.c_str());
|
(void)system(cmd.c_str());
|
||||||
|
|
||||||
int fd = open(alarmFile.c_str(),O_RDONLY);
|
memset(&fl, 0, sizeof(fl));
|
||||||
|
fl.l_type = F_RDLCK; // read lock
|
||||||
if (fd == -1)
|
fl.l_whence = SEEK_SET;
|
||||||
// doesn't exist yet, return
|
fl.l_start = 0;
|
||||||
return;
|
fl.l_len = 0; //lock whole file
|
||||||
|
|
||||||
ifstream hisAlarm (alarmFile.c_str(), ios::in);
|
// create new file
|
||||||
|
if (fd = open(alarmFile.c_str(),O_RDONLY) >= 0)
|
||||||
// acquire read lock
|
{ // lock file
|
||||||
if (flock(fd,LOCK_SH) == -1)
|
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||||
{
|
|
||||||
throw runtime_error ("Lock alarm log file error");
|
|
||||||
}
|
|
||||||
|
|
||||||
//get mm / dd / yy from incoming date
|
|
||||||
string mm = date.substr(0,2);
|
|
||||||
string dd = date.substr(3,2);
|
|
||||||
string yy = date.substr(6,2);
|
|
||||||
|
|
||||||
Alarm alarm;
|
|
||||||
|
|
||||||
while (!hisAlarm.eof())
|
|
||||||
{
|
|
||||||
hisAlarm >> alarm;
|
|
||||||
if (alarm.getAlarmID() != INVALID_ALARM_ID) {
|
|
||||||
time_t cal = alarm.getTimestampSeconds();
|
|
||||||
struct tm tm;
|
|
||||||
localtime_r(&cal, &tm);
|
|
||||||
char tmp[3];
|
|
||||||
strftime (tmp, 3, "%m", &tm);
|
|
||||||
string alarm_mm = tmp;
|
|
||||||
alarm_mm = alarm_mm.substr(0,2);
|
|
||||||
strftime (tmp, 3, "%d", &tm);
|
|
||||||
string alarm_dd = tmp;
|
|
||||||
alarm_dd = alarm_dd.substr(0,2);
|
|
||||||
strftime (tmp, 3, "%y", &tm);
|
|
||||||
string alarm_yy = tmp;
|
|
||||||
alarm_yy = alarm_yy.substr(0,2);
|
|
||||||
|
|
||||||
if ( mm == alarm_mm && dd == alarm_dd && yy == alarm_yy )
|
|
||||||
//don't sort
|
|
||||||
// alarmList.insert (AlarmList::value_type(alarm.getAlarmID(), alarm));
|
|
||||||
alarmList.insert (AlarmList::value_type(INVALID_ALARM_ID, alarm));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hisAlarm.close();
|
|
||||||
unlink (alarmFile.c_str());
|
|
||||||
|
|
||||||
// release lock
|
|
||||||
if (flock(fd,LOCK_UN) == -1)
|
|
||||||
{
|
|
||||||
throw runtime_error ("Release lock active alarm log file error");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ALARM_DEBUG)
|
|
||||||
{
|
|
||||||
AlarmList :: iterator i;
|
|
||||||
for (i = alarmList.begin(); i != alarmList.end(); ++i)
|
|
||||||
{
|
{
|
||||||
cout << i->second << endl;
|
ostringstream oss;
|
||||||
|
oss << "getAlarm: error locking file " <<
|
||||||
|
alarmFile <<
|
||||||
|
": " <<
|
||||||
|
strerror(errno) <<
|
||||||
|
", proceding anyway.";
|
||||||
|
cerr << oss.str() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ifstream hisAlarm (alarmFile.c_str(), ios::in);
|
||||||
|
|
||||||
|
//get mm / dd / yy from incoming date
|
||||||
|
string mm = date.substr(0,2);
|
||||||
|
string dd = date.substr(3,2);
|
||||||
|
string yy = date.substr(6,2);
|
||||||
|
|
||||||
|
Alarm alarm;
|
||||||
|
|
||||||
|
while (!hisAlarm.eof())
|
||||||
|
{
|
||||||
|
hisAlarm >> alarm;
|
||||||
|
if (alarm.getAlarmID() != INVALID_ALARM_ID) {
|
||||||
|
time_t cal = alarm.getTimestampSeconds();
|
||||||
|
struct tm tm;
|
||||||
|
localtime_r(&cal, &tm);
|
||||||
|
char tmp[3];
|
||||||
|
strftime (tmp, 3, "%m", &tm);
|
||||||
|
string alarm_mm = tmp;
|
||||||
|
alarm_mm = alarm_mm.substr(0,2);
|
||||||
|
strftime (tmp, 3, "%d", &tm);
|
||||||
|
string alarm_dd = tmp;
|
||||||
|
alarm_dd = alarm_dd.substr(0,2);
|
||||||
|
strftime (tmp, 3, "%y", &tm);
|
||||||
|
string alarm_yy = tmp;
|
||||||
|
alarm_yy = alarm_yy.substr(0,2);
|
||||||
|
|
||||||
|
if ( mm == alarm_mm && dd == alarm_dd && yy == alarm_yy )
|
||||||
|
//don't sort
|
||||||
|
// alarmList.insert (AlarmList::value_type(alarm.getAlarmID(), alarm));
|
||||||
|
alarmList.insert (AlarmList::value_type(INVALID_ALARM_ID, alarm));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hisAlarm.close();
|
||||||
|
unlink (alarmFile.c_str());
|
||||||
|
|
||||||
|
fl.l_type = F_UNLCK; //unlock
|
||||||
|
fcntl(fd, F_SETLK, &fl);
|
||||||
|
|
||||||
|
|
||||||
|
if (ALARM_DEBUG)
|
||||||
|
{
|
||||||
|
AlarmList :: iterator i;
|
||||||
|
for (i = alarmList.begin(); i != alarmList.end(); ++i)
|
||||||
|
{
|
||||||
|
cout << i->second << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace alarmmanager
|
} //namespace alarmmanager
|
||||||
|
@@ -2840,6 +2840,8 @@ int ProcessMonitor::updateLog(std::string action, std::string level)
|
|||||||
{
|
{
|
||||||
MonitorLog log;
|
MonitorLog log;
|
||||||
Oam oam;
|
Oam oam;
|
||||||
|
struct flock fl;
|
||||||
|
int fd;
|
||||||
|
|
||||||
string fileName;
|
string fileName;
|
||||||
oam.getSystemConfig("SystemLogConfigFile", fileName);
|
oam.getSystemConfig("SystemLogConfigFile", fileName);
|
||||||
@@ -3080,29 +3082,46 @@ int ProcessMonitor::updateLog(std::string action, std::string level)
|
|||||||
unlink (fileName.c_str());
|
unlink (fileName.c_str());
|
||||||
ofstream newFile (fileName.c_str());
|
ofstream newFile (fileName.c_str());
|
||||||
|
|
||||||
// create new file
|
memset(&fl, 0, sizeof(fl));
|
||||||
int fd = open(fileName.c_str(),O_RDWR|O_CREAT, 0644);
|
fl.l_type = F_RDLCK; // read lock
|
||||||
|
fl.l_whence = SEEK_SET;
|
||||||
// Aquire an exclusive lock
|
fl.l_start = 0;
|
||||||
if (flock(fd,LOCK_EX) == -1) {
|
fl.l_len = 0; //lock whole file
|
||||||
log.writeLog(__LINE__, "ERROR: file lock failure on " + fileName, LOG_TYPE_ERROR );
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
copy(lines.begin(), lines.end(), ostream_iterator<string>(newFile, "\n"));
|
|
||||||
newFile.close();
|
|
||||||
|
|
||||||
// Release lock
|
|
||||||
if (flock(fd,LOCK_UN) == -1)
|
|
||||||
{
|
|
||||||
log.writeLog(__LINE__, "ERROR: file unlock failure on " + fileName, LOG_TYPE_ERROR );
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
oam.syslogAction("restart");
|
// create new file
|
||||||
|
if ((fd = open(fileName.c_str(), O_RDWR|O_CREAT, 0644)) >= 0)
|
||||||
|
{ // lock file
|
||||||
|
|
||||||
|
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||||
|
{
|
||||||
|
ostringstream oss;
|
||||||
|
oss << "ProcessMonitor::updateLog: error locking file " <<
|
||||||
|
fileName <<
|
||||||
|
": " <<
|
||||||
|
strerror(errno) <<
|
||||||
|
", proceding anyway.";
|
||||||
|
cerr << oss.str() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
copy(lines.begin(), lines.end(), ostream_iterator<string>(newFile, "\n"));
|
||||||
|
newFile.close();
|
||||||
|
|
||||||
|
fl.l_type = F_UNLCK; //unlock
|
||||||
|
fcntl(fd, F_SETLK, &fl);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
oam.syslogAction("restart");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ostringstream oss;
|
||||||
|
oss << "ProcessMonitor::updateLog: error opening file " <<
|
||||||
|
fileName <<
|
||||||
|
": " <<
|
||||||
|
strerror(errno);
|
||||||
|
throw runtime_error(oss.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//update file priviledges
|
//update file priviledges
|
||||||
|
Reference in New Issue
Block a user