Back to index

tor  0.2.3.18-rc
Functions | Variables
tor_main.c File Reference

Stub module containing a main() function. More...

#include "micro-revision.i"

Go to the source code of this file.

Functions

int tor_main (int argc, char *argv[])
 Main entry point for the Tor process.
int main (int argc, char *argv[])
 We keep main() in a separate file so that our unit tests can use functions from main.c)

Variables

const char tor_git_revision [] = ""
 String describing which Tor subversion repository version the source was built from.

Detailed Description

Stub module containing a main() function.

Allows unit test binary to link against main.c.

Definition in file tor_main.c.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

We keep main() in a separate file so that our unit tests can use functions from main.c)

Definition at line 28 of file tor_main.c.

{
  return tor_main(argc, argv);
}

Here is the call graph for this function:

int tor_main ( int  argc,
char *  argv[] 
)

Main entry point for the Tor process.

Called from main().

Definition at line 2586 of file main.c.

{
  int result = 0;
#if defined (WINCE)
  WCHAR path [MAX_PATH] = {0};
  WCHAR fullpath [MAX_PATH] = {0};
  PWCHAR p = NULL;
  FILE* redir = NULL;
  FILE* redirdbg = NULL;

  // this is to facilitate debugging by opening
  // a file on a folder shared by the wm emulator.
  // if no flashcard (real or emulated) is present,
  // log files will be written in the root folder
  if (find_flashcard_path(path,MAX_PATH) == -1) {
    redir = _wfreopen( L"\\stdout.log", L"w", stdout );
    redirdbg = _wfreopen( L"\\stderr.log", L"w", stderr );
  } else {
    swprintf(fullpath,L"\\%s\\tor",path);
    CreateDirectory(fullpath,NULL);

    swprintf(fullpath,L"\\%s\\tor\\stdout.log",path);
    redir = _wfreopen( fullpath, L"w", stdout );

    swprintf(fullpath,L"\\%s\\tor\\stderr.log",path);
    redirdbg = _wfreopen( fullpath, L"w", stderr );
  }
#endif

#ifdef _WIN32
  /* Call SetProcessDEPPolicy to permanently enable DEP.
     The function will not resolve on earlier versions of Windows,
     and failure is not dangerous. */
  HMODULE hMod = GetModuleHandleA("Kernel32.dll");
  if (hMod) {
    typedef BOOL (WINAPI *PSETDEP)(DWORD);
    PSETDEP setdeppolicy = (PSETDEP)GetProcAddress(hMod,
                           "SetProcessDEPPolicy");
    if (setdeppolicy) setdeppolicy(1); /* PROCESS_DEP_ENABLE */
  }
#endif

  update_approx_time(time(NULL));
  tor_threads_init();
  init_logging();
#ifdef USE_DMALLOC
  {
    /* Instruct OpenSSL to use our internal wrappers for malloc,
       realloc and free. */
    int r = CRYPTO_set_mem_ex_functions(_tor_malloc, _tor_realloc, _tor_free);
    tor_assert(r);
  }
#endif
#ifdef NT_SERVICE
  {
     int done = 0;
     result = nt_service_parse_options(argc, argv, &done);
     if (done) return result;
  }
#endif
  if (tor_init(argc, argv)<0)
    return -1;
  switch (get_options()->command) {
  case CMD_RUN_TOR:
#ifdef NT_SERVICE
    nt_service_set_state(SERVICE_RUNNING);
#endif
    result = do_main_loop();
    break;
  case CMD_LIST_FINGERPRINT:
    result = do_list_fingerprint();
    break;
  case CMD_HASH_PASSWORD:
    do_hash_password();
    result = 0;
    break;
  case CMD_VERIFY_CONFIG:
    printf("Configuration was valid\n");
    result = 0;
    break;
  case CMD_RUN_UNITTESTS: /* only set by test.c */
  default:
    log_warn(LD_BUG,"Illegal command number %d: internal error.",
             get_options()->command);
    result = -1;
  }
  tor_cleanup();
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char tor_git_revision[] = ""

String describing which Tor subversion repository version the source was built from.

This string is generated by a bit of shell kludging int src/or/Makefile.am, and is usually right.

Definition at line 10 of file tor_main.c.