Esempio n. 1
0
int main(int argc, char **argv)
#endif
{
  long cache_hits, cache_misses;

#if CHROMIUM
  char *argv[] = { "vncreflector" };
  (void) parse_args;
  (void) report_usage;
  /*opt_log_filename = "reflector.log";*/
  opt_log_filename = NULL;
  opt_no_banner = 1;
  opt_foreground = 1;
  opt_stderr_loglevel = 5;
#else
  /* Parse command line, exit on error */
  parse_args(argc, argv);
#endif


  if (!opt_no_banner) {
    fprintf(stderr,
"VNC Reflector %s.  Copyright (C) 2001-2003 HorizonLive.com, Inc.\n\n"
"HorizonLive provides e-Learning and collaborative synchronous presentation\n"
"solutions in a totally Web-based environment.  For more information about\n"
"HorizonLive, please see our website at http://www.horizonlive.com/\n\n",
            VERSION);
  }

  if (!log_open(opt_log_filename, opt_file_loglevel,
                (opt_foreground) ? opt_stderr_loglevel : -1)) {
    fprintf(stderr, "%s: error opening log file (ignoring this error)\n",
            argv[0]);
  }

  log_write(LL_MSG, "Starting VNC Reflector %s", VERSION);

  /* Fork the process to the background if necessary */
  if (!opt_foreground) {
    if (!opt_no_banner) {
      fprintf(stderr, "Starting in the background, "
              "see the log file for errors and other messages.\n");
    }

    if (getpid() != 1) {
      signal(SIGTTIN, SIG_IGN);
      signal(SIGTTOU, SIG_IGN);
      signal(SIGTSTP, SIG_IGN);
      if (fork ())
        return 0;
      setsid();
    }
    close(0);
    close(1);
    close(2);
    log_write(LL_INFO, "Switched to the background mode");
  }

  /* Initialization */
  if (init_screen_info()) {
    read_password_file();
    set_host_encodings(opt_request_tight, opt_tight_level);
    set_client_passwords(opt_client_password, opt_client_ro_password);
    fbs_set_prefix(opt_fbs_prefix, opt_join_sessions);

    set_active_file(opt_active_filename);
    set_actions_file(opt_actions_filename);

    aio_init();
    if (opt_bind_ip != NULL) {
      if (aio_set_bind_address(opt_bind_ip)) {
        log_write(LL_INFO, "Would bind listening sockets to address %s",
                  opt_bind_ip);
      } else {
        log_write(LL_WARN, "Illegal address to bind listening sockets to: %s",
                  opt_bind_ip);
      }
    }

    /* Main work */
    if (vnc_spu.server_port == -1)
    {
      /* Try a series of port numbers until we find one that's free
       * for us.  Then, signal our parent thread that the port number
       * is available.
       */
      int i;
      for (i = 0; i < NUM_SERVER_PORTS; i++) {
        int p = FIRST_SERVER_PORT + i;
	if (wait_for_client(p)) {
	  /* OK, we've got our port number now.  So signal parent thread. */
	  crLockMutex(&vnc_spu.lock);
	  vnc_spu.server_port = p;
	  opt_cl_listen_port = vnc_spu.server_port;
	  crSignalCondition(&vnc_spu.cond);
	  crUnlockMutex(&vnc_spu.lock);

	  if (write_pid_file()) {
	    /*set_control_signals()*/
	    aio_mainloop();
	    remove_pid_file();
	  }
	  break;
	}
      }
      if (i == NUM_SERVER_PORTS) {
	log_write(LL_ERROR, "Unable to find a free port in the range"
		  " %d through %d",
		  FIRST_SERVER_PORT, FIRST_SERVER_PORT + NUM_SERVER_PORTS - 1);
	exit(1);
      }
    }
    else {
      /* user-configured port number */
      opt_cl_listen_port = vnc_spu.server_port;
      if (wait_for_client(opt_cl_listen_port)) {
	if (write_pid_file()) {
	  /*set_control_signals()*/
	  aio_mainloop();
	  remove_pid_file();
	}
      }
    }

    /* Cleanup */
    if (g_framebuffer != NULL) {
      log_write(LL_DETAIL, "Freeing framebuffer and associated structures");
      free(g_framebuffer);
      free_enc_cache();
    }
    if (g_screen_info.name != NULL)
      free(g_screen_info.name);

    get_hextile_caching_stats(&cache_hits, &cache_misses);
    if (cache_hits + cache_misses != 0) {
      log_write(LL_INFO, "Hextile BGR233 caching efficiency: %d%%",
                (int)((cache_hits * 100 + (cache_hits + cache_misses) / 2)
                      / (cache_hits + cache_misses)));
    }
  }

  log_write(LL_MSG, "Terminating");

  /* Close logs */
  if (!log_close() && opt_foreground) {
    fprintf(stderr, "%s: error closing log file (ignoring this error)\n",
            argv[0]);
  }

  /* Done */
  exit(1);
}
Esempio n. 2
0
int main(int argc, char **argv)
{
  long cache_hits, cache_misses;

  /* Parse command line, exit on error */
  parse_args(argc, argv);

  if (!opt_no_banner) {
    fprintf(stderr,
"VNC Reflector %s.  Copyright (C) 2001-2003 HorizonLive.com, Inc.\n\n"
"HorizonLive provides e-Learning and collaborative synchronous presentation\n"
"solutions in a totally Web-based environment.  For more information about\n"
"HorizonLive, please see our website at http://www.horizonlive.com/\n\n",
            VERSION);
  }


   log_write(LL_MSG, "log_open");
  if (!log_open(opt_log_filename, opt_file_loglevel,
                (opt_foreground) ? opt_stderr_loglevel : -1)) {
    fprintf(stderr, "%s: error opening log file (ignoring this error)\n",
            argv[0]);
  }
  log_write(LL_MSG, "Starting VNC Reflector %s", VERSION);

  /* Fork the process to the background if necessary */
  if (!opt_foreground) {
    if (!opt_no_banner) {
      fprintf(stderr, "Starting in the background, "
              "see the log file for errors and other messages.\n");
    }

    if (getpid() != 1) {
      signal(SIGTTIN, SIG_IGN);
      signal(SIGTTOU, SIG_IGN);
      signal(SIGTSTP, SIG_IGN);
      if (fork ())
        return 0;
      setsid();
    }
    close(0);
    close(1);
    close(2);
    log_write(LL_INFO, "Switched to the background mode");
  }
  log_write(LL_MSG, "init_screen_info()");
  /* Initialization */
  if (init_screen_info()) {
    log_write(LL_MSG, "read_password_file()");
    read_password_file();
    set_host_encodings(opt_request_tight, opt_tight_level);
    set_client_passwords(opt_client_password, opt_client_ro_password);
    fbs_set_prefix(opt_fbs_prefix, opt_join_sessions);

    set_active_file(opt_active_filename);
    set_actions_file(opt_actions_filename);
    log_write(LL_INFO, "---------- haciendo bind -----------");
    aio_init();
    if (opt_bind_ip != NULL) {
      if (aio_set_bind_address(opt_bind_ip)) {
        log_write(LL_INFO, "Would bind listening sockets to address %s",
                  opt_bind_ip);
      } else {
        log_write(LL_WARN, "Illegal address to bind listening sockets to: %s",
                  opt_bind_ip);
      }
    }
    
    log_write(LL_INFO, "----------main.c-----------");
    /* Main work */
    if (connect_to_host(opt_host_info_file, opt_cl_listen_port)) {
      if (write_pid_file()) {
        set_control_signals();
        aio_mainloop();
        remove_pid_file();
      }
    }

    /* Cleanup */
    if (g_framebuffer != NULL) {
      log_write(LL_DETAIL, "Freeing framebuffer and associated structures");
      free(g_framebuffer);
      free_enc_cache();
    }
    if (g_screen_info.name != NULL)
      free(g_screen_info.name);

    get_hextile_caching_stats(&cache_hits, &cache_misses);
    if (cache_hits + cache_misses != 0) {
      log_write(LL_INFO, "Hextile BGR233 caching efficiency: %d%%",
                (int)((cache_hits * 100 + (cache_hits + cache_misses) / 2)
                      / (cache_hits + cache_misses)));
    }
  }

  log_write(LL_MSG, "Terminating");

  /* Close logs */
  if (!log_close() && opt_foreground) {
    fprintf(stderr, "%s: error closing log file (ignoring this error)\n",
            argv[0]);
  }

  /* Done */
  exit(1);
}