diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-11-06 15:21:45 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-11-06 15:21:45 -0500 |
commit | c60f3ea6077451facf2335b7a7c4bc9eaf13c038 (patch) | |
tree | 2c6b62c420f106a72bd3652b3a237475d071b870 /src/feature/hibernate | |
parent | 8a5590ebace8a1c1b367e0eec29ed8bc2712e812 (diff) | |
parent | bd0e38dcfeb63303af83069e4e1e4c70982c56d7 (diff) | |
download | tor-c60f3ea6077451facf2335b7a7c4bc9eaf13c038.tar.gz tor-c60f3ea6077451facf2335b7a7c4bc9eaf13c038.zip |
Merge remote-tracking branch 'tor-github/pr/474' into maint-0.3.5
Diffstat (limited to 'src/feature/hibernate')
-rw-r--r-- | src/feature/hibernate/hibernate.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/feature/hibernate/hibernate.c b/src/feature/hibernate/hibernate.c index 02b05ca3a2..4c46c4fe2a 100644 --- a/src/feature/hibernate/hibernate.c +++ b/src/feature/hibernate/hibernate.c @@ -856,6 +856,26 @@ hibernate_begin(hibernate_state_t new_state, time_t now) "connections, and will shut down in %d seconds. Interrupt " "again to exit now.", options->ShutdownWaitLength); shutdown_time = time(NULL) + options->ShutdownWaitLength; +#ifdef HAVE_SYSTEMD + /* tell systemd that we may need more than the default 90 seconds to shut + * down so they don't kill us. add some extra time to actually finish + * shutting down, otherwise systemd will kill us immediately after the + * EXTEND_TIMEOUT_USEC expires. this is an *upper* limit; tor will probably + * only take one or two more seconds, but assume that maybe we got swapped + * out and it takes a little while longer. + * + * as of writing, this is a no-op with all-defaults: ShutdownWaitLength is + * 30 seconds, so this will extend the timeout to 60 seconds. + * default systemd DefaultTimeoutStopSec is 90 seconds, so systemd will + * wait (up to) 90 seconds anyways. + * + * 2^31 usec = ~2147 sec = ~35 min. probably nobody will actually set + * ShutdownWaitLength to more than that, but use a longer type so we don't + * need to think about UB on overflow + */ + sd_notifyf(0, "EXTEND_TIMEOUT_USEC=%" PRIu64, + ((uint64_t)(options->ShutdownWaitLength) + 30) * TOR_USEC_PER_SEC); +#endif } else { /* soft limit reached */ hibernate_end_time = interval_end_time; } |