diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-04-23 09:13:24 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-04-23 09:13:24 -0400 |
commit | cd3fc2aa4867e89877bbfb99f4f767d761b91f25 (patch) | |
tree | 5ff12068373e17f8218907d153f67b6c8c9fcc26 /src/or | |
parent | 8c01aee2e3b8970af96f5b1a662bdf80d0e22489 (diff) | |
parent | dca36eff8fbe9307aa2f74d26841399537e11406 (diff) | |
download | tor-cd3fc2aa4867e89877bbfb99f4f767d761b91f25.tar.gz tor-cd3fc2aa4867e89877bbfb99f4f767d761b91f25.zip |
Merge remote-tracking branch 'neel/b25511-r4'
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/control.c | 28 | ||||
-rw-r--r-- | src/or/control.h | 4 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/or/control.c b/src/or/control.c index 6f56313eaa..dda8872182 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -1931,6 +1931,31 @@ getinfo_helper_listeners(control_connection_t *control_conn, return 0; } +/** Implementation helper for GETINFO: answers requests for information about + * the current time in both local and UTF forms. */ +STATIC int +getinfo_helper_current_time(control_connection_t *control_conn, + const char *question, + char **answer, const char **errmsg) +{ + (void)control_conn; + (void)errmsg; + + struct timeval now; + tor_gettimeofday(&now); + char timebuf[ISO_TIME_LEN+1]; + + if (!strcmp(question, "current-time/local")) + format_local_iso_time_nospace(timebuf, (time_t)now.tv_sec); + else if (!strcmp(question, "current-time/utc")) + format_iso_time_nospace(timebuf, (time_t)now.tv_sec); + else + return 0; + + *answer = tor_strdup(timebuf); + return 0; +} + /** Implementation helper for GETINFO: knows the answers for questions about * directory information. */ STATIC int @@ -3073,6 +3098,9 @@ static const getinfo_item_t getinfo_items[] = { DOC("config/defaults", "List of default values for configuration options. " "See also config/names"), + PREFIX("current-time/", current_time, "Current time."), + DOC("current-time/local", "Current time on the local system."), + DOC("current-time/utc", "Current UTC time."), PREFIX("downloads/networkstatus/", downloads, "Download statuses for networkstatus objects"), DOC("downloads/networkstatus/ns", diff --git a/src/or/control.h b/src/or/control.h index 2fd3c553f3..2f312a6638 100644 --- a/src/or/control.h +++ b/src/or/control.h @@ -311,6 +311,10 @@ STATIC int getinfo_helper_dir( control_connection_t *control_conn, const char *question, char **answer, const char **errmsg); +STATIC int getinfo_helper_current_time( + control_connection_t *control_conn, + const char *question, char **answer, + const char **errmsg); #endif /* defined(CONTROL_PRIVATE) */ |