summaryrefslogtreecommitdiff
path: root/src/faketime.c
diff options
context:
space:
mode:
authorDerrick Brashear <shadow@dementia.org>2011-07-05 10:46:34 -0400
committerDerrick Brashear <shadow@dementia.org>2011-07-05 10:46:34 -0400
commit3c24c524b3c086abb8a5fe749a9d09b2c8b712c0 (patch)
treef626dc646243561f1cbb9b4af10237a14f4f3867 /src/faketime.c
parenteb59447a6d41f03f9f3bd97876a766f9164c5993 (diff)
downloadfaketime-ng-3c24c524b3c086abb8a5fe749a9d09b2c8b712c0.tar.gz
macos: pass one gettimeofday unmodified
needed to avoid a malloc recursion; dyld calls the libSystem initializer, which calls malloc as the first caller; that uses the arc4 randomizer, which calls gettimeofday... the call to fake_time calls strptime_l, _strptime0, gmtsub, and boom, back at malloc. pass one gettimeofday call to let the malloc succeed.
Diffstat (limited to 'src/faketime.c')
-rw-r--r--src/faketime.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/faketime.c b/src/faketime.c
index 1a961a1..618896e 100644
--- a/src/faketime.c
+++ b/src/faketime.c
@@ -630,6 +630,9 @@ time_t fake_time(time_t *time_tptr) {
static time_t last_data_fetch = 0; /* not fetched previously at first call */
static int cache_expired = 1; /* considered expired at first call */
static int cache_duration = 10; /* cache fake time input for 10 seconds */
+#ifdef __APPLE__
+ static int malloc_arena = 0;
+#endif
#ifdef PTHREAD_SINGLETHREADED_TIME
static pthread_mutex_t time_mutex=PTHREAD_MUTEX_INITIALIZER;
@@ -699,6 +702,13 @@ static pthread_mutex_t time_mutex=PTHREAD_MUTEX_INITIALIZER;
} /* cache had expired */
+#ifdef __APPLE__
+ SINGLE_IF(malloc_arena==0)
+ malloc_arena = 1;
+ return *time_tptr;
+ END_SINGLE_IF
+#endif
+
/* check whether the user gave us an absolute time to fake */
switch (user_faked_time[0]) {