692 Commits

Author SHA1 Message Date
Wolfgang Hommel
0c2e3d41be the missing else branch on CLOCK_MONOTONIC in clock_nanosleep (#426) 2023-06-06 20:10:31 +02:00
Wolfgang Hommel
f262b5fba7 Re-check fake_monotonic_setting in clock_nanosleep (#426) 2023-06-06 19:48:18 +02:00
Wolfgang Hommel
d17bb114c6 Honor fake_monotoic_clock setting in clock_nanosleep, addresses #426 2023-06-04 13:21:09 +02:00
Wolfgang Hommel
7df1bf7122 Fix #424 2023-04-30 20:26:07 +02:00
Wolfgang Hommel
6d072025c0 Merge pull request #422 from fixindan/dead_lock_no_return
Swapped out pthread_rwlock_xxlock(), which doesn't return if it can't…
2023-02-25 12:58:03 +01:00
Dixin Fan
8ef74e33b6 Swapped out pthread_rwlock_xxlock(), which doesn't return if it can't obtain the lock, with pthread_rwlock_xxtrylock() followed by sched yield and error code return. The issue is sometimes a thread calling pthread_cond_init() or pthread_cond_destroy() can't acquire the lock when another thread is waiting on a condition variable notification via pthread_cond_timedwait(), and thus the thread calling pthread_cond_init() or pthread_cond_destroy() end up hanging indefinitely. 2023-02-24 16:18:47 -06:00
Wolfgang Hommel
6fc4ae74f4 Merge pull request #416 from sliquister/master
ensure faketime can't be initialized more than once
2023-01-27 20:43:41 +01:00
Valentin Gatien-Baron
1997652d8e ensure faketime can't be initialized more than once
One callsite of ftpl_init wasn't protected by the "if (!initialized)"
condition, specifically:

static void ftpl_init (void) __attribute__ ((constructor));

If another "constructor" was called before this one, and that other
constructor used time or filesystem functions, ftlp_init would be
initialized by that other constructor, and then reinitialized by the
ftpl_init constructor. At that point, confusion ensues.
2023-01-16 21:26:39 -05:00
Wolfgang Hommel
de37190d40 Merge pull request #415 from usertam/master
libfaketime.c: wrap timespec_get in TIME_UTC macro
2022-12-20 19:25:59 +01:00
Samuel Tam
e0e6b79568 libfaketime.c: wrap timespec_get in TIME_UTC macro
Function `timespec_get` is not guaranteed to be declared in MacOS
since its standard library is non-conformance to modern standards.
Therefore, skip patching `timespec_get` if it is undeclared by the
standard library.

The detection of `timespec_get` is based on the conjecture that the
macro `TIME_UTC` is only defined when `timespec_get` is declared.
2022-12-20 02:08:45 +08:00
Wolfgang Hommel
df8a045597 Fix for Debian Bug#1017865 as provided by Samuel Thibault 2022-08-28 13:39:18 +02:00
Wolfgang Hommel
2adb56b07f Merge pull request #408 from daglem/short_read
Handle short reads from timestamp file
2022-08-28 13:33:51 +02:00
Dag Lem
1c80b19fe5 Handle short reads from timestamp file 2022-08-22 11:21:14 +02:00
Wolfgang Hommel
32eedc2b42 Merge pull request #406 from enr0n/master
test/snippets: fix time.c compiler error on 32-bit arches
2022-08-10 22:27:39 +02:00
Nick Rosbrook
ccc9992840 test/snippets: fix time.c compiler error on 32-bit arches
Cast t to unsigned long and use the %lu format specifier instead of %zd.
This is more portable to 32-bit arches, avoiding the following compiler
error:

 snippets/time.c:2:31: error: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 3 has type ‘time_t’ {aka ‘long int’} [-Werror=format=]
     2 | printf("[%s] time() yielded %zd\n", where, t);
       |                             ~~^            ~
       |                               |            |
       |                               int          time_t {aka long int}
       |                             %ld
 cc1: all warnings being treated as errors
2022-08-10 14:40:42 -04:00
Wolfgang Hommel
a059f1294f Merge pull request #404 from perldude/perldude-issue-403
issue#403
2022-07-25 20:32:23 +02:00
Wolfgang Hommel
f4bf28356c Merge pull request #397 from j-xella/sun_compiler
Refactor to get rid of some non-standard gcc extensions
2022-07-25 20:32:02 +02:00
Michael Sullivan
5c63238544 issue#403
Disable including `sys/time.h` on ARM to prevent conflicting declarations of `gettimeofday()`.
2022-07-25 09:53:26 -07:00
Wolfgang Hommel
be4e373e63 Merge pull request #400 from sveyret/shared-mem-sync
Reset shared memory when start time is reset
2022-06-20 19:41:24 +02:00
Stéphane Veyret
431f09eb19 Reset shared memory when start time is reset 2022-06-17 16:38:41 +02:00
Aleksandr Jakusev
326c20ebb5 Refactor to get rid of some non-standard gcc extensions
Without the changes Sun studio 12.8 compiler fails, for example

Note that only the errors are fixed. On the compiler above, some
warnings still remain, so -Werror has to be removed as well from the
compiler switches in order for the compilation to succeed.
2022-05-26 23:44:39 +00:00
Wolfgang Hommel
b61fade280 honor dont_fake_monotonic in experimental sem_clockwait() (addresses #390) 2022-05-16 19:20:33 +02:00
Wolfgang Hommel
859751e2cb fix reverse user_rate in sem_clockwait() (addresses #390) 2022-05-14 23:09:03 +02:00
Wolfgang Hommel
f706373bc2 Experimental sem_clockwait() support (addresses #390) 2022-05-11 21:47:35 +02:00
Wolfgang Hommel
e7ca8378ca Merge pull request #391 from psychon/asan2
Fix another hang under ASAN
2022-05-09 19:39:43 +02:00
Uli Schlachter
3b3f80a42f Fix another hang under ASAN
We have a long-running program that we want to run under sanitizers for
extra error checking and under faketime to speed up the clock. This
program hangs after a while. Backtraces suggest that the hangs occur
because of recursion in the memory allocator, which apparently locks a
non-recursive mutex.

Specifically, what we see is that due to our use of FAKETIME_NO_CACHE=1,
libfaketime wants to reload the config file inside a (random) call to
clock_gettime(). libfaketime then uses fopen() / fclose() for reading
the config files. These function allocate / free a buffer for reading
data and specifically the call to free() that happens inside fclose()
ends up calling clock_gettime() again. At this point, libfaketime locks
up because it has a time_mutex that is locked and none-recursive.

Sadly, I did not manage to come up with a stand-alone reproducer for
this problem. Also, the above description is from memory after half a
week of vacation, so it might be (partially) wrong.

More information can be found here:

- https://github.com/wolfcw/libfaketime/issues/365#issuecomment-1115802530
- https://github.com/wolfcw/libfaketime/issues/365#issuecomment-1116178907

This commit first adds a test case. This new test uses the already
existing libmallocintercept.so to cause calls to clock_gettime() during
memory allocation routines. The difference to the already existing
version is that additionally FAKETIME_NO_CACHE and
FAKETIME_TIMESTAMP_FILE are set. This new test hung with its last output
suggesting a recursive call to malloc:

Called malloc() from libmallocintercept...successfully
Called free() on from libmallocintercept...successfully
Called malloc() from libmallocintercept...Called malloc() from libmallocintercept...

Sadly, gdb was unable to provide a meaningful backtrace for this hang.

Next, I replaced the use of fopen()/fgets()/fgets() with
open()/read()/close(). This code no longer reads the config file
line-by-line, but instead it reads all of it at once and then "filters
out" the result (ignores comment lines, removes end of line markers).

I tried to keep the behaviour of the code the same, but I know at least
one difference: Previously, the config file was read line-by-line and
lines that began with a comment character were immediately ignored. The
new code only reads the config once and then removes comment lines.
Since the buffer that is used contains only 256 characters, it is
possible that config files that were previously parsed correctly now
longer parse. A specific example: if a file begins with 500 '#'
characters in its first line and then a timestamp in the second line,
the old code was able to parse this file while the new code would only
see an empty file.

After this change, the new test no longer hangs. Sadly, I do not
actually know its effect on the "actual bug" that I wanted to fix, but
since there are no longer any calls to fclose(), there cannot be any
hangs inside fclose().

Signed-off-by: Uli Schlachter <psychon@znc.in>
2022-05-09 13:53:51 +02:00
Wolfgang Hommel
2bfbe19f71 silence minor type warning in libmallocintercept.c 2022-05-08 21:24:51 +02:00
Wolfgang Hommel
75cbe8e507 silence minor type warning in libmallocintercept.c 2022-05-08 21:20:29 +02:00
Wolfgang Hommel
e8838709ea silence minor type warning in libmallocintercept.c 2022-05-08 21:09:45 +02:00
Wolfgang Hommel
bf3a08b04d silence minor type warning in libmallocintercept.c 2022-05-08 21:05:10 +02:00
Wolfgang Hommel
141d1a7a87 Merge pull request #389 from psychon/asan
Work-around / fix libasan incompatibility
2022-05-08 20:56:16 +02:00
Uli Schlachter
0f79f21e11 Add libmallocintercept.so to make clean
Signed-off-by: Uli Schlachter <psychon@znc.in>
2022-05-08 19:20:51 +02:00
Uli Schlachter
450d5d4549 Disable FAILRE_PRE_INIT_CALLS by default
Signed-off-by: Uli Schlachter <psychon@znc.in>
2022-05-08 19:17:27 +02:00
Uli Schlachter
fff49b23fc Add FAIL_PRE_INIT_CALLS define
This commit adds a new define FAIL_PRE_INIT_CALLS. When that define is
set, calls to clock_gettime() that occur before ftpl_init() was called
(due to being marked with __attribute__((constructor))) will just fail
and return -1.

After this commit, the test case added in the previous commit no longer
hangs. To make this actually work, this new define is enabled by
default.

Fixes: https://github.com/wolfcw/libfaketime/issues/365
Signed-off-by: Uli Schlachter <psychon@znc.in>
2022-05-04 14:51:35 +02:00
Uli Schlachter
6e0f978079 Add test reproducing ASAN-like hangs
Backtraces suggest that AddressSanitizer replaces malloc() with a
function that

- locks a mutex and
- calls clock_gettime() while the mutex is held

This commit adds a test that implements a trivial malloc() that behaves
similarly. Currently, this test hangs.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2022-05-04 14:25:13 +02:00
Wolfgang Hommel
f836ea3eb3 Merge pull request #388 from dkg/cleanup-random-tests
test: remember to clean up repeat_random
2022-04-16 21:17:55 +02:00
Wolfgang Hommel
642b6ee870 Merge pull request #387 from dkg/clean-syscall-tests
clean up tests related to syscall
2022-04-16 21:17:41 +02:00
Daniel Kahn Gillmor
03cb104691 test: remember to clean up repeat_random 2022-04-16 10:27:53 -07:00
Daniel Kahn Gillmor
7e86fb5419 tests: avoid testing syscall snippets if -DINTERCEPT_SYSCALL is not set
See https://bugs.debian.org/1007828
2022-04-16 10:06:23 -07:00
Daniel Kahn Gillmor
e9c74131fc tests: clean whitespace in Makefile 2022-04-16 10:05:40 -07:00
Wolfgang Hommel
8fa0530d83 Honor tv_nsec in timeouts on ppoll() calls (addresses #381) 2022-04-02 13:52:18 +02:00
Wolfgang Hommel
98e3d3f36f select(): Scale timeout parameter by user rate on return (addresses #382) 2022-04-02 13:47:04 +02:00
Wolfgang Hommel
0ca35dd8c4 Merge pull request #375 from inorton/fix_374_UFAKE_STAT
fixes #374 fix compiling without FAKE_STAT or with FAKE_UTIME
2022-03-18 19:31:35 +01:00
Ian Norton
2d941a894f fixes #374 fix compiling without FAKE_STAT 2022-03-18 12:25:55 +00:00
Wolfgang Hommel
f50664f0bd Update NEWS file about v0.9.10 changes 2022-03-04 20:33:18 +01:00
Wolfgang Hommel
d475b92594 Update release date to March 2022 for 0.9.10 (closes #366) v0.9.10 2022-03-04 20:28:35 +01:00
Wolfgang Hommel
40edcc7ca0 Documentation updated regarding FAKETIME_FORCE_MONOTONIC_FIX 2022-02-28 15:42:55 +01:00
Wolfgang Hommel
da348ae2dd Limit glibc auto-sensing to compilation on glibc systems (addresses #369) 2022-02-28 15:21:45 +01:00
Wolfgang Hommel
68f01e7101 Limit glibc auto-sensing to compilation on glibc systems (addresses #369) 2022-02-28 15:19:08 +01:00
Wolfgang Hommel
089a78add5 Exclude glibc versioning on macOS; bump autosense lower threshold to 2.24 2022-02-26 11:07:38 +01:00