tor_main.c 971 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Copyright 2001-2004 Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2017, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #include "orconfig.h"
  6. #ifdef ENABLE_RESTART_DEBUGGING
  7. #include <stdlib.h>
  8. #endif
  9. /**
  10. * \file tor_main.c
  11. * \brief Stub module containing a main() function.
  12. *
  13. * We keep the main function in a separate module so that the unit
  14. * tests, which have their own main()s, can link against main.c.
  15. **/
  16. int tor_main(int argc, char *argv[]);
  17. /** We keep main() in a separate file so that our unit tests can use
  18. * functions from main.c.
  19. */
  20. int
  21. main(int argc, char *argv[])
  22. {
  23. int r;
  24. #ifdef ENABLE_RESTART_DEBUGGING
  25. int restart_count = getenv("TOR_DEBUG_RESTART") ? 1 : 0;
  26. again:
  27. #endif
  28. r = tor_main(argc, argv);
  29. if (r < 0 || r > 255)
  30. return 1;
  31. #ifdef ENABLE_RESTART_DEBUGGING
  32. else if (r == 0 && restart_count--)
  33. goto again;
  34. #endif
  35. else
  36. return r;
  37. }