Beispiel #1
0
void run_shell()
{

  char shell_buffer[1000];
  int shell_buffer_pos = 0;
  char c;

  initialize_commands();
  clean_screen_segment(DEBUG);
  clean_screen_segment(SHELL);
  screen_division();
  prompt();
  while(true)
  {
    c = getChar();

    switch(c)
    {
      case '\n':
        shell_run_command(shell_buffer, &shell_buffer_pos);
        prompt();
        break;
      case '\b':
        if (shell_buffer_pos > 0)
        {
          shell_buffer_pos--;
          video_erase_write(SHELL);
        }
        break;
      default:
        shell_buffer[shell_buffer_pos++] = c;
        putchar(c);
    }
  }
}
Beispiel #2
0
int main(int argc, const char **argv)
{

  vector<const char*> args;

  Config_t config;
  char *config_file;
  int i;

  global_config = &config;   //** Make the global point to what's loaded
  memset(global_config, 0, sizeof(Config_t));  //** init the data
  global_network = NULL;

  if (argc < 2) {
     printf("ibp_server [-d] config_file\n\n");
     printf("-d          - Run as a daemon\n");
     printf("config_file - Configuration file\n");
     return(0);
  }

  int astart = 1;
  int daemon = 0;
  if (strcmp(argv[astart], "-d") == 0) {
     daemon = 1;
     argv[astart] = "";
     astart++;
  } 

  config_file = (char *)argv[astart];
 
  argv_to_vec(argc, argv, args);
  parse_config_options(args);     // These are for EBOFS 


  //*** Open the config file *****
  printf("Config file: %s\n\n", config_file);

  GKeyFile *keyfile;
  GKeyFileFlags flags;
  GError *error = NULL;

  keyfile = g_key_file_new();
  flags = G_KEY_FILE_NONE;

  /* Load the GKeyFile from disk or return. */
  if (!g_key_file_load_from_file (keyfile, config_file, flags, &error)) {
    g_error (error->message);
    return(-1);
  }

  
  //** Parse the global options first ***
  parse_config(keyfile, &config);

  init_thread_slots(2*config.server.max_threads);  //** Make pigeon holes

  dns_cache_init(1000);
  init_subnet_list(config.server.iface[0].hostname);  

  //*** Install the commands: loads Vectable info and parses config options only ****
  install_commands(keyfile);

  g_key_file_free(keyfile);   //Free the keyfile context

  set_starttime();

  log_preamble(&config);

  configure_signals();   //** Setup the signal handlers

  //*** Set up the shutdown variables  
  pthread_mutex_init(&shutdown_lock, NULL);
  pthread_mutex_unlock(&shutdown_lock);
  shutdown_now = 0;

  //*** Make the searchable version of the resources ***
  config.rl = create_resource_list(config.res, config.n_resources);
//  log_printf(0, "Looking up resource 2 and printing info.....\n")
//  print_resource(resource_lookup(config.rl, "2"), log_fd());

  init_stats(config.server.stats_size);
  lock_alloc_init();

  //***Launch as a daemon if needed***
  if (args.size() == 2) {    //*** Launch as a daemon ***
     if ((strcmp(config.server.logfile, "stdout") == 0) || 
         (strcmp(config.server.logfile, "stderr") == 0)) {
        log_printf(0, "Can't launch as a daemom because log_file is either stdout or stderr\n");  
        log_printf(0, "Running in normal mode\n");  
     } else if (fork() == 0) {    //** This is the daemon
        log_printf(0, "Running as a daemon.\n");
        flush_log();
        fclose(stdin);     //** Need to close all the std* devices **
        fclose(stdout);
        fclose(stderr);

        char fname[1024];
        fname[1023] = '\0';
        snprintf(fname, 1023, "%s.stdout", config.server.logfile);
        assert((stdout = fopen(fname, "w")) != NULL);
        snprintf(fname, 1023, "%s.stderr", config.server.logfile);
        assert((stderr = fopen(fname, "w")) != NULL);
//        stdout = stderr = log_fd();  //** and reassign them to the log device         
printf("ibp_server.c: STDOUT=STDERR=LOG_FD() dnoes not work!!!!!!!!!!!!!!!!!!!!!!!!\n");
     } else {           //** Parent exits
        exit(0);         
     }    
  }

//  test_alloc();   //** Used for testing allocation speed only

  //*** Initialize all command data structures.  This is mainly 3rd party commands ***
  initialize_commands();

  //** Launch the garbage collection threads
  for (i=0; i<config.n_resources; i++) launch_resource_cleanup_thread(&(config.res[i]));
  //*** Start the activity log ***
  alog_open();

  server_loop(&config);     //***** Main processing loop ******

  //*** Shutdown the activity log ***
  alog_close();

  //*** Destroy all the 3rd party structures ***
  destroy_commands();

  lock_alloc_destroy();

  destroy_thread_slots();

  shutdown(&config);

  free_resource_list(config.rl);

  free_stats();

  log_printf(0, "main: Completed shutdown. Exiting\n");
//  close_log();
//  close_debug();
}