19 #include <ndb_global.h>
22 #include "APIService.hpp"
28 #include <sys/types.h>
40 m_procfile =
"ndb_cpcd.db";
44 if(m_monitor != NULL) {
51 CPCD::findUniqueId() {
75 arg->
m_id = findUniqueId();
85 rs->
err(AlreadyExists,
"Name already exists");
91 rs->
err(AlreadyExists,
"Id already exists");
118 rs->
err(NotExists,
"No such process");
153 rs->
err(NotExists,
"No such process");
160 if(proc->
start() != 0){
161 rs->
err(Error,
"Failed to start");
166 rs->
err(Error,
"Already starting");
169 rs->
err(Error,
"Already started");
172 rs->
err(Error,
"Currently stopping");
196 rs->
err(NotExists,
"No such process");
206 rs->
err(AlreadyStopped,
"Already stopped");
210 rs->
err(Error,
"Already stopping");
220 CPCD::notifyChanges() {
232 static int link(
const char* from_file,
const char* to_file)
234 BOOL fail_if_exists = TRUE;
235 if (CopyFile(from_file, to_file, fail_if_exists) == 0)
249 char newfile[PATH_MAX+4];
250 char oldfile[PATH_MAX+4];
251 char curfile[PATH_MAX];
259 f = fopen(newfile,
"w");
263 logger.critical(
"Cannot open `%s': %s\n", newfile, strerror(errno));
280 fprintf(f,
"start process\nid: %d\n\n",
m_processes[
i]->m_id);
300 if(
link(curfile, oldfile) != 0)
301 logger.error(
"Cannot rename '%s' -> '%s'", curfile, oldfile);
303 if(unlink(curfile) != 0) {
304 logger.critical(
"Cannot remove file '%s'", curfile);
309 if(
link(newfile, curfile) != 0) {
310 printf(
"-->%d\n", __LINE__);
312 logger.critical(
"Cannot rename '%s' -> '%s': %s",
313 curfile, newfile, strerror(errno));
324 logger.info(
"Process list saved as '%s'", curfile);
339 f = fopen(m_procfile.
c_str(),
"r");
345 f = fopen(secondfile.
c_str(),
"r");
349 logger.info(
"Configuration file `%s' not found",
351 logger.info(
"Starting with empty configuration");
355 logger.info(
"Configuration file `%s' missing",
357 logger.info(
"Backup configuration file `%s' is used",
375 if(proc->m_processType == TEMPORARY){
376 temporary.push_back(proc->
m_id);
380 for(i = 0; i<temporary.size(); i++){