mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Merge branch 'restart_debug_squashed'
This commit is contained in:
@@ -742,6 +742,20 @@ shutdown_did_not_work_callback(evutil_socket_t fd, short event, void *arg)
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
|
||||
#ifdef ENABLE_RESTART_DEBUGGING
|
||||
static struct event *tor_shutdown_event_loop_for_restart_event = NULL;
|
||||
static void
|
||||
tor_shutdown_event_loop_for_restart_cb(
|
||||
evutil_socket_t fd, short event, void *arg)
|
||||
{
|
||||
(void)fd;
|
||||
(void)event;
|
||||
(void)arg;
|
||||
tor_event_free(tor_shutdown_event_loop_for_restart_event);
|
||||
tor_shutdown_event_loop_and_exit(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* After finishing the current callback (if any), shut down the main loop,
|
||||
* clean up the process, and exit with <b>exitcode</b>.
|
||||
@@ -2741,6 +2755,31 @@ do_main_loop(void)
|
||||
main_loop_should_exit = 0;
|
||||
main_loop_exit_value = 0;
|
||||
|
||||
#ifdef ENABLE_RESTART_DEBUGGING
|
||||
{
|
||||
static int first_time = 1;
|
||||
|
||||
if (first_time && getenv("TOR_DEBUG_RESTART")) {
|
||||
first_time = 0;
|
||||
const char *sec_str = getenv("TOR_DEBUG_RESTART_AFTER_SECONDS");
|
||||
long sec;
|
||||
int sec_ok=0;
|
||||
if (sec_str &&
|
||||
(sec = tor_parse_long(sec_str, 10, 0, INT_MAX, &sec_ok, NULL)) &&
|
||||
sec_ok) {
|
||||
/* Okay, we parsed the seconds. */
|
||||
} else {
|
||||
sec = 5;
|
||||
}
|
||||
struct timeval restart_after = { (time_t) sec, 0 };
|
||||
tor_shutdown_event_loop_for_restart_event =
|
||||
tor_evtimer_new(tor_libevent_get_base(),
|
||||
tor_shutdown_event_loop_for_restart_cb, NULL);
|
||||
event_add(tor_shutdown_event_loop_for_restart_event, &restart_after);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return run_main_loop_until_done();
|
||||
}
|
||||
|
||||
|
||||
+15
-1
@@ -3,6 +3,11 @@
|
||||
* 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.
|
||||
@@ -19,9 +24,18 @@ int tor_main(int argc, char *argv[]);
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int r = tor_main(argc, 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user