From 73514dd0e561b521c2c23eb6038301eac3cdcbb1 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 29 Mar 2020 12:51:26 +0200 Subject: [PATCH] allow passing of fancy time to timetravel option --- src/pq/pq_connect.c | 2 +- src/util/common_logging.c | 4 +++- src/util/getopt_helpers.c | 32 ++++++++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c index a7a57f98a..8da273b2b 100644 --- a/src/pq/pq_connect.c +++ b/src/pq/pq_connect.c @@ -190,7 +190,7 @@ apply_patch (struct GNUNET_PQ_Context *db, (0 != code) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not run PSQL on file %s: %d", + "Could not run PSQL on file %s: %d\n", buf, (int) code); return GNUNET_SYSERR; diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 27ac88a05..527dffc02 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -705,7 +705,9 @@ parse_all_definitions () * @return #GNUNET_OK on success */ int -GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) +GNUNET_log_setup (const char *comp, + const char *loglevel, + const char *logfile) { const char *env_logfile; diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c index a2572ccab..f053158ae 100644 --- a/src/util/getopt_helpers.c +++ b/src/util/getopt_helpers.c @@ -623,18 +623,42 @@ set_timetravel_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, const char *value) { long long delta; + long long minus; + struct GNUNET_TIME_Relative rt; (void) scls; (void) ctx; - if (1 != sscanf (value, - "%lld", - &delta)) + while (isspace (value[0])) + value++; + minus = 1; + if (value[0] == '-') + { + minus = -1; + value++; + } + else if (value[0] == '+') + { + value++; + } + if (GNUNET_OK != + GNUNET_STRINGS_fancy_time_to_relative (value, + &rt)) { fprintf (stderr, - _ ("You must pass a number to the `%s' option.\n"), + _ ( + "You must pass a relative time (optionally with sign) to the `%s' option.\n"), + option); + return GNUNET_SYSERR; + } + if (rt.rel_value_us > LONG_LONG_MAX) + { + fprintf (stderr, + _ ("Value given for time travel `%s' option is too big.\n"), option); return GNUNET_SYSERR; } + delta = (long long) rt.rel_value_us; + delta *= minus; GNUNET_TIME_set_offset (delta); return GNUNET_OK; } -- 2.25.1