summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Hommel <wolfcw@users.noreply.github.com>2021-08-01 20:44:14 +0200
committerGitHub <noreply@github.com>2021-08-01 20:44:14 +0200
commitb7fff74716ccd962413cdf31977a27c381b8a746 (patch)
tree0512ea3aebc4a64f13b7dfab74a150796dd79531
parent9043941fa9e98917ed1f672d794deab4d73592a3 (diff)
parente26859e5ca10b669faf357b576f8a9f2300619d8 (diff)
downloadlibfaketime-b7fff74716ccd962413cdf31977a27c381b8a746.tar.gz
Merge pull request #344 from sliquister/fake-stateless
Add a build variable to opt-out of behaviors that reduce reliability
-rw-r--r--src/Makefile52
-rw-r--r--src/libfaketime.c7
2 files changed, 40 insertions, 19 deletions
diff --git a/src/Makefile b/src/Makefile
index ad2b797..c1b890d 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,24 +1,19 @@
#
# Notes:
#
-# * Compilation Defines:
+# * Compilation Defines that are set by default:
#
# FAKE_STAT
-# - Enables time faking also for files' timestamps.
+# - Enables time faking when reading files' timestamps.
#
-# FAKE_FILE_TIMESTAMPS, FAKE_UTIME
-# - Enables time faking for the utime* functions. If enabled via
-# FAKE_UTIME define instead of FAKE_FILE_TIMESTAMPS, the faking
-# defaults to off without FAKE_UTIME in the environment.
+# FAKE_SLEEP
+# - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll()
#
-# NO_ATFILE
-# - Disables support for the fstatat() group of functions
+# FAKE_TIMERS
+# - Also intercept timer_settime() and timer_gettime()
#
-# PTHREAD_SINGLETHREADED_TIME
-# - Define this if you want to single-thread time() ... there ARE
-# possible caching side-effects in a multithreaded environment
-# without this, but the performance impact may require you to
-# try it unsynchronized.
+# FAKE_PTHREAD
+# - Intercept pthread_cond_timedwait
#
# FAKE_INTERNAL_CALLS
# - Also intercept libc internal __functions, e.g. not just time(),
@@ -26,14 +21,22 @@
# that make use of low-level system calls, such as Java Virtual
# Machines.
#
-# FAKE_SLEEP
-# - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll()
+# PTHREAD_SINGLETHREADED_TIME (only set in libfaketimeMT.so)
+# - Define this if you want to single-thread time() ... there ARE
+# possible caching side-effects in a multithreaded environment
+# without this, but the performance impact may require you to
+# try it unsynchronized.
#
-# FAKE_TIMERS
-# - Also intercept timer_settime() and timer_gettime()
+# * Compilation Defines that are unset by default:
#
-# FAKE_PTHREAD
-# - Intercept pthread_cond_timedwait
+# FAKE_FILE_TIMESTAMPS, FAKE_UTIME
+# - Enables time faking for the utime* functions. If enabled via
+# FAKE_FILE_TIMESTAMPS, the faking is opt-in at runtime using
+# with the FAKE_UTIME environment variable. If enabled via
+# FAKE_UTIME, the faking is opt-out at runtime.
+#
+# NO_ATFILE
+# - Disables support for the fstatat() group of functions
#
# FAKE_SETTIME
# - Intercept clock_settime(), settimeofday(), and adjtime()
@@ -53,6 +56,17 @@
# -Dvariadic_promotion_t=int into CFLAGS). See src/faketime_common.h for
# more info.
#
+# FAKE_STATELESS
+# - Remove support for any functionality that requires sharing state across
+# threads of a process, or different processes. This decreases the risk of
+# interference with a program's normal execution, at the cost of supporting
+# fewer ways of specifying the time.
+# Concretely, this currently:
+# - disables PTHREAD_SINGLETHREADED_TIME, which can cause deadlocks in
+# multithreaded programs that fork due to making clock_gettime not
+# async-signal-safe
+# - disables all shared-memory across processes
+#
# FORCE_MONOTONIC_FIX
# - If the test program hangs forever on
# " pthread_cond_timedwait: CLOCK_MONOTONIC test
diff --git a/src/libfaketime.c b/src/libfaketime.c
index afafc5d..6def8f2 100644
--- a/src/libfaketime.c
+++ b/src/libfaketime.c
@@ -60,6 +60,9 @@
#include "time_ops.h"
#include "faketime_common.h"
+#if defined PTHREAD_SINGLETHREADED_TIME && defined FAKE_STATELESS
+#undef PTHREAD_SINGLETHREADED_TIME
+#endif
/* pthread-handling contributed by David North, TDI in version 0.7 */
#if defined PTHREAD_SINGLETHREADED_TIME || defined FAKE_PTHREAD
@@ -2652,7 +2655,11 @@ static void ftpl_init(void)
initialized = 1;
+#ifdef FAKE_STATELESS
+ if (0) ft_shm_init();
+#else
ft_shm_init();
+#endif
#ifdef FAKE_STAT
if (getenv("NO_FAKE_STAT")!=NULL)
{