mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / src / mgmsrv / MgmtSrvrConfig.cpp
blob74d4ff5ded1cc39468506644111d084a9abae5eb
1 /* Copyright (c) 2003-2005 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #include <signaldata/TestOrd.hpp>
17 #include <OutputStream.hpp>
19 #include "MgmtSrvr.hpp"
20 #include "SignalQueue.hpp"
21 #include <InitConfigFileParser.hpp>
22 #include <ConfigRetriever.hpp>
23 #include <ndb_version.h>
25 /**
26 * Save a configuration to the running configuration file
28 int
29 MgmtSrvr::saveConfig(const Config *conf) {
30 BaseString newfile;
31 newfile.appfmt("%s.new", m_configFilename.c_str());
33 /* Open and write to the new config file */
34 FILE *f = fopen(newfile.c_str(), "w");
35 if(f == NULL) {
36 /** @todo Send something apropriate to the log */
37 return -1;
39 FileOutputStream stream(f);
40 conf->printConfigFile(stream);
42 fclose(f);
44 /* Rename file to real name */
45 rename(newfile.c_str(), m_configFilename.c_str());
47 return 0;
50 Config *
51 MgmtSrvr::readConfig() {
52 Config *conf;
53 InitConfigFileParser parser;
54 if (m_configFilename.length())
56 conf = parser.parseConfig(m_configFilename.c_str());
58 else
60 ndbout_c("Reading cluster configuration using my.cnf");
61 conf = parser.parse_mycnf();
63 return conf;
66 Config *
67 MgmtSrvr::fetchConfig() {
68 struct ndb_mgm_configuration * tmp = m_config_retriever->getConfig();
69 if(tmp != 0){
70 Config * conf = new Config();
71 conf->m_configValues = tmp;
72 return conf;
74 return 0;