From e26859e5ca10b669faf357b576f8a9f2300619d8 Mon Sep 17 00:00:00 2001 From: Valentin Gatien-Baron Date: Sun, 1 Aug 2021 08:41:17 -0400 Subject: add a build variable to opt-out of some behaviors Specifically behaviors that increase the chance that a wrapped program will not behave like an unwrapped program does, thus causing reliability issues. --- src/Makefile | 11 +++++++++++ src/libfaketime.c | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/src/Makefile b/src/Makefile index 15e1c68..c1b890d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -56,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) { -- cgit v1.2.1