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
This commit is contained in:
@@ -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 )
|
||||||
@@ -2544,40 +2547,54 @@ namespace oam
|
|||||||
|
|
||||||
string fileName = AlarmConfigFile;
|
string fileName = AlarmConfigFile;
|
||||||
|
|
||||||
int fd = open(fileName.c_str(), O_RDWR|O_CREAT, 0644);
|
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
|
||||||
|
|
||||||
// Aquire an exclusive lock
|
// open config file
|
||||||
if (flock(fd,LOCK_EX) == -1) {
|
if ((fd = open(fileName.c_str(), O_RDWR)) >= 0)
|
||||||
throw runtime_error ("Lock file error: " + fileName);
|
{ // lock file
|
||||||
}
|
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||||
|
|
||||||
// write parameter to disk
|
|
||||||
|
|
||||||
Config* alaConfig = Config::makeConfig(AlarmConfigFile.c_str());
|
|
||||||
alaConfig->setConfig(Section, name, value);
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
exceptionControl("setAlarmConfig", API_FAILURE);
|
// write parameter to disk
|
||||||
}
|
|
||||||
|
|
||||||
// Release lock
|
Config* alaConfig = Config::makeConfig(AlarmConfigFile.c_str());
|
||||||
if (flock(fd,LOCK_UN)==-1)
|
alaConfig->setConfig(Section, name, value);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
alaConfig->write();
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{}
|
||||||
|
|
||||||
|
fl.l_type = F_UNLCK; //unlock
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
|
@@ -2902,6 +2902,9 @@ 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);
|
||||||
if (fileName == oam::UnassignedName ) {
|
if (fileName == oam::UnassignedName ) {
|
||||||
@@ -3137,33 +3140,49 @@ int ProcessMonitor::updateLog(std::string action, std::string level)
|
|||||||
//
|
//
|
||||||
|
|
||||||
if (restart) {
|
if (restart) {
|
||||||
|
|
||||||
unlink (fileName.c_str());
|
unlink (fileName.c_str());
|
||||||
ofstream newFile (fileName.c_str());
|
ofstream newFile (fileName.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(fileName.c_str(),O_RDWR|O_CREAT, 0644);
|
if ((fd = open(fileName.c_str(), O_RDWR|O_CREAT, 0644)) >= 0)
|
||||||
|
{ // lock file
|
||||||
|
|
||||||
// Aquire an exclusive lock
|
if (fcntl(fd, F_SETLKW, &fl) != 0)
|
||||||
if (flock(fd,LOCK_EX) == -1) {
|
{
|
||||||
log.writeLog(__LINE__, "ERROR: file lock failure on " + fileName, LOG_TYPE_ERROR );
|
ostringstream oss;
|
||||||
close(fd);
|
oss << "ProcessMonitor::updateLog: error locking file " <<
|
||||||
return -1;
|
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
|
||||||
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 );
|
ostringstream oss;
|
||||||
close(fd);
|
oss << "ProcessMonitor::updateLog: error opening file " <<
|
||||||
return -1;
|
fileName <<
|
||||||
|
": " <<
|
||||||
|
strerror(errno);
|
||||||
|
throw runtime_error(oss.str());
|
||||||
}
|
}
|
||||||
close(fd);
|
|
||||||
|
|
||||||
oam.syslogAction("restart");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//update file priviledges
|
//update file priviledges
|
||||||
|
Reference in New Issue
Block a user