本文整理汇总了C++中Oam::changeMyCnf方法的典型用法代码示例。如果您正苦于以下问题:C++ Oam::changeMyCnf方法的具体用法?C++ Oam::changeMyCnf怎么用?C++ Oam::changeMyCnf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oam
的用法示例。
在下文中一共展示了Oam::changeMyCnf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
Oam oam;
//check for port argument
string mysqlPort;
if (argc > 1) {
mysqlPort = argv[1];
// set mysql password
oam.changeMyCnf( "port", mysqlPort );
exit (0);
}
//my.cnf file
string mycnfFile = startup::StartUp::installDir() + "/mysql/my.cnf";
ifstream mycnffile (mycnfFile.c_str());
if (!mycnffile) {
cerr << "mycnfUpgrade - my.cnf file not found: " << mycnfFile << endl;
exit (1);
}
//my.cnf.rpmsave file
string mycnfsaveFile = startup::StartUp::installDir() + "/mysql/my.cnf.rpmsave";
ifstream mycnfsavefile (mycnfsaveFile.c_str());
if (!mycnfsavefile) {
cerr << "mycnfUpgrade - my.cnf.rpmsave file not found: " << mycnfsaveFile << endl;
exit (1);
}
//include arguments file
string includeFile = startup::StartUp::installDir() + "/bin/myCnf-include-args.text";
ifstream includefile (includeFile.c_str());
if (!includefile) {
cerr << "mycnfUpgrade - my.cnf include argument file not found: " << includeFile << endl;
exit (1);
}
//exclude arguments file
string excludeFile = startup::StartUp::installDir() + "/bin/myCnf-exclude-args.text";
ifstream excludefile (excludeFile.c_str());
if (!excludefile) {
cerr << "mycnfUpgrade - my.cnf exclude argument file not found: " << excludefile << endl;
exit (1);
}
//go though include list
char line[200];
string includeArg;
while (includefile.getline(line, 200))
{
includeArg = line;
//see if in my.cnf.rpmsave
ifstream mycnfsavefile (mycnfsaveFile.c_str());
char line[200];
string oldbuf;
while (mycnfsavefile.getline(line, 200))
{
oldbuf = line;
string::size_type pos = oldbuf.find(includeArg,0);
if ( pos != string::npos ) {
//check if this is commented out
if ( line[0] != '#' )
{
// no, find in my.cnf and replace
ifstream mycnffile (mycnfFile.c_str());
vector <string> lines;
char line1[200];
string newbuf;
while (mycnffile.getline(line1, 200))
{
newbuf = line1;
string::size_type pos = newbuf.find(includeArg,0);
if ( pos != string::npos )
newbuf = oldbuf;
//output to temp file
lines.push_back(newbuf);
}
//write out a new my.cnf
mycnffile.close();
unlink (mycnfFile.c_str());
ofstream newFile (mycnfFile.c_str());
//create new file
int fd = open(mycnfFile.c_str(), O_RDWR|O_CREAT, 0666);
copy(lines.begin(), lines.end(), ostream_iterator<string>(newFile, "\n"));
newFile.close();
close(fd);
}
break;
}
}
}
//.........这里部分代码省略.........