mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-13 14:43:46 +01:00
97d9ba2380
For 23847, we want Tor to be able to shut down and then restart in the same process. Here's a patch to make the Tor binary do that. To test it, you need to build with --enable-restart-debugging, and then you need to set the environment variable TOR_DEBUG_RESTART. With this option, Tor will then run for 5 seconds, then restart itself in-process without exiting. This only happens once. You can change the 5-second interval using TOR_DEBUG_RESTART_AFTER_SECONDS. Implements ticket 24583.
43 lines
971 B
C
43 lines
971 B
C
/* Copyright 2001-2004 Roger Dingledine.
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
|
* Copyright (c) 2007-2017, The Tor Project, Inc. */
|
|
/* See LICENSE for licensing information */
|
|
|
|
#include "orconfig.h"
|
|
#ifdef ENABLE_RESTART_DEBUGGING
|
|
#include <stdlib.h>
|
|
#endif
|
|
|
|
/**
|
|
* \file tor_main.c
|
|
* \brief Stub module containing a main() function.
|
|
*
|
|
* We keep the main function in a separate module so that the unit
|
|
* tests, which have their own main()s, can link against main.c.
|
|
**/
|
|
|
|
int tor_main(int argc, char *argv[]);
|
|
|
|
/** We keep main() in a separate file so that our unit tests can use
|
|
* functions from main.c.
|
|
*/
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
int r;
|
|
#ifdef ENABLE_RESTART_DEBUGGING
|
|
int restart_count = getenv("TOR_DEBUG_RESTART") ? 1 : 0;
|
|
again:
|
|
#endif
|
|
r = tor_main(argc, argv);
|
|
if (r < 0 || r > 255)
|
|
return 1;
|
|
#ifdef ENABLE_RESTART_DEBUGGING
|
|
else if (r == 0 && restart_count--)
|
|
goto again;
|
|
#endif
|
|
else
|
|
return r;
|
|
}
|
|
|