Back to index

nordugrid-arc-nox  1.1.0~rc6
Functions | Variables
main_win32.cpp File Reference
#include <fstream>
#include <signal.h>
#include <arc/ArcConfig.h>
#include <arc/message/MCCLoader.h>
#include <arc/XMLNode.h>
#include <arc/Logger.h>
#include "../options.h"

Go to the source code of this file.

Functions

static void shutdown (int)
static void merge_options_and_config (Arc::Config &cfg, Arc::ServerOptions &opt)
static std::string init_logger (Arc::Config &cfg)
int main (int argc, char **argv)

Variables

Arc::Config config
Arc::MCCLoaderloader = NULL
Arc::Loggerlogger = Arc::Logger::rootLogger

Function Documentation

static std::string init_logger ( Arc::Config cfg) [static]

Definition at line 49 of file main_win32.cpp.

{   
    /* setup root logger */
    Arc::XMLNode log = cfg["Server"]["Logger"];
    Arc::LogStream* sd = NULL;
    std::string log_file = (std::string)log;
    std::string str = (std::string)log.Attribute("level");
    if(!str.empty()) {
      Arc::LogLevel level = Arc::string_to_level(str);
      Arc::Logger::rootLogger.setThreshold(level); 
    }


    Arc::Logger::rootLogger.addDestination(*sd);
    if(!log_file.empty()) {
      std::fstream *dest = new std::fstream(log_file.c_str(), std::fstream::out | std::fstream::app);
      if(!(*dest)) {
        logger.msg(Arc::ERROR,"Failed to open log file: %s",log_file);
        _exit(1);
      }
      sd = new Arc::LogStream(*dest);
    }
    Arc::Logger::rootLogger.removeDestinations();
    if(sd) Arc::Logger::rootLogger.addDestination(*sd);
    if ((bool)cfg["Server"]["Foreground"]) {
      logger.msg(Arc::INFO, "Start foreground");
      Arc::LogStream *err = new Arc::LogStream(std::cerr);
      Arc::Logger::rootLogger.addDestination(*err);
    }
    return log_file;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 81 of file main_win32.cpp.

{
    signal(SIGTTOU, SIG_IGN);
    // Temporary stderr destination for error messages
    Arc::LogStream logcerr(std::cerr);
    Arc::Logger::getRootLogger().addDestination(logcerr);
    /* Create options parser */
    Arc::ServerOptions options;
      
    try {
        std::list<std::string> params = options.Parse(argc, argv);
        if (params.size() == 0) {
            /* Load and parse config file */
            config.parse(options.xml_config_file.c_str());
            if(!config) {
                logger.msg(Arc::ERROR, "Failed to load service configuration from file %s",options.xml_config_file);
                exit(1);
            };

            if (options.version) {
                std::cout << Arc::IString("%s version %s", "arched", VERSION) << std::endl;
                exit(0);
            }

            if(!MatchXMLName(config,"ArcConfig")) {
              logger.msg(Arc::ERROR, "Configuration root element is not <ArcConfig>");
              exit(1);
            }

            /* overwrite config variables by cmdline options */
            merge_options_and_config(config, options);
            std::string pid_file = (std::string)config["Server"]["PidFile"];
            /* initalize logger infrastucture */
            std::string root_log_file = init_logger(config);
            
            // set signal handlers 
            signal(SIGTERM, shutdown);
            signal(SIGINT, shutdown);

            // bootstrap
            loader = new Arc::MCCLoader(config);
            if(!*loader) {
                logger.msg(Arc::ERROR, "Failed to load service side MCCs");
            } else {
                logger.msg(Arc::INFO, "Service side MCCs are loaded");
                // sleep forever
                for (;;) {
                    sleep(INT_MAX);
                }
            }
        } else {
            logger.msg(Arc::ERROR, "Unexpected arguments supplied");
        }
    } catch (const Glib::Error& error) {
      logger.msg(Arc::ERROR, error.what());
    }
    
    return 0;
}

Here is the call graph for this function:

static void merge_options_and_config ( Arc::Config cfg,
Arc::ServerOptions opt 
) [static]

Definition at line 28 of file main_win32.cpp.

{   
    Arc::XMLNode srv = cfg["Server"];
    if (!(bool)srv) {
      logger.msg(Arc::ERROR, "No server config part of config file");
      return;
    }
    if (opt.pid_file != "") {
        if (!(bool)srv["PidFile"]) {
           srv.NewChild("PidFile")=opt.pid_file;
        } else {
            srv["PidFile"] = opt.pid_file;
        }
    }
    if (opt.foreground == true) {
        if (!(bool)srv["Foreground"]) {
            srv.NewChild("Foreground");
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void shutdown ( int  ) [static]

Definition at line 21 of file main_win32.cpp.

{
    logger.msg(Arc::VERBOSE, "shutdown");
    delete loader;
    _exit(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 17 of file main_win32.cpp.

Definition at line 18 of file main_win32.cpp.

Definition at line 19 of file main_win32.cpp.