rendered paste body#include <stdio.h> // sscanf()#include <stdlib.h> // exit()#include <string.h> // strncpy()#include <signal.h>#include "rcs.hh" // EMC NML#include "emc.hh" // EMC NML#include "emcglb.h" // emcGetArgs(), EMC_NMLFILE#define MAXTIME 10.0static int iniLoad(const char *filename){ Inifile inifile; const char *inistring; // open it if (inifile.open(filename) == false) { return -1; } if (NULL != (inistring = inifile.find("DEBUG", "EMC"))) { // copy to global if (1 != sscanf(inistring, "%x", &EMC_DEBUG)) { EMC_DEBUG = 0; } } else { // not found, use default EMC_DEBUG = 0; } if (EMC_DEBUG & EMC_DEBUG_RCS) { set_rcs_print_flag(PRINT_EVERYTHING); max_rcs_errors_to_print = -1; } if (NULL != (inistring = inifile.find("NML_FILE", "EMC"))) { // copy to global strcpy(EMC_NMLFILE, inistring); } else { // not found, use default } // close it inifile.close(); return 0;}static RCS_CMD_CHANNEL *emcCommandChannel = NULL;static RCS_STAT_CHANNEL *emcStatusChannel = NULL;static NML *emcErrorChannel = NULL;static RCS_CMD_CHANNEL *toolCommandChannel = NULL;static RCS_STAT_CHANNEL *toolStatusChannel = NULL;void nice_exit(int ignore) { _exit(0);}int main(int argc, char *argv[]){ double start_time; int s=0; // process command line args if (0 != emcGetArgs(argc, argv)) { rcs_print_error("Error in argument list\n"); exit(1); } // get configuration information iniLoad(EMC_INIFILE); set_rcs_print_destination(RCS_PRINT_TO_NULL); rcs_print("after iniLoad()\n"); start_time = etime()+MAX_TIME; emcCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "emcsvr", EMC_NMLFILE); emcStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "emcsvr", EMC_NMLFILE); emcErrorChannel = new NML(nmlErrorFormat, "emcError", "emcsvr", EMC_NMLFILE); toolCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "toolCmd", "emcsvr", EMC_NMLFILE); toolStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "toolSts", "emcsvr", EMC_NMLFILE); //reinstantiation loop while (etime() < start_time && !s) ) { s=1; if (!emcCommandChannel->valid()) { delete emcCommandChannel;emcCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "emcsvr", EMC_NMLFILE); s=0; } if (!emcStatusChannel->valid()) { rcs_print("emcStatusChannel bungalo-ed, attempt to reinstantiate\n"); delete emcStatusChannel; emcStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "emcsvr", EMC_NMLFILE); s=0; } if (!emcErrorChannel->valid()) { rcs_print("emcErrorChannel bungalo-ed, attempt to reinstantiate\n"); delete emcErrorChannel; emcErrorChannel = new NML(nmlErrorFormat, "emcError", "emcsvr", EMC_NMLFILE); s=0; } if (!toolCommandChannel->valid()) { rcs_print("toolCommandChannel bungalo-ed, attempt to reinstantiate\n"); delete toolCommandChannel; toolCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "toolCmd", "emcsvr", EMC_NMLFILE); s=0; } if (!toolStatusChannel->valid()) { rcs_print("toolStatusChannel bungalo-ed, attempt to reinstantiate\n"); delete toolStatusChannel; toolStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "toolSts", "emcsvr", EMC_NMLFILE); s=0; } esleep(0.200); } set_rcs_print_destination(RCS_PRINT_TO_STDERR); signal(SIGTERM, nice_exit); run_nml_servers(); return 0;}