summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthowse <thowse@tritium.com.au>2020-02-14 10:36:29 +1000
committerthowse <thowse@tritium.com.au>2020-02-14 10:36:29 +1000
commitf7de52c07b2aa18bab368ccdc04b1f223952830d (patch)
treee17c11205cd02ac7ad9f1d8418694901e4df0e1c
parent90f11685b5c46f0b1b48d9aaa7e70172e4a2c44e (diff)
downloadlibfaketime-f7de52c07b2aa18bab368ccdc04b1f223952830d.tar.gz
Refresh the monotonic faketime setting envar when cache expires.
-rw-r--r--src/libfaketime.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/libfaketime.c b/src/libfaketime.c
index 745384d..b67bbe4 100644
--- a/src/libfaketime.c
+++ b/src/libfaketime.c
@@ -518,6 +518,30 @@ static void ft_cleanup (void)
/*
* =======================================================================
+ * Get monotonic faketime setting === GETENV
+ * =======================================================================
+ */
+
+static void get_fake_monotonic_setting(int* current_value)
+{
+ char *tmp_env;
+ if ((tmp_env = getenv("FAKETIME_DONT_FAKE_MONOTONIC")) != NULL
+ || (tmp_env = getenv("DONT_FAKE_MONOTONIC")) != NULL)
+ {
+ if (0 == strcmp(tmp_env, "1"))
+ {
+ (*current_value) = 0;
+ }
+ else
+ {
+ (*current_value) = 1;
+ }
+ }
+}
+
+
+/*
+ * =======================================================================
* Internal time retrieval === INTTIME
* =======================================================================
*/
@@ -2290,14 +2314,7 @@ static void ftpl_init(void)
cache_enabled = 0;
}
}
- if ((tmp_env = getenv("FAKETIME_DONT_FAKE_MONOTONIC")) != NULL
- || (tmp_env = getenv("DONT_FAKE_MONOTONIC")) != NULL)
- {
- if (0 == strcmp(tmp_env, "1"))
- {
- fake_monotonic_clock = 0;
- }
- }
+ get_fake_monotonic_setting(&fake_monotonic_clock);
/* Check whether we actually should be faking the returned timestamp. */
/* We can prevent faking time for specified commands */
@@ -2707,6 +2724,8 @@ int fake_clock_gettime(clockid_t clk_id, struct timespec *tp)
}
} /* read fake time from file */
parse_ft_string(user_faked_time);
+ /* read monotonic faketime setting from envar */
+ get_fake_monotonic_setting(&fake_monotonic_clock);
} /* cache had expired */
if (infile_set)