Ejemplo n.º 1
0
void run_chordtest(int argc, char **argv)
{
  node *n = node_start(LOG_ERROR,0);
  if (NULL == n)
    exit(1);

  if (0 == argc) {
    /* Standalone mode; run the test locally */
    endpointid managerid;
    managerid.ip = n->listenip;
    managerid.port = n->listenport;
    managerid.localid = MANAGER_ID;
    start_manager(n);
    testchord(n,&managerid,1);
  }
  else {
    /* Client mode; run the chord test on a set of remote nodes specified in the file */
    endpointid *managerids;
    int nmanagers;
    if (0 != read_managers(n,argv[0],&managerids,&nmanagers))
      exit(1);
    testchord(n,managerids,nmanagers);
    free(managerids);
  }

  node_run(n);
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: irontec/isaac
/**
 * \brief Main program function
 *
 * This functions parse command line options to determine Isaac behaviour
 * This progran can be used as a Isaac process or a CLI client
 * if -r option is specified.
 *
 * \param argc Argument counter
 * \param argv Array of string arguments passed to the program
 */
int
main(int argc, char *argv[])
{
    pid_t pid;
    int opt_remote = 0;
    char opt;
    char * xarg = NULL;

    // Parse commandline arguments
    while ((opt = getopt(argc, argv, "dhrvx:")) != EOF) {
        switch (opt) {
        case 'd':
            debug++;
            break;
        case 'r':
            opt_remote++;
            break;
        case 'x':
            opt_execute++;
            opt_remote++; // This is implicit in 'x'
            xarg = strdup(optarg);
            break;
        case 'v':
            version();
            exit(EXIT_SUCCESS);
        case 'h':
        case '?':
            usage();
            exit(EXIT_SUCCESS);
        }
    }

    // Check if there is an Isaac is already running
    if (opt_remote) {
        if (remote_tryconnect() == 0) {
            if (!opt_execute) {
                remote_control(NULL);
                return 0;
            } else {
                remote_control(xarg);
                return 0;
            }
        } else {
            fprintf(stderr, "Unable to connect to remote Isaac (does %s exist?)\n", CLI_SOCKET);
            exit(1);
        }
    } else {
        // Check Isaac is not already running
        if (access(CLI_SOCKET, F_OK) == 0) {
            fprintf(stderr, "%s already running on %s. Use '%s -r' to connect\n", argv[0],
                    CLI_SOCKET, argv[0]);
            exit(1);
        }
    }

    // If we are not in debug mode, then fork to background
    if (!debug) {
        if ((pid = fork()) < 0)
            exit(1);
        else if (pid > 0)
            exit(0);
    }

    cfg_init(&config);

    // Setup signal handlers
    (void) signal(SIGINT, quit);
    (void) signal(SIGTERM, quit);
    (void) signal(SIGPIPE, SIG_IGN);

    // Read configuration files
    if (cfg_read(&config, CFILE) != 0) {
        fprintf(stderr, "Failed to read configuration file %s\n", CFILE);
        quit(EXIT_FAILURE);
    }

    // Initialize logging
    if (start_logging(config.logtype, config.logfile, config.logtag, config.loglevel) != 0) {
        fprintf(stderr, "Failed to read configuration file %s\n", CFILE);
        quit(EXIT_FAILURE);
    }

    // Load Modules. The contain the server Applications
    if (load_modules() != 0) {
        quit(EXIT_FAILURE);
    }

    // Start manager thread
    if (start_manager(config.manaddr, config.manport, config.manuser, config.manpass) != 0) {
        quit(EXIT_FAILURE);
    }

    // Start cli service
    if (cli_server_start() != 0) {
        quit(EXIT_FAILURE);
    }
    
        // Start server thread
    if (start_server(config.listenaddr, config.listenport) == -1) {
        quit(EXIT_FAILURE);
    }

    // All subsystems Up!
    isaac_log(LOG_NONE, "\e[1;37m%s Ready.\e[0m\n", PACKAGE_NAME);

    // Wait here until any signal is sent
    pause();

    // Unreachable code :D
    return 0;
}