370 Commits

Author SHA1 Message Date
Wolfgang Hommel
57de5bbe83 Merge pull request #252 from sdettmer/automake_make_check
**FOR REVIEW** Automake make check
2020-04-09 19:29:29 +02:00
Steffen Dettmer
c2b5b71777 First few fixes for make check (#250) 2020-04-09 17:43:51 +02:00
Steffen Dettmer
6c0947c86e Fixed make distcheck (#250) 2020-04-09 17:43:10 +02:00
Steffen Dettmer
b36ad2342c Removed automatically created files (#250) 2020-04-09 16:58:44 +02:00
Wolfgang Hommel
d40d0ebaa7 adapt travis.yml to automake 2020-04-09 06:37:39 +02:00
Wolfgang Hommel
081845440b fix bracket syntax on Linux 2020-04-09 06:34:20 +02:00
Wolfgang Hommel
30207e8fdf merge with @manchicken's automake branch 2020-04-09 06:26:49 +02:00
Wolfgang Hommel
d2f0daf092 Merge pull request #246 from sdettmer/dev/sde/pthread_cond_init_232_lazy_init
Add lazy ftpl_init() to pthread_cond_init_232(), fixes #245.
2020-04-08 20:11:57 +02:00
Steffen Dettmer
c5b5d0b56e Add lazy ftpl_init() to pthread_cond_init_232(), fixes #245. 2020-04-08 19:57:14 +02:00
Wolfgang Hommel
f8a0ad2496 Merge pull request #244 from sdettmer/dev/sde/faketime_link_flags
Added support for FAKETIME_LINK_FLAGS for #243.
2020-04-08 19:47:46 +02:00
Steffen Dettmer
0e3269efdc Added support for FAKETIME_LINK_FLAGS for #243. 2020-04-08 19:40:31 +02:00
Wolfgang Hommel
04e78e67bf Unskip file parsing on improper initialization #240 2020-03-26 20:07:24 +01:00
Wolfgang Hommel
0e798503a4 Merge pull request #237 from FeepingCreature/fix/use-pthread-mutex-initializer-again
replace global state struct with local state struct holding a pointer to the global mutex variable
2020-03-16 13:45:37 +01:00
Mathis Beer
a7f7a54e1d replace global state struct with local state struct holding a pointer to the global mutex variable
this fixes the `{ 0 }` initializer not compiling on some platforms
fix issue 231
fix issue 235
2020-03-16 07:57:07 +01:00
Wolfgang Hommel
8075c2e250 Merge pull request #234 from FeepingCreature/fix/use-appropriate-mask-function
Fix timing issue with multiple threads
2020-03-12 21:39:17 +01:00
Mathis Beer
a12ca58dfa fix threading issue: don't assign to the global lock state struct until we're safely inside the mutex.
Otherwise, we might be overwriting the global lock state from two different
threads at once.
2020-03-12 06:49:29 +01:00
Mathis Beer
b4dea2ef9b Unlock faketime lock on all return paths from libfaketime.c.
These gymnastics are necessary because pthread_cleanup_push
and pthread_cleanup_pop must match exactly 1:1 and appear at
the same level of indentation.

This is because pthread_cleanup_push/pop are implemented in
such a way that pthread_cleanup_push opens a scope and
pthread_cleanup_pop closes it.

They're macros with unbalanced brackets.
C, ladies and gentlemen.

So instead of returning, we have to set a field indicating our
intent to return and then jump to the unlock site.
2020-03-12 06:45:43 +01:00
Mathis Beer
796b30bebf use pthread_sigmask instead of sigprocmask
pthread_sigmask is the one meant for threaded programs.
2020-03-12 06:43:33 +01:00
Wolfgang Hommel
70d26ec15c Merge pull request #230 from FeepingCreature/fix/block-signals-while-locked
Fix deadlock issues with signals: block all signals while inside mutex.
2020-03-03 19:47:49 +01:00
Mathis Beer
052239d828 Fix deadlock issues with signals: block all signals while inside mutex. 2020-03-03 17:22:52 +01:00
Wolfgang Hommel
fe8c0acee6 Merge pull request #229 from FeepingCreature/fix/dont-allocate-stack-buffers
fake_clock_gettime: avoid placing large buffers on the stack
2020-02-20 21:10:19 +01:00
Mathis Beer
c44a332e0e fake_clock_gettime: avoid placing large buffers on the stack 2020-02-20 12:14:14 +01:00
Wolfgang Hommel
a54f204209 Merge pull request #227 from wolfcw/develop
Refresh the monotonic faketime setting envvar when cache expires.
2020-02-14 19:42:23 +01:00
Wolfgang Hommel
195888434a Merge pull request #225 from tjhowse/develop
Refresh the monotonic faketime setting envar when cache expires.
2020-02-14 19:36:06 +01:00
thowse
f7de52c07b Refresh the monotonic faketime setting envar when cache expires. 2020-02-14 10:36:29 +10:00
Wolfgang Hommel
0efe7b3e3e Merge pull request #220 from aristanemi/mul_overflow_fix
timespec multiplication overflow fix
2019-12-17 18:55:20 +01:00
Abhishek Sunkum Rammurthy
b542e14959 time multiplication overflow fix
In 32 bit platforms, timespecmul2() macro function, overflow occurs during multiplication.
Size of `long` type in 32 bit platform is 4 bytes, but the size of `long` type in 64 bit platform is 8 bytes.
2019-12-17 15:16:38 +01:00
Wolfgang Hommel
78385ba8b7 Use -DFAKE_FILE_TIMESTAMPS to intercept utime[s](), by @speq, #183 2019-12-14 21:49:23 +01:00
Wolfgang Hommel
b3dcef470e fix #ifndef for timermul, @speq, #183 2019-12-14 21:30:31 +01:00
Wolfgang Hommel
90f11685b5 wrap nanosec ops in #ifndef, patch by @paul-j-lucas, #219 2019-12-14 19:49:04 +01:00
Wolfgang Hommel
d7ef17a0de Merge pull request #218 from wolfcw/revert-178-automake-branch
Revert "Automake branch"
2019-11-30 09:37:00 +01:00
Wolfgang Hommel
3123ad7fe2 Revert "Automake branch" 2019-11-30 09:36:46 +01:00
Wolfgang Hommel
af2d2e5111 Merge pull request #178 from manchicken/automake-branch
Automake branch
2019-11-30 09:36:36 +01:00
Wolfgang Hommel
11fbc2ada1 Create make-test.yml 2019-11-30 09:16:43 +01:00
Michael D. Stemle, Jr
f92d919fb0 Merged master in and cleaned up.
We no longer need the OSX-specific test. Tests are passing, too.
2019-11-27 14:32:15 -05:00
Wolfgang Hommel
22f8c3dd36 Work around race conditions when semaphore gets deleted by parent process (#217) 2019-11-20 08:43:24 +01:00
Wolfgang Hommel
a0fe6b56b0 Merge pull request #215 from wolfcw/develop
Merge changes from develop branch
2019-11-14 19:33:00 +01:00
Wolfgang Hommel
fdc3c81ae0 Merge pull request #214 from daowens01/unused_variable_compiler_error
Wrap user_per_tick_inc_set_backup declaration in ifdef
2019-11-14 19:08:44 +01:00
David Owens
10b9818c2c Wrap user_per_tick_inc_set_backup declaration in ifdef
Building without FAKE_STAT defined causes compilation errors due to
unused variable user_per_tick_inc_set_backup.  Move declaration inside
FAKE_STAT section along with the code making use of it.
2019-11-14 09:27:27 -06:00
Wolfgang Hommel
826f8b7792 Detect and bail out of endless recursive calls to clock_gettime() (#130) 2019-09-05 22:52:07 +02:00
Wolfgang Hommel
5d1e6325f2 Add FAKE_SETTIME to CFLAGS to intercept time-setting calls (#179) 2019-09-03 12:01:33 +02:00
Wolfgang Hommel
8ed946cb63 Documentation for packagers, esp. about FORCE_PTHREAD_NONVER and FORCE_MONOTONIC_FIX 2019-08-31 21:32:52 +02:00
Wolfgang Hommel
108370f850 Adds FORCE_PTHREAD_NONVER flag for platforms where pthread functions are not intercepted 2019-08-29 09:55:04 +02:00
Wolfgang Hommel
3de0d02353 Add macOS / OSX build to .travis.yml 2019-08-23 21:20:48 +02:00
Wolfgang Hommel
dc2ae5eef3 Add FORCE_MONOTONIC_FIX to .travis.yml 2019-08-23 19:34:51 +02:00
Wolfgang Hommel
1c05fdd333 Adding a simple .travis.yml file 2019-08-23 19:27:38 +02:00
Wolfgang Hommel
c60390a7e3 Updated documentation regarding compatibility, use on macOS, and contributions 2019-08-23 15:24:13 +02:00
Wolfgang Hommel
ece59abf39 Cleanup old and outdated packaging infos 2019-08-23 14:54:08 +02:00
Wolfgang Hommel
d79ed053d7 Updated documentation regarding shared memory, fixed spelling 2019-08-23 14:46:06 +02:00
Wolfgang Hommel
416c5f4708 Fix shared memory cleanup on local creation 2019-08-23 12:29:33 +02:00
Wolfgang Hommel
a238cfa2b6 Added FAKETIME_COMPILE_CFLAGS to Makefiles 2019-08-23 11:38:35 +02:00
Wolfgang Hommel
ba32d1b01c Added FORCE_MONOTONIC_FIX CFLAG to avoid hangs on timedwait (#202 #142) 2019-08-23 10:29:53 +02:00
Wolfgang Hommel
30ba0b852a Fix Makefile to run 'make src' before running 'make test' (#201) 2019-08-23 10:12:38 +02:00
Wolfgang Hommel
5932e38032 Handle platforms that do not implement semopen() (#203) 2019-08-23 10:08:32 +02:00
Wolfgang Hommel
13748ddb22 Fix building on macOS in preparation of v0.9.8 release 2019-08-22 23:39:36 +02:00
Wolfgang Hommel
5f033fe486 Intercept epoll_wait(), epoll_pwait(), and pselect() (#115) 2019-08-22 23:29:48 +02:00
Wolfgang Hommel
52108dba7a Added FAKETIME_XRESET to smoothen run-time transition between 'x' modifier values (#198) 2019-08-22 00:49:21 +02:00
Wolfgang Hommel
5ddb237842 Adjusted tests on macOS based on compilation defaults 2019-08-21 18:42:05 +02:00
Wolfgang Hommel
314b1298c9 Added support for clock_nanosleep() (#105) 2019-08-21 18:05:17 +02:00
Wolfgang Hommel
7573d20cd4 Further preparations for the upcoming v0.9.8 release 2019-08-21 11:01:24 +02:00
Wolfgang Hommel
0c8905f4ad fix stat faking when FAKETIME 'i' modifier is set (#183) 2019-08-21 10:23:01 +02:00
Wolfgang Hommel
57917c4d5a Added follow-file-timestamp mode via FAKETIME='%' and FAKETIME_FOLLOW_FILE (#156) 2019-08-20 19:43:15 +02:00
Wolfgang Hommel
e85863f671 Added note regarding leap year handling in documentation (#145) 2019-08-20 18:07:17 +02:00
Wolfgang Hommel
d5c0050684 Added environment variable FAKETIME_DONT_RESET to enable old start-at behavior (#163) 2019-08-20 15:43:29 +02:00
Wolfgang Hommel
b855b8a0d3 Updated documentation regarding offset specification on x/i modifiers 2019-08-20 13:08:36 +02:00
Wolfgang Hommel
29efeed247 don't fake time during dlsym() calls in ftpl_init (#130) 2019-08-20 10:49:01 +02:00
Wolfgang Hommel
c13e41024e Improved handling of shm/semaphores w.r.t. stale states (#199) 2019-08-20 09:53:22 +02:00
Wolfgang Hommel
65cdc7b718 Avoid hangs with clock_monotonic for pthread_cond_timedwait 2019-08-19 19:38:01 +02:00
Wolfgang Hommel
d923612c2b Improved cross-platform compatibility defaults 2019-08-19 19:16:07 +02:00
Wolfgang Hommel
59127e7514 More error details on sem_open failures 2019-08-19 14:21:47 +02:00
Wolfgang Hommel
3b494ac6c9 Safety check when creating semaphore locally 2019-08-18 19:06:52 +02:00
Wolfgang Hommel
073d185102 More detailed error messages on shm errors 2019-08-16 15:53:47 +02:00
Wolfgang Hommel
a70db9196a Shared memory cleanup when it was created locally 2019-08-13 19:48:29 +02:00
Wolfgang Hommel
7498c405ed Create shared memory if we don't have it yet (#120) 2019-08-13 19:35:45 +02:00
Wolfgang Hommel
aa091db286 Preparations for 0.9.8 release 2019-08-12 12:25:41 +02:00
Wolfgang Hommel
5e56e9a8fe addressing #190 #196 2019-08-04 18:47:30 +02:00
Wolfgang Hommel
fe42c2b4cf start-at-faketime startup fix, addresses #196 2019-08-04 17:59:33 +02:00
Wolfgang Hommel
579b908580 Merge pull request #194 from qnox/configuration_reload_fix
fixed configuration reload
2019-06-26 19:20:38 +02:00
qnox
2827a69ffe fixed configuration reload 2019-06-26 17:40:37 +02:00
Wolfgang Hommel
949183381f Merge pull request #192 from qnox/fake_pthreads_thread_safety
Fixed thread safety issue in pthread faking methods
2019-06-01 12:28:07 +02:00
qnox
ff48a007a2 fixed thread safety issue in pthread faking methods 2019-05-31 22:46:54 +02:00
Wolfgang Hommel
9846eceb10 Use absolute offset in #190, fix case 1 2019-05-03 16:03:13 +02:00
Wolfgang Hommel
7bc0d5044f Use absolute offset in #190 2019-05-03 15:45:28 +02:00
Wolfgang Hommel
ceac4c7036 Merge pull request #184 from FeepingCreature/fix-inconsistent-envvar
Rename DONT_FAKE_MONOTONIC to FAKETIME_DONT_FAKE_MONOTONIC for consistency
2019-02-05 08:11:21 +01:00
Mathis Beer
5c4fdb5173 Rename DONT_FAKE_MONOTONIC to FAKETIME_DONT_FAKE_MONOTONIC for consistency.
The old variable still works.
2019-02-05 07:45:31 +01:00
Mike Stemle
150a6cb3b2 Added a check for missing libtool. 2018-10-11 10:22:04 -04:00
Michael D. Stemle, Jr
39a85e380c Fixed a _bunch_ of autotools bugs. 2018-10-07 22:38:55 -04:00
Michael D. Stemle, Jr
825043515f Applying fixes for GNU/Linux, and the MT variant of the library. 2018-10-03 22:17:28 -04:00
Michael D. Stemle, Jr
335617c4c7 Fixed a bunch more issues, including prefix-related issues and library version breakage. 2018-10-02 23:22:51 -04:00
Michael D. Stemle, Jr
96668a9c6d Fixing a couple of issues I just found. 2018-10-02 22:20:14 -04:00
Michael D. Stemle, Jr
24fd806e6b Added GNU autotools support. 2018-10-02 22:02:30 -04:00
Michael D. Stemle, Jr
39c6872f6d Removing old makefiles. 2018-10-01 20:08:27 -04:00
Wolfgang Hommel
5c6518c597 Merge pull request #171 from ringlej/fixes
Allow specifying fractions of a second when setting FAKETIME
2018-08-01 19:29:00 +02:00
Jon Ringle
93148b3599 Allow specifying fractions of a second when setting FAKETIME
Signed-off-by: Jon Ringle <jringle@gridpoint.com>
2018-07-31 16:33:57 -04:00
Wolfgang Hommel
9a2c84d68c Merge pull request #161 from tpetazzoni/gcc8-fixes
Gcc8 fixes
2018-05-18 06:20:16 +02:00
Thomas Petazzoni
8e5af129ff faketime.c: fix shared_objs[] array size
shared_objs[] will contain the concatenation of sem_name and shm_name,
which are both 4096 bytes long, and shared_objs[] itself is only 4096
bytes long. This causes a build failure with gcc 8.x:

faketime.c: In function 'main':
faketime.c:289:45: error: '%s' directive output may be truncated writing up to 4095 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
     snprintf(shared_objs, PATH_BUFSIZE, "%s %s", sem_name, shm_name);
                                             ^~             ~~~~~~~~
faketime.c:289:5: note: 'snprintf' output between 2 and 8192 bytes into a destination of size 4096
     snprintf(shared_objs, PATH_BUFSIZE, "%s %s", sem_name, shm_name);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This commit fixes that by enlarging the shared_objs[] array to twice
the of PATH_BUFSIZE, plus one byte for the space.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2018-05-17 23:35:08 +02:00
Thomas Petazzoni
096c11b563 libfaketime.c: fix uninitialized 'result' use
The pthread_cond_timedwait_common() function declares a 'result'
variable, but in some code paths, it may be returned without being
initialized. This commit fixes that by initializing the variable.

Fixes:

libfaketime.c: In function 'pthread_cond_timedwait_common':
libfaketime.c:2534:7: error: 'result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   int result;
       ^~~~~~

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2018-05-17 23:31:01 +02:00
Thomas Petazzoni
9bfae502d1 libfaketime.c: fix pthread_cleanup_push() build failure
gcc 8.x introduced stricter checking on types, and the trick to cast
pthread_mutex_unlock() into a function acceptable for
pthread_cleanup_push() no longer builds:

libfaketime.c: In function 'fake_clock_gettime':
libfaketime.c:2039:24: error: cast between incompatible function types from 'int (*)(pthread_mutex_t *)' {aka 'int (*)(union <anonymous> *)'} to 'void (*)(void *)' [-Werror=cast-function-type]
   pthread_cleanup_push((void (*)(void *))pthread_mutex_unlock, (void *)&time_mutex);
                        ^

Rather than continuing to hack around, introduce an auxilliary
function with the type expected by pthread_cleanup_push().

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2018-05-17 23:31:01 +02:00
Thomas Petazzoni
0d964363a4 libfaketime.c: fix strncpy() issues raised by gcc 8.x
gcc 8.x introduced stricter checking on strncpy(), and causes the
following build failures:

libfaketime.c: In function 'fake_clock_gettime.part.4':
libfaketime.c:2134:7: error: 'strncpy' specified bound 256 equals destination size [-Werror=stringop-truncation]
       strncpy(user_faked_time, tmp_env, BUFFERLEN);
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libfaketime.c:2134:7: error: 'strncpy' specified bound 256 equals destination size [-Werror=stringop-truncation]
       strncpy(user_faked_time, tmp_env, BUFFERLEN);
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libfaketime.c: In function 'ftpl_init':
libfaketime.c:1884:12: error: 'strncpy' specified bound 1024 equals destination size [-Werror=stringop-truncation]
     (void) strncpy(ft_spawn_target, getenv("FAKETIME_SPAWN_TARGET"), 1024);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libfaketime.c:1945:5: error: 'strncpy' specified bound 8192 equals destination size [-Werror=stringop-truncation]
     strncpy(user_faked_time_fmt, tmp_env, BUFSIZ);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libfaketime.c: In function 'ftpl_init':
libfaketime.c:1884:12: error: 'strncpy' specified bound 1024 equals destination size [-Werror=stringop-truncation]
     (void) strncpy(ft_spawn_target, getenv("FAKETIME_SPAWN_TARGET"), 1024);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libfaketime.c:1945:5: error: 'strncpy' specified bound 8192 equals destination size [-Werror=stringop-truncation]
     strncpy(user_faked_time_fmt, tmp_env, BUFSIZ);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This commit fixes that by making sure we keep one final byte for the
nul terminator, as suggested by
https://github.com/wolfcw/libfaketime/issues/150.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2018-05-17 23:31:01 +02:00
Wolfgang Hommel
8107db7849 Improved parsing error logging 2018-05-03 19:36:47 +02:00
Wolfgang Hommel
c9473def03 Merge pull request #146 from FeepingCreature/feature/wait-ms
Add FAKETIME_WAIT_MS to force pthread_cond_timedwait to wait x ms instead of what its parameters say.
2018-02-20 06:29:18 +01:00
Wolfgang Hommel
baeed314cf Merge pull request #148 from dkg/use-CPPFLAGS
Use CPPFLAGS during compilation
2018-02-20 06:22:38 +01:00
Daniel Kahn Gillmor
90727b7d19 Use CPPFLAGS during compilation
CPPFLAGS is traditionally used to include C preprocessor flags.  While
faketime doesn't apply anything to CPPFLAGS directly, it is good form
to adopt standard settings that might be externally applied.
2018-02-19 14:20:31 -08:00
Wolfgang Hommel
8c22d91057 Merge pull request #147 from dkg/fixalpha
fix gettimeofday() on alpha (see https://bugs.debian.org/890813)
2018-02-19 20:41:23 +01:00
Michael Cree
a5d7f5b1cc fix gettimeofday() on alpha (see https://bugs.debian.org/890813)
In https://bugs.debian.org/890813, Michael Cree <mcree@orcon.net.nz>
reports:

>  The faketime package fails to work correctly on the Alpha
>  architecture. This failure of faketime to work correctly is the
>  reason for the mbedtls FTBFS, which uses faketime in its test
>  suite [1].
>
>  Consider the following test program (which I call "time-test"):
>
>  #include <stdio.h>
>  #include <sys/time.h>
>  #include <unistd.h>
>
>  int main(void)
>  {
>      struct timeval tv;
>
>      for (int j=0; j<5; j++) {
>          usleep(10000);
>          gettimeofday(&tv, NULL);
>          printf("s=%ld    us=%ld\n", tv.tv_sec, tv.tv_usec);
>      }
>      return 0;
>  }
>
>  When run it produces output like:
>
>  s=1519025990    us=838219
>  s=1519025990    us=848965
>  s=1519025990    us=859711
>  s=1519025990    us=870456
>  s=1519025990    us=881202
>
>  But when run as (with faketime built in its source directory):
>
>  LD_PRELOAD=faketime-0.9.7/src/libfaketime.so.1 FAKETIME="-1d" ./time-test
>
>  the output is:
>
>  s=2199023743604    us=0
>  s=2199023657204    us=0
>  s=2199023570804    us=0
>  s=2199023484404    us=0
>  s=2199023398004    us=0
>
>  which is definitely not correct.
>
>  The reason for the incorrect behaviour is that there are two
>  gettimeofday symbols in libc on Alpha and the dlsym() call to link
>  to the gettimeofday() is picking up the function with the wrong ABI.
>  I attach a patch to fix that.  Faketime built with the attached
>  patch works correctly and with a fixed faketime the mbedtls source
>  package builds to completion on Alpha.
2018-02-19 11:30:11 -08:00
Mathis Beer
229ce22fbc Add FAKETIME_WAIT_MS to force pthread_cond_timedwait to wait x ms instead of what its parameters say.
This prevents us from getting stuck in place when the timestamp changes.
2018-02-19 10:26:26 +01:00
Wolfgang Hommel
0487e41c34 Merge pull request #141 from dkg/speling
fix spelling :)
2018-01-16 20:25:11 +01:00
Daniel Kahn Gillmor
b3a2667e9f fix spelling :) 2018-01-16 14:21:36 -05:00
Wolfgang Hommel
6a4d1cc84e Merge pull request #140 from jprjr/musl-compat
Only use dlvsym on glibc systems
2018-01-14 19:55:09 +01:00
John Regan
87d2a67401 Only use dlvsym on glibc systems
This makes libfaketime compatible with musl libc, and likely others.
2018-01-14 12:31:39 -06:00
Wolfgang Hommel
3881dd2ebf Merge pull request #138 from mliertzer/fake_pthread
Implement fix for pthread_cond_timedwait
2018-01-02 12:23:57 +01:00
Matthias Liertzer
fb91c4fcde Implement a fix for pthread_cond_timedwait with faketime
pthread_cond_timedwait takes an absolute time as an argument, which
the function directly passes on to the kernel via the futex
syscall. In an application this absolute time argument is calculated
via the fake times provided by libfaketime. Since the kernel has no
knowledge of the fake time, pthread_cond_timedwait must be redefined
such that it converts the fake time back to real time before passing
it on.
2018-01-02 02:22:59 +01:00
Matthias Liertzer
ab7a2302f2 Rename compat library enumeration 2018-01-02 01:42:41 +01:00
Matthias Liertzer
d117ad79a2 Fix spelling of positive 2018-01-02 01:42:41 +01:00
Matthias Liertzer
5235f6f417 Make sure that DONT_FAKE_MONOTONIC=1 affects all monotonic clocks 2018-01-02 01:40:10 +01:00
Matthias Liertzer
3376334dfc Hide ftpl_init and ft_cleanup from exported functions 2018-01-02 00:16:23 +01:00
Wolfgang Hommel
bb635e4367 Treat unknown clock_ids like CLOCK_REALTIME (experimental) 2017-11-30 20:28:06 +01:00
Wolfgang Hommel
a79f5330f4 Fix #114 as suggested by @niraizik 2017-11-17 20:27:58 +01:00
Wolfgang Hommel
0dee4f88e0 Updated OSX packaging info for v0.9.7 2017-11-14 20:37:55 +01:00
Wolfgang Hommel
c9a681c3e3 Preparations for 0.9.7 release 2017-11-14 20:28:32 +01:00
Wolfgang Hommel
4ce283594f Merge pull request #122 from jasonsoooz/patch-1
Mention possibility of running java in README
2017-10-01 10:06:43 +02:00
Jason Soo
d42a2a9ec7 Mention possibility of running java in README 2017-09-30 15:51:39 +10:00
Wolfgang Hommel
5d41d41da8 Merge pull request #119 from dariaphoebe/namefix-1
fix my name
2017-07-25 07:15:29 +02:00
Daria Phoebe Brashear
46aa5773c7 fix my name 2017-07-24 16:42:38 -04:00
Wolfgang Hommel
3fe3cf1536 Updated Homebrew formula 2017-07-13 18:35:26 +02:00
Wolfgang Hommel
b23fbd5c5e Pass existing null pointers in select() 2017-06-08 19:50:34 +02:00
Wolfgang Hommel
fa88a28c4d Avoid null pointer dereference in select() 2017-06-07 20:37:12 +02:00
Wolfgang Hommel
6e4037768a early preparations for 0.9.7 release 2017-05-19 21:51:25 +02:00
Wolfgang Hommel
fa91edb0a3 Started to integrate mpareja's CLOCK_BOOTTIME patch 2017-05-19 19:14:58 +02:00
Wolfgang Hommel
725c80673c Updated for macOS Sierra 2017-05-19 19:05:12 +02:00
Wolfgang Hommel
4a9c93475e Fix macro-related compiler warnings 2017-05-19 18:55:11 +02:00
Wolfgang Hommel
842c2e4269 Merge branch 'macos-sierra' 2017-05-19 18:51:01 +02:00
Wolfgang Hommel
af0b2f85a7 Merge pull request #113 from umitanuki/support-select
Support select call
2017-05-19 18:22:14 +02:00
Hitoshi Harada
120f6898f4 Support select call 2017-05-18 17:52:03 -07:00
Wolfgang Hommel
3c0ce9c885 Merge pull request #108 from manchicken/osx-fix
Adding some code to make OSX build properly.
2017-02-28 19:19:51 +01:00
Michael D. Stemle, Jr
2c78776aaf Adding some code to make OSX build properly. 2017-02-28 10:19:32 -05:00
Balint Reczey
5dd65efa14 Merge pull request #107 from jwilk/spelling
Fix typo in README
2017-02-28 13:28:44 +01:00
Jakub Wilk
d1fdfb1950 Fix typo in README 2017-02-28 12:22:50 +01:00
Wolfgang Hommel
57b098c98a Merge pull request #103 from andir/master
Disable the non-null compare warning/error.
2016-12-20 19:46:02 +01:00
Andreas Rammhold
47e958b753 Disable the non-null compare warning/error.
We rely on the provided local library definitions for the hooked
functions which in some cases (GCC >6) carry a non-null-attribute flag
which causes compile errors on `!= NULL` checks.
2016-12-20 19:30:14 +01:00
Wolfgang Hommel
1d5976d1ab Merge pull request #102 from infinity0/patch-1
Document the faking of filesystem timestamps
2016-12-09 20:27:20 +01:00
Ximin Luo
582ae36e1d Document the faking of filesystem timestamps
It's hard to notice the tiny reference to `fstat(2)` amongst all the text about the system clock. This is a significant behaviour that is very surprising, and the default setting (on) messes with buildsystems in a counter-intuitive way. Also document how to switch it off.
2016-12-09 00:24:05 +01:00
Wolfgang Hommel
8fb6330a28 Fixes compilation issues on macOS Sierra 2016-10-30 13:25:38 +01:00
Wolfgang Hommel
da778084e5 Merge pull request #92 from hbuchsbaum/work
do not destroy environment when parsing FAKETIME_ONLY_CMDS
2016-06-27 08:54:00 +02:00
Helmut Buchsbaum
9220b5c58e do not destroy environment when parsing FAKETIME_ONLY_CMDS
Using strtok_r directly on environment string changes the environment
e.g. for subprocesses and thus changes the FAKETIME_ONLY_CMDS
setting for the subprocess to the first command only.

Avoid this by copying the environment string before parsing.
2016-06-27 08:13:33 +02:00
Wolfgang Hommel
b68f2820c4 Merge pull request #91 from jwilk/spelling
Fix spelling mistakes
2016-06-02 21:51:55 +02:00
Jakub Wilk
4786b94f8e Fix grammar in README
"allow" is a transitive verb, which requires an object,
so "allow to <verb>" is ungrammatical.
2016-06-02 21:36:54 +02:00
Jakub Wilk
0d790dabb6 Fix license name in README
There's no such thing as "GNU Public License";
GPL stands for "General Public License".
2016-06-02 21:31:43 +02:00
Jakub Wilk
6de283f621 Fix typos 2016-06-02 21:31:42 +02:00
Wolfgang Hommel
7f907c32fc Merge pull request #86 from udda/udda-patch-1
Call printf only once in usage(char*)
2016-03-15 12:34:05 +01:00
Wolfgang Hommel
0af6be50cb Merge pull request #87 from steffen-kiess/fix-init
Do not fake times during ftpl_init()
2016-03-15 12:32:56 +01:00
Steffen Kieß
b193c95475 Do not fake times during ftpl_init()
Some libc functions called by ftpl_init() might call fstat() or a similar
function which is intercepted by libfaketime. In this case, the time should
not be faked because the static variables are not yet set up properly.

See https://github.com/wolfcw/libfaketime/issues/72 for further information.
2016-03-15 10:46:05 +01:00
Mario Cianciolo
d95d96f5ea Call printf only once in usage(char*)
Replace multiple calls to printf with one single call, passing the entire string at once.
I think this is faster and more readable.
2016-03-07 17:47:23 +01:00
Wolfgang Hommel
904cc5007d Merge pull request #84 from vavrusa/master
Fixed coarse clock on platforms that don't support them
2016-01-29 17:35:15 +01:00
Marek Vavrusa
811b7916ad Fixed coarse clock on platforms that don't support them
having same number for coarse and non-coarse clock
leads to duplicate case values in switches
2016-01-29 11:20:39 +00:00
Wolfgang Hommel
74425d76e1 Updated regarding coarse clocks 2015-12-28 18:46:39 +01:00
Wolfgang Hommel
3a26d7b3bb Merge branch 'azat-coarse' into develop 2015-12-28 17:55:32 +01:00
Azat Khuzhin
4398deaa3d Raw support for COARSE clocks 2015-12-28 16:54:55 +03:00
Georg Koppen
18f5ec0671 Allow more than one command being skipped 2015-06-04 18:42:20 +02:00
Wolfgang Hommel
638a535b5f Merge pull request #65 from kilobyte/master
Fix build failure on x32 (printf warnings).
2015-03-09 18:48:37 +01:00
Adam Borowski
cc4c1c3a29 Fix build failure on x32 (printf warnings).
On x32, time_t is 64-bit to avoid Y2038 problems.  This doesn't play well
using printf("%ld"), and -Werror turns this into a build failure.
2015-03-09 08:39:06 +01:00
Wolfgang Hommel
6357820d52 Added hint about library search paths 2015-02-19 20:24:07 +01:00
Jon Ringle
64cb35857c Merge branch 'develop' (Jon Ringle's patches)
Merge pull request #55 from ringlej/feature/fix-FAKETIME-cache

Conflicts:
	src/libfaketime.c
2015-02-08 17:44:50 +01:00
Wolfgang Hommel
28d0acfedb Merge pull request #62 from dubek/fix-mt-build
Fix libfaketimeMT build to define PTHREAD
2015-01-08 11:24:03 +01:00
Dov Murik
3ed13f498c Fix libfaketimeMT build to define PTHREAD 2015-01-07 17:38:00 -05:00
Erich E. Hoover
afbb1f20c2 Fix possible infinite loop on construction. 2014-12-17 21:40:13 +01:00
Balint Reczey
68772ec36a Hide internal functions
Also remove unused fake_time().
2014-12-11 08:13:40 +01:00
Balint Reczey
3bb30f74b3 Use constructor attribute at _declaration_ 2014-12-11 08:06:28 +01:00
Erich E. Hoover
0bde083556 Make sure that the constructor has been called when the loader chose to load another constructor first. 2014-12-11 08:05:21 +01:00
Wolfgang Hommel
10b479cf29 Merge pull request #59 from mac-joker/master
New features: custom timestamp file and cache managment
2014-11-21 08:54:36 +01:00
Joker
75896bdd32 added runtime cache manipulation: change duration and active state with environment variables 2014-11-17 10:42:15 +01:00
Joker
6c207c9c68 Custom timestamp filename added: ~/.faketimerc alternative 2014-11-17 10:28:20 +01:00
Balint Reczey
527478d318 Merge pull request #58 from ltfetch/master
Wait for all transitive child processes to exit
2014-10-28 00:00:57 +01:00
ltfetch
48ef50f6c3 use pipe to block process exit until all transitive children exit 2014-10-26 20:40:24 -05:00
ltfetch
035add4eff don't leak pipe fd 2014-10-27 01:10:13 +00:00
Wolfgang Hommel
455261985d Merge pull request #55 from ringlej/feature/fix-FAKETIME-cache
Feature/fix faketime cache
2014-08-26 22:37:56 +02:00
Wolfgang Hommel
e680ca9bce Merge pull request #54 from ringlej/feature/sem_timedwait
Add support to fake sem_timedwait
2014-08-26 22:33:21 +02:00
Jon Ringle
1c5a717528 Reset ftpl_starttime when setting new relative FT_START_AT time
Signed-off-by: Jon Ringle <jringle@gridpoint.com>
2014-08-26 13:23:59 -04:00
Jon Ringle
bdd0f0aea9 Don't parse user_faked_time if it hasn't changed
Signed-off-by: Jon Ringle <jringle@gridpoint.com>
2014-08-26 11:24:18 -04:00
Jon Ringle
7c26cffac6 Re-evaluate FAKETIME environment when cache expires
When the cache expires, the FAKETIME environment does not get re-evaluated
if FAKETIME value changes. This used to work on libfaketime-0.9.1, but was
broken at some point afterwards. This fixes this problem

Signed-off-by: Jon Ringle <jringle@gridpoint.com>
2014-08-26 11:24:13 -04:00
Jon Ringle
cac3dc732a Add support to fake sem_timedwait
Signed-off-by: Jon Ringle <jringle@gridpoint.com>
2014-08-26 11:16:35 -04:00
Wolfgang Hommel
c7d7eeb49d Merge pull request #52 from joyent/man-exclude-monotonic
docs: add --exclude-monotonic to man page.
2014-08-18 09:27:03 +02:00
Julien Gilli
cae9387908 docs: add --exclude-monotonic to man page.
This was missing from PR #49.
2014-08-17 22:17:23 -07:00
Wolfgang Hommel
a6c8bb4636 Merge pull request #50 from joyent/sunos-smartos-support
Make libfaketime build, run and pass tests on SmartOS.
2014-08-07 19:46:48 +02:00
Julien Gilli
95b70c7acc Make libfaketime build, run and pass tests on SmartOS.
Since SmartOS is close to SunOS, it's possible that these changes make
libfaketime build and run on other SunOS-like platforms.

These changes were tested on MacOS X and Ubuntu 12.04, and no regression
appeared during testing.
2014-08-06 11:29:02 -07:00
Wolfgang Hommel
841b782a4c Started adding changes since v0.9.6 release 2014-07-26 09:56:41 +02:00
Wolfgang Hommel
03da54787c Merge pull request #49 from joyent/dont-fake-monotonic-clocks
Add --exclude-monotonic command line option.
2014-07-26 09:50:55 +02:00
Julien Gilli
d19da98bb4 Add --exclude-monotonic command line option.
--exclude-monotonic prevents faketime from overriding
the clock with id CLOCK_MONOTONIC when using clock_gettime.

Add DONT_FAKE_MONOTONIC env variable to libfaketime that
has the same effect.

Add functional test for DONT_FAKE_MONOTONIC support.
2014-07-25 15:43:38 -07:00
Gerardo Malazdrewicz
3bed636a41 Debian Bug#753460: Updated fix for 699599
This patch checks if __clock_gettime is available, and if not,
it uses clock_gettime instead.

Maybe this patch can be improved using dlvsym.
2014-07-19 11:07:37 +02:00
Wolfgang Hommel
70aa6b394d Preparations for 0.9.6 release 2014-06-07 17:04:02 +02:00
Antonio Terceiro
1faf137f72 fix handling of existing LD_PRELOAD in environment
This patch fixes handling of the string length when composing an updated
 LD_PRELOAD that includes both the previous value and the entry for
 libeatmydata.
2014-06-07 16:50:05 +02:00
Kees Cook
7d1a8307e1 pass through exit codes when possible, otherwise report
failure and full waitpid status and exit with a failure.
2014-06-07 16:42:46 +02:00
Wolfgang Hommel
7fdcd1adaf Merge branch 'develop' 2014-02-14 15:59:26 +01:00
Wolfgang Hommel
c3e4760338 Updated documentation for v0.9.6 & Makefile consolidation 2014-02-14 15:59:06 +01:00
Wolfgang Hommel
740e2858dc OSX autoselection in primary Makefile 2014-02-13 12:33:00 +01:00
Han Jiang
1b6cdf3d0f valgrind complains memory leak due to lack of sem_close() 2014-01-26 17:18:21 +01:00
Han Jiang
a34c2bd8c3 Typo when showing version information 2014-01-24 15:33:39 +01:00
Wolfgang Hommel
b28b5c3a5d Update of the Homebrew formula and docs 2013-11-15 23:37:31 +01:00
Wolfgang Hommel
106818614d Minor source code style fixes 2013-11-07 19:35:18 +01:00
Wolfgang Hommel
e653c388bf Minor updates to debug msgs and docs related to filter commands 2013-10-30 21:47:56 +01:00
Wolfgang Hommel
64519e28e0 Merge pull request #37 from rbalint/filter-commands
Filter commands
2013-10-30 13:31:05 -07:00
Balint Reczey
0d04c87755 Constify progname 2013-10-28 23:02:21 +01:00
Balint Reczey
c2ca839b6a Limit faking based on command name 2013-10-28 22:58:03 +01:00
Wolfgang Hommel
368f58c0f8 Added installation via Fink on OSX 2013-10-27 21:53:19 +01:00
Wolfgang Hommel
04ae576541 Packaging details, some for Linux 2013-10-27 11:33:16 +01:00
Wolfgang Hommel
2d0cc5d86b Packaging details, starting with OS X 2013-10-27 10:24:20 +01:00
Wolfgang Hommel
3a8a2b0351 fix value for kFreeBSD 2013-10-20 21:56:56 +02:00
Balint Reczey
1f938d9642 Use SIGUSR1 instead of SIGRTMIN in tests
This will probably fix compilation on Debian GNU/Hurd
2013-10-20 17:28:29 +02:00
Balint Reczey
5fb86ae178 Define CLOCK_MONOTONIC_RAW where it is not present
This fixes compilation on Debian GNU/kFreeBSD
2013-10-20 17:16:20 +02:00
Balint Reczey
27a4e3a7ad Fall back to default timer_settime() & timer_gettime() if no versioned version is present 2013-10-20 16:53:40 +02:00
Balint Reczey
23200c4321 Fix tests on libc 2.17 2013-10-20 16:43:10 +02:00
Wolfgang Hommel
76edab7837 Fix -lrt issues in Makefile 2013-10-18 17:45:57 +02:00
Wolfgang Hommel
3ac3286356 Do not use -ldl -lm when linking the wrapper 2013-10-16 20:08:57 +02:00
Balint Reczey
bb278fc159 Define config file parsing related variables in smaller scopes 2013-10-16 13:42:25 +02:00
Ray Donnelly
1bb5ee3920 Ensure late calls return correct results
.. the cache expiration would reset to using +0 as
the faketime ignoring the FAKETIME env var.
2013-10-16 11:24:26 +02:00
Balint Reczey
d1e7781db6 Add nanosecond resolution to file stat functions
Based on Ray Donnelly's idea in ddf7f4ab35
2013-10-16 10:56:45 +02:00
Balint Reczey
9c2b1a6295 Drop unused code 2013-10-16 10:19:25 +02:00
Balint Reczey
3a2d8e2ccc Enable faking internal calls on OS X
Tested on OS X 10.8 with the test suite
2013-10-16 10:00:51 +02:00
Balint Reczey
c719a977a7 Finish safe faking of internal calls 2013-10-16 09:33:50 +02:00
Balint Reczey
c1cc101f91 Fake __clock_gettime() and similar calls using __... calls
This breaks potential infinite loops.
2013-10-16 09:16:05 +02:00
Wolfgang Hommel
cd3597174c Remove second '-lrt' on linker calls to fix 32-bit building issue 2013-10-16 08:11:02 +02:00
Wolfgang Hommel
458c6d693d fix directory permissions on install 2013-10-13 18:25:52 +02:00
Wolfgang Hommel
a8f8378e77 MacPorts changeset 112093 by ryandesign 2013-10-13 12:24:52 +02:00
Wolfgang Hommel
4c23ee2730 Updated TODO list 2013-10-13 11:19:30 +02:00
Wolfgang Hommel
b659b76c0c Updated installation notes for OS X 2013-10-11 23:37:50 +02:00
Wolfgang Hommel
088eb66b24 Added credits for MacPorts Portfile design and build cleanup 2013-10-11 16:42:38 +02:00
Wolfgang Hommel
0208015a9b set library versions on OSX as suggested by ryandesign at MacPorts 2013-10-11 16:41:01 +02:00
Wolfgang Hommel
a0987efa5c renamed library name from libfaketime.dylib.1 to libfaketime.1.dylib based on Apple design guidelines. Thanks to ryandesign at MacPorts 2013-10-11 16:33:37 +02:00
Wolfgang Hommel
ed9009495b Changes to Makefiles by ryandesign at MacPorts, changeset 112062 2013-10-11 16:29:11 +02:00
Wolfgang Hommel
cee051c2bc avoid unused variables warnings 2013-10-06 13:12:39 +02:00
Wolfgang Hommel
a64b04c441 Added note about how to test without installation 2013-10-05 18:01:38 +02:00
Wolfgang Hommel
ad012825de introducing rudimentary multilib installation path support 2013-10-05 17:53:58 +02:00
Wolfgang Hommel
858eb36e4f Preliminary multi-arch support for faketime wrapper when -DMULTI_ARCH is set 2013-10-05 11:16:12 +02:00
Balint Reczey
7d13d305c9 Add -Wextra and -Werror CFLAGS and also fix compile errors 2013-10-04 22:54:07 +02:00
Balint Reczey
bce065d17d fix missing break;-s 2013-10-04 22:34:12 +02:00
Balint Reczey
8906bfda8f rework endianness handling code to avoid aliasing warnings 2013-10-04 22:26:54 +02:00
Wolfgang Hommel
be2b7c0a0c fix compiler warning with -Wunused-result enabled 2013-10-04 11:48:54 +02:00
Wolfgang Hommel
7c2371e4a8 fix compiler warning with -Wstrict-overflow enabled 2013-10-04 11:45:55 +02:00
Wolfgang Hommel
a7858cb1dd fixed for gcc > 4.6 2013-10-04 10:42:27 +02:00
Wolfgang Hommel
1183cece14 deliberately ignore return values in test program 2013-10-04 10:39:09 +02:00
Wolfgang Hommel
4586eef851 Documentation on building 32-bit libraries on 64-bit platforms 2013-10-04 10:24:23 +02:00
Wolfgang Hommel
d4ffebbf98 Added note about building 32-bit libraries/binaries 2013-10-04 10:22:11 +02:00
Wolfgang Hommel
cb60b68e02 add default PREFIX to main Makefile.OSX 2013-10-03 18:24:27 +02:00
Wolfgang Hommel
782d3585b2 try multiple paths to find libfaketime.dylib.1 on OSX 2013-10-03 18:08:44 +02:00
Wolfgang Hommel
0b1845c36d Update default PREFIX on OSX 2013-10-03 17:58:01 +02:00
Wolfgang Hommel
6dcde9c4d9 Ensure target directory exists 2013-10-03 17:38:39 +02:00
Wolfgang Hommel
bbd2ee58f2 Makefile for OSX man page installation 2013-10-03 17:30:12 +02:00
Wolfgang Hommel
9d669f7528 ensure temporary destroot binpath exists 2013-10-03 17:28:11 +02:00
Wolfgang Hommel
a7297ba25c create bindir during installation if it does not yet exist (fixed) 2013-10-03 17:26:38 +02:00
Wolfgang Hommel
9d85b5a783 create bindir during installation if it does not yet exist 2013-10-03 17:22:39 +02:00
Balint Reczey
7c9a327919 Fix parsing timestamps containing only i... or x... 2013-10-03 15:42:53 +02:00
Wolfgang Hommel
6fafd23f8a fix -lrt call for faketime binary linking 2013-10-03 11:44:51 +02:00
Wolfgang Hommel
3debc093e4 fix -lrt call for library linking 2013-10-03 11:31:57 +02:00
Wolfgang Hommel
f21318289f fix missing linker run 2013-10-03 11:23:41 +02:00
Wolfgang Hommel
47e8fbef18 Merge branch 'develop' 2013-10-02 15:40:02 +02:00
Wolfgang Hommel
f0f8282817 No -DFAKE_TIMERS on OSX 2013-10-02 15:39:43 +02:00
Wolfgang Hommel
338ec2e3df Merge branch 'develop' 2013-10-02 15:36:07 +02:00
Wolfgang Hommel
bb87fb619e improved readability of test script output 2013-10-02 15:32:46 +02:00
Wolfgang Hommel
b9ba8ab444 uniform test output style 2013-10-01 13:15:34 +02:00
Wolfgang Hommel
8c1ba7899d improved output readability for timer tests 2013-10-01 13:12:34 +02:00
Wolfgang Hommel
c59e816539 Ensure that -lrt is passed to compiler/linker for faketime.c 2013-10-01 12:35:08 +02:00
Balint Reczey
50c6ad4dc2 Provide timer related functions compatible with GLIBC 2.2 and >= 2.3.3 [pr32 @8615959] 2013-09-30 16:36:13 +02:00
Wolfgang Hommel
cda19e4cb7 Updated gitignore: Ignore new faketime binary wrapper 2013-09-05 16:27:58 +02:00
Wolfgang Hommel
27468e804d Updated gitignore: Ignore new faketime binary wrapper 2013-09-05 14:37:05 +02:00
Wolfgang Hommel
e8846e6245 Merge branch 'master' into develop 2013-09-05 11:17:34 +02:00
Wolfgang Hommel
ae6af2eea9 fixed missing blank line before last timetest call 2013-09-05 11:16:57 +02:00
Balint Reczey
92d37e79b9 Use clock_gettime() to fake ftime() and time() [rbalint/pr31] 2013-09-05 11:15:51 +02:00
Wolfgang Hommel
65cccbbd45 Merge branch 'master' of https://github.com/wolfcw/libfaketime 2013-09-05 10:28:27 +02:00
Wolfgang Hommel
c2087711eb Unbalanced parenthesis in libfaketime.c (#30, a168290) 2013-09-05 10:27:11 +02:00
Wolfgang Hommel
2f9377790c Applied libfaketime name change and style guide 2013-09-05 10:27:11 +02:00
Wolfgang Hommel
51b1a2eba4 Wrap new and experimental features in #ifdef FAKE_SLEEP FAKE_TIMERS 2013-09-05 10:27:11 +02:00
Wolfgang Hommel
98a0cacf3a Updated manpage for upcoming 0.9.5 2013-09-05 10:27:11 +02:00
Balint Reczey
3d63dd33e5 Fix rouding issues, Add reminder to rewrite faking time(), gettimeofday, etc. [rbalint pr29] 2013-09-05 10:27:11 +02:00
Balint Reczey
545685e5a8 Use nanosleep() in faked sleep() and usleep() to avoid rounding issues [rbalint/pr28] 2013-09-05 10:26:57 +02:00
Wolfgang Hommel
e029bf883d Merge branch 'master' into develop 2013-09-04 17:23:29 +02:00
Wolfgang Hommel
6fb53d08dd Unbalanced parenthesis in libfaketime.c (#30, a168290) 2013-09-04 17:22:52 +02:00
Wolfgang Hommel
7fd7051b22 enable FAKE_TIMERS for development branch 2013-09-04 14:23:23 +02:00
Wolfgang Hommel
e09350e374 Applied libfaketime name change and style guide 2013-09-04 14:21:13 +02:00
Wolfgang Hommel
4c508fc375 Wrap new and experimental features in #ifdef FAKE_SLEEP FAKE_TIMERS 2013-09-04 14:20:43 +02:00
Wolfgang Hommel
a9898e91b0 Updated manpage for upcoming 0.9.5 2013-09-04 13:21:41 +02:00
Wolfgang Hommel
afa133ee7f Fix rouding issues, Add reminder to rewrite faking time(), gettimeofday, etc. [rbalint pr29] 2013-09-04 13:10:26 +02:00
Wolfgang Hommel
259a9a0966 Use nanosleep() in faked sleep() and usleep() to avoid rounding issues [rbalint/pr28] 2013-09-04 13:05:04 +02:00
Wolfgang Hommel
3f4563fd92 README.developers added; editor modelines in libfaketime.c 2013-09-04 12:50:00 +02:00
Wolfgang Hommel
e0248e9f4d merge of rbalint/fake-timers 2013-09-03 17:13:16 +02:00
Wolfgang Hommel
cdab1d089e more cleanup, indentation, C style etc. 2013-09-03 13:42:10 +02:00
Wolfgang Hommel
6e789eda25 indentation and other style issues 2013-09-03 13:23:42 +02:00
Wolfgang Hommel
c4a3671219 Merge branch 'fake-poll' into integration 2013-09-03 11:27:52 +02:00
Wolfgang Hommel
227ebff470 testing Makefile adapted for OSX 2013-09-02 14:38:43 +02:00
Wolfgang Hommel
568fef7228 Makefiles and test suite improved for OS X 2013-09-02 14:32:44 +02:00
Wolfgang Hommel
89f58cd720 Updated documentation and credits 2013-09-02 14:09:32 +02:00
Balint Reczey
d69e6557da Fake poll() and ppoll() 2013-09-01 19:28:53 +02:00
Balint Reczey
5d9429257b Fix typo in README 2013-09-01 18:22:47 +02:00
Wolfgang Hommel
aef788c795 Revert "merged rbalint's pr27"
This reverts commit 5283614bec, reversing
changes made to 4ecef4db08.
2013-09-01 16:04:21 +02:00
Wolfgang Hommel
5283614bec merged rbalint's pr27 2013-09-01 15:59:45 +02:00
Balint Reczey
4ecef4db08 Sleep() and alarm() still could apply faking several times 2013-08-31 20:32:45 +02:00
Balint Reczey
d92829adb1 Fake clock_get_time() on __APPLE__ 2013-08-30 20:28:10 +02:00
Balint Reczey
5bef478921 Fix compilation on __APPLE__ 2013-08-30 18:54:05 +02:00
Balint Reczey
9e36de18fb Default to clang on __APPLE__ to support thread local variables 2013-08-30 18:39:28 +02:00
Wolfgang Hommel
ddfebc8645 Improved OS X support
Conflicts:
	src/libfaketime.c
2013-08-30 18:18:51 +02:00
Balint Reczey
564f6e0942 Prevent applying time faking mote than once 2013-08-30 18:08:30 +02:00
Balint Reczey
e2882ef56c Don't use a = {b,c} assignment 2013-08-29 11:35:33 +02:00
Balint Reczey
3b498bf24f Fix missing clock_gettime() related #defines on __APPLE__ 2013-08-29 11:21:45 +02:00
Balint Reczey
59a9a36056 Assume system being little endian on __APPLE__ 2013-08-29 11:10:47 +02:00
Wolfgang Hommel
cde288fb0e fix so ./faketime is not a library 2013-08-29 10:59:57 +02:00
Wolfgang Hommel
c84c37d137 guard against broken dlsym by Toni G 2013-08-29 10:23:26 +02:00
Wolfgang Hommel
ccd43c21cd fix so ./faketime is not a library 2013-08-29 10:17:26 +02:00
Wolfgang Hommel
eff33e1b5b Revert a2c8ac6..8b67256
This rolls back to commit a2c8ac6687.
2013-08-29 10:15:15 +02:00
Wolfgang Hommel
8b67256736 Revert 30dd22e..bdac73e
This rolls back to commit 30dd22e157.
2013-08-29 10:08:32 +02:00
Wolfgang Hommel
bdac73e3b9 failed attempt to get it working on OS X 2013-08-29 10:05:45 +02:00
Wolfgang Hommel
ceca4b2fd7 Merge pull request #26 from rbalint/fake-sleep
Fake sleep
2013-08-29 00:24:01 -07:00
Balint Reczey
6fa8be96fc Fake sleep() and friends
This speeds up testing ;-)
2013-08-28 18:41:54 +02:00
Balint Reczey
6f83e225b1 Fix calculating faked time when user rate is not set 2013-08-28 14:41:49 +02:00
Balint Reczey
15d621d3aa Use global Faketime start time when started using "faketime" 2013-08-28 14:41:49 +02:00
Balint Reczey
77eb253136 Start system time from the same global clocks in every processes after replaying a file 2013-08-28 14:41:49 +02:00
Balint Reczey
7931cd180c Break loop of clock_gettime()-s when stopping replayin timestamps from file 2013-08-28 14:41:48 +02:00
Balint Reczey
6333941bed Fix faketime_common.h's description 2013-08-28 14:41:48 +02:00
Balint Reczey
9c37b38b65 Fake CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW clocks 2013-08-28 14:41:48 +02:00
Balint Reczey
4c253b3865 Speed up/slow down per process timers 2013-08-28 14:41:48 +02:00
Balint Reczey
8bb28faa91 Save faked timestamps to file, load faked timestamps from file
The files can be set using FAKETIME_SAVE_FILE and FAKETIME_LOAD_FILE
environment variables respectively.
2013-08-28 14:41:48 +02:00
Balint Reczey
7caed1a0c8 Fix typo setting wrong value for startup time on __APPLE__ 2013-08-28 14:38:11 +02:00
Wolfgang Hommel
30dd22e157 Merging Balint's files 2013-08-25 10:42:36 +02:00
Balint Reczey
ebf08018ff Refactor time faking calculations 2013-08-24 23:57:08 +02:00
Balint Reczey
6094fa9d87 Use nanosecond resolution for timestamps internally 2013-08-24 23:52:41 +02:00
Wolfgang Hommel
03fbad9bca Revert a0e3346..2dceb57
This rolls back to commit a0e33461a0.
2013-08-24 21:24:57 +02:00
Balint Reczey
45e9b4609e Refactor environment variable parsing and faking calculation 2013-08-24 15:52:09 +02:00
Balint Reczey
639d9caec8 Refactor limited faking and spawn support 2013-08-23 02:41:21 +02:00
Wolfgang Hommel
2dceb574ac Merge pull request #22 from tonigi/master
Libfaketime patch: process-shared "start at"
2013-08-22 06:53:12 -07:00
Toni G
b84e76ccf8 Merge branch 'master' of github.com:tonigi/libfaketime 2013-08-22 02:09:15 +02:00
Toni G
1ac7472769 Comment 2013-08-22 02:08:46 +02:00
Toni G
b4e3028494 explanation in readme 2013-08-22 02:08:30 +02:00
Toni G
b97121f7d6 explanation in readme 2013-08-22 02:07:16 +02:00
Toni G
982d90cbd2 comment 2013-08-22 01:57:39 +02:00
Toni G
af245d9d6c explanation in readme 2013-08-22 01:49:53 +02:00
Toni G
6db9ee8cf2 refactored ^ + @ 2013-08-22 01:30:44 +02:00
Toni G
fd1d3f161e explicit failure if ^ and not faketime 2013-08-22 01:13:31 +02:00
Toni G
ee8b780a87 Caret debugged, works 2013-08-22 01:03:16 +02:00
Toni G
39fc1bb0a8 attempt at global relative 2013-08-21 23:26:04 +02:00
Toni G
4a4673df6c guard against broken dlsym which returns 0 on __clock_gettime but does not set dlerror() 2013-08-21 21:27:02 +02:00
Toni G
65df40a624 added pthreads in make 2013-08-21 20:30:16 +02:00
Wolfgang Hommel
a0e33461a0 avoid_loop Patch by Gerardo Malazdrewicz <gerardo@malazdrewicz.com.ar> 2013-08-21 10:00:50 +02:00
Wolfgang Hommel
a2c8ac6687 moved outside #ifdef FAKE_STAT 2013-08-21 09:54:10 +02:00
Wolfgang Hommel
6f7acba526 Merge pull request #21 from rbalint/deterministic-time
Deterministic time
2013-08-20 23:36:13 -07:00
Balint Reczey
7287f9fe1d Cut _ftpl_time() 2013-08-20 15:40:51 +02:00
Balint Reczey
b9a46c9536 Look up all faked functions during library init
This makes us able to avoid protecting lookups with mutexes
2013-08-20 15:13:23 +02:00
Balint Reczey
bd5150e8dc Merge shared object init to existing constructor function 2013-08-19 21:13:10 +02:00
Balint Reczey
d5cd7064f5 Use the same global clock for all processes spawned by faketime -f '... iN'
In case the clock is set to advance with each faked time(), etc. call, the
counter uses the same clock counter stored in shared memory and protected
by a semaphore.
2013-08-19 14:08:51 +02:00
Balint Reczey
bfd4b9f5f3 Rewrite faketime shell script in C 2013-08-19 13:26:17 +02:00
Balint Reczey
ae45c5c48e Don't set USEDIRECT implicitly when the date looks suspicious 2013-08-17 22:16:44 +02:00
Wolfgang Hommel
c127aec450 Merge pull request #20 from rbalint/deterministic-time
Advance time with each time(), gettimeofday(), etc. call
2013-08-15 12:16:46 -07:00
Balint Reczey
2451de2244 Advance time with each time(), gettimeofday(), etc. call 2013-08-15 18:50:41 +02:00
Wolfgang Hommel
946f8e2378 GNU/kFreeBSD fix by Petr Salinger, fixes Bug#712709 2013-06-20 20:42:44 +02:00
Wolfgang Hommel
043d457fd2 Merge pull request #19 from dkg/wolf
build system fixes
2013-06-12 00:18:38 -07:00
Daniel Kahn Gillmor
02a0a3b231 separate the testing step from the build step
There are circumstances where you just want to repeat the build
without running the tests.  keeping the "test" target distinct from
the "all" target makes it possible to do that cleanly.
2013-06-11 10:23:05 -04:00
Daniel Kahn Gillmor
c818885733 Fix link order for --as-needed (see http://bugs.debian.org/711958)
In Ubuntu, the attached patch was applied to achieve the following:

  * as-needed.patch: Fix object/library link order for --as-needed.

When building with --as-needed, libraries need to be listed on the
link line after the objects that reference them.  In the autotools
world (and elsewhere), the LDFLAGS variable has been split into
LDFLAGS and LDADD to represent the need to list libs last.  This
patch makes that change to your Makefile, so this builds correctly
with --as-needed in LDFLAGS.
2013-06-11 10:13:25 -04:00
Daniel Kahn Gillmor
337581c040 allow overriding specific arguments without changing the Makefile
for example, now you can do:

 make PREFIX=/usr

without any modification to the Makefile and have it behave as
intended.
2013-06-11 10:10:14 -04:00
Wolfgang Hommel
e55e800a4c Merge pull request #16 from adrelanos/master
Time Privacy script
2013-05-09 23:47:56 -07:00
adrelanos
bb350d4b77 added command line options 2013-05-06 03:39:11 +00:00
adrelanos
eaa8e53318 Create timeprivacy
see https://github.com/adrelanos/timeprivacy
2013-05-03 03:45:45 +00:00
Wolfgang Hommel
10074a0030 Hugues Andreux: better support for different installation locations 2013-02-20 19:52:18 +01:00
Wolfgang Hommel
4c2ff5e559 Merge pull request #11 from dfong/master
bug in reading faketimerc
2012-11-28 10:11:52 -08:00
don fong
cd267e8dd5 whitespace fix
replace tabs with spaces to match surrounding code
2012-11-27 14:01:12 -08:00
don fong
bd1de99d3a bug in reading faketimerc
if the faketimerc file begins with an empty line, then the inner
loop that trims trailing eol chars could possibly step backward
past the beginning of the buffer (line).  if the byte just
preceding line also happened to contain a '\n' or '\r',
it could be clobbered.
2012-11-27 13:38:48 -08:00
Wolfgang Hommel
471e2a5620 Fixed 2012-11-24 19:40:10 +01:00
Wolfgang Hommel
037552cfed fixed a bug reported by goofansu 2012-11-23 21:03:39 +01:00
Wolfgang Hommel
dab8698a03 Merge pull request #8 from domo141/d3ff79a
Implementation of implicit '-f'
2012-09-10 22:24:07 -07:00
Tomi Ollila
d3ff79a0aa src/faketime: implicit '-f' for $offset that is faketime-known relative
When $offset arg looks like the relative value described in README
section "4d) Using offsets for relative dates", set USEDIRECT variable
even when '-f' option is not present. Without the '-f' the $offset would
be useless so this is convenience feature for the user. Using '-f' in
command line to explicitly set USEDIRECT is retained.
2012-09-09 20:36:37 +03:00
Wolfgang Hommel
532f0dc65d Merge pull request #7 from domo141/topic-wsc1
whitespace cleanup
2012-08-30 09:48:22 -07:00
Tomi Ollila
b648b7712d whitespace cleanup
Used (emacs) M-x untabify for whole faketime.c as the prevailing
style in that file used spaces for indentation.

Used M-x delete-trailing-whitespace to all files that had either
trailing whitespace or empty lines at the end of file to remove
those.
2012-08-30 10:46:58 +03:00
Wolfgang Hommel
d8053c280c Reorder linker flags as suggested by Lukas Fleischer 2012-02-05 00:07:54 +01:00
Wolfgang Hommel
b067cdce2b Initialize INSTALL as suggested by Lukas Fleischer 2012-02-05 00:05:46 +01:00
45 changed files with 7441 additions and 1532 deletions

23
.github/workflows/make-test.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: Run make test
on:
push:
branches:
- master
- develop
schedule:
- cron: '30 9 * * *'
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- name: make
run: make
- name: make test
run: make test

23
.gitignore vendored
View File

@@ -3,5 +3,28 @@
timetest
src/libfaketime.dylib.1
src/libfaketime.1.dylib
src/core
src/faketime
.vscode/
Makefile
Makefile.in
/aclocal.m4
/autom4te.cache/
/config.*
/configure
/depcomp
/install-sh
/libtool
/ltmain.sh
/m4/
/missing
/stamp-h?
.deps/
.dirstamp
.libs/
*.l[ao]
compile
test-driver

17
.travis.yml Normal file
View File

@@ -0,0 +1,17 @@
language: c
matrix:
include:
- os: linux
compiler: gcc
- os: osx
osx_image: xcode11
script:
- cd ${TRAVIS_BUILD_DIR}
- sh ./build.sh init
- ./configure
- FAKETIME_COMPILE_CFLAGS="-DFORCE_MONOTONIC_FIX" make
- cd test
- make test
- make distcheck

2
AUTHORS Normal file
View File

@@ -0,0 +1,2 @@
Wolfgang Hommel <wolfcw>
Balint Reczey <rbalint>

11
ChangeLog Normal file
View File

@@ -0,0 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.
Additional change history is viewable in the `NEWS` file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Changed
- Mike Stemle added GNU autotools

View File

@@ -1,30 +0,0 @@
all:
$(MAKE) -C src all
$(MAKE) -C test all
test:
$(MAKE) -C test all
install:
$(MAKE) -C src install
$(MAKE) -C man install
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/share/doc/faketime/"
$(INSTALL) -m0644 README "${DESTDIR}${PREFIX}/share/doc/faketime/README"
$(INSTALL) -m0644 NEWS "${DESTDIR}${PREFIX}/share/doc/faketime/NEWS"
uninstall:
$(MAKE) -C src uninstall
$(MAKE) -C man uninstall
rm -f "${DESTDIR}${PREFIX}/share/doc/faketime/README"
rm -f "${DESTDIR}${PREFIX}/share/doc/faketime/NEWS"
rmdir "${DESTDIR}${PREFIX}/share/doc/faketime"
clean:
$(MAKE) -C src clean
$(MAKE) -C test clean
distclean:
$(MAKE) -C src distclean
$(MAKE) -C test distclean
.PHONY: all test install uninstall clean distclean

4
Makefile.am Normal file
View File

@@ -0,0 +1,4 @@
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS=-I m4
SUBDIRS=src test man
EXTRA_DIST=README.developers README.OSX README.packagers TODO

93
NEWS
View File

@@ -1,3 +1,89 @@
Since 0.9.9:
- Mike Stemle added GNU autotools
- Additional link-time LDFLAGS can be passed via the
environment variable FAKETIME_LINK_FLAGS when
running 'make'.
Since 0.9.8:
- Compile-time CFLAG FAKE_SETTIME can be enabled to
intercept calls to clock_settime(), settimeofday(), and
adjtime(). (suggested and prototyped by @ojura)
- Additional compile-time CFLAGs can be passed via the
environment variable FAKETIME_COMPILE_CFLAGS when
running 'make'.
- src/Makefile CFLAG FORCE_PTHREAD_NONVER should be set on
systems that hang on CLOCK_REALTIME, or that hang on
CLOCK_MONOTONIC where FORCE_MONOTONIC_FIX is not sufficient.
Since 0.9.7:
- Passthrough for unknown clock ids to avoid error messages
- Fixes for multithreaded operations (mliertzer, qnox)
- glibc-related fixes (jprjr) and gcc8 support (tpetazzoni)
- Improved error message output on parsing errors
- fix file stat() faking when 'i' modifier is used for determinism
- Use FAKETIME="%" to take FAKETIME setting from a file as
specified in FAKETIME_FOLLOW_FILE
- Added FAKETIME_DONT_RESET environment variable to avoid
faketime resets when subprocesses are started (similar to
the old v0.9.6 behavior)
- Added FAKETIME_XRESET to avoid large clock jumps when
the 'x' modifier is used and changed during run-time
- Do not fake time during libfaketime initialization to
improve compatibility with memory allocation libraries that
use time-related functions themselves
- Fixes for shared memory related issues, especially when
not using the faketime wrapper
- Updated glibc compatibility settings for various platforms
- Support for clock_nanosleep() with realtime and monotonic clocks
- Support for epoll_wait(), epoll_pwait(), and pselect()
- src/Makefile CFLAG FORCE_MONOTONIC_FIX should be set (only) on
platforms where the test program hangs forever at the
CLOCK_MONOTONIC test.
Since 0.9.6:
- Julien Gilli added an option to disable monotonic time faking
- Azat Khuzhin added support for COARSE clocks
- Preliminary support for CLOCK_BOOTTIME (Linux)
- Fixed compilation on macOS (High) Sierra and various compiler warnings
- Support for select() call added by Hitoshi Harada (umitanuki)
- Updated documentation
Since 0.9.5:
- fixed crashes that happened when other LD_PRELOAD libraries were used
- fixed passing through of return values when using the faketime wrapper
- fixed compile-time issues with CLOCK_MONOTONIC_RAW on some platforms
- rbalint added Filter commands: FAKETIME_ONLY_CMDS and
FAKETIME_SKIP_CMDS control which (sub-)processes libfaketime
is applied to.
Since 0.9:
- ryandesign at MacPorts provided a Portfile for MacPorts and
fixed various build issues on OSX.
- Balint Reczey added support for nanosecond resolution, saving
timestamps to files, speeding up and slowing down per-process
timers, CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW, faketime
support for system calls such as sleep() and alarm().
- Applied a patch by Gerardo Malazdrewicz and Toni G to restore
compatibility with newer versions of glibc.
- Balint Reczey added an option to use the same global clock setting
for all libfaketime-spawned processes.
- Balint Reczey has rewritten the faketime wrapper shell script in C
and refactored libfaketime.
- Balint Reczey added support for advancing the time with each time-
related system call ("deterministic time").
- Added "timeprivacy" wrapper by adrelanos; it ensures that programs
are started with unique timestamps.
- Code and documentation cleanup by Tomi Ollila.
- Reworked Makefiles for more flexible installation, including fixes
by Lukas Fleischner, Daniel Kahm Gillmor, and Hugues Andreux.
- Fixed license issues as pointed out by Paul Wouters.
- Mac OS X support has been improved for OS X 10.7 and 10.8; due to
changes to the underlying libraries on OS X, libfaketime 0.9.5 will
no longer work with OS X < 10.6; use libfaketime 0.9(.1) for older
OS X installations.
- Don Fong has contributed a new framework for functional tests.
Petr Salinger ensured its compatibility with GNU/kFreeBSD.
Since 0.8.2:
- Added support for "limited faking".
You can optionally specify when libfaketime starts to fake the
@@ -5,15 +91,15 @@ Since 0.8.2:
a program can be started regularly, and after 5 minutes run-time
it will be sent two years into the future. Those limiting
start and stop times can be specified in seconds or as the
number of any time-related function calls within the program.
number of any time-related function calls within the program.
- Added a feature to spawn an external process after x seconds
or y time-related system calls. This can, for example, be used
to execute an arbitrary shell script x seconds after a program
has been started.
has been started.
Since 0.8.1:
- Added a MacOS port.
Thanks to Derrick Brashear!
Thanks to Daria Phoebe Brashear!
- Added a functional test framework that aids in automatically
determining whether libfaketime works properly on the current
machine. Thanks to Don Fong!
@@ -88,4 +174,3 @@ Since 0.2:
Since 0.1:
- Fixed segfault when calling time(NULL). Thanks to Andres Ojamaa!
- Added additional sanity checks.

560
README
View File

@@ -1,6 +1,5 @@
=====================================================
FakeTime Preload Library, version 0.9 (February 2011)
=====================================================
libfaketime, version 0.9.8 (August 2019)
========================================
Content of this file:
@@ -17,80 +16,121 @@ Content of this file:
e) Advanced features and caveats
f) Faking the date and time system-wide
g) Using the "faketime" wrapper script
h) "Limiting" libfaketime
i) Spawning an external process
h) "Limiting" libfaketime based on elapsed time or number of calls
i) "Limiting" libfaketime per process
j) Spawning an external process
k) Saving timestamps to file, loading them from file
5. License
6. Contact
1. Introduction
---------------
FTPL intercepts various system calls which programs use to retrieve the
current date and time. It can then report faked dates and times (as
specified by you, the user) to these programs. This means you can modify
the system time a program sees without having to change the time system-
wide.
libfaketime intercepts various system calls that programs use to retrieve the
current date and time. It then reports modified (faked) dates and times (as
specified by you, the user) to these programs. This means you can modify the
system time a program sees without having to change the time system-wide.
FTPL allows you to specify both absolute dates (e.g., 01/01/2004) and
libfaketime allows you to specify both absolute dates (e.g., 01/01/2004) and
relative dates (e.g., 10 days ago).
FTPL might be used for various purposes, for example
libfaketime might be used for various purposes, for example
- running legacy software with y2k bugs
- testing software for year-2038 compliance
- deterministic build processes
- debugging time-related issues, such as expired SSL certificates
- running software which ceases to run outside a certain timeframe
- using different system-wide date and time settings, e.g. on OpenVZ-
based virtual machines running on the same host
- testing software for year-2038 compliance
libfaketime ships with a command line wrapper called "faketime" that makes it
easier to use, but does not expose all of libfaketime's functionality. If your
use case is not covered by the faketime command, make sure to look in this
documentation whether it can be achieved by using libfaketime directly.
2. Compatibility issues
-----------------------
* FTPL has been designed on and for Linux 2.x, but is supposed and has been
reported to work on other *NIXes as well.
- libfaketime is supposed to work on Linux and macOS.
Your mileage may vary; some other *NIXes have been reported to work as well.
* FTPL uses the library preload mechanism and thus cannot work with statically
linked binaries or binaries that have the setuid-flag set (e.g., suidroot
programs like "ping" or "passwd").
- libfaketime uses the library preload mechanism of your operating system's
linker (which is involved in starting programs) and thus cannot work with
statically linked binaries or binaries that have the setuid-flag set (e.g.,
suidroot programs like "ping" or "passwd"). Please see you system linker's
manpage for further details.
* As of version 0.7, support has been added for use in a pthreads environment. A
separate library is built (libfaketimeMT.so.1) which contains the pthread
synchronization calls. This library also single-threads calls through the
time() intercept, because several variables are statically cached by the
library and could cause issues when accessed without synchronization. However,
the performance penalty for this might be an issue for some applications. If
this is the case, you can try using an unsynchronized time() intercept by
removing the -DPTHREAD_SINGLETHREADED_TIME from the Makefile and rebuilding
libfaketimeMT.so.1 . Thanks to David North, TDI!
- libfaketime supports the pthreads environment. A separate library is built
(libfaketimeMT.so.1), which contains the pthread synchronization calls. This
library also single-threads calls through the time() intercept because
several variables are statically cached by the library and could cause issues
when accessed without synchronization.
* If and only if you want to run Java programs with faked times in the future
(not in the past) on Linux, you also should set the environment variable
LD_ASSUME_KERNEL=2.4.19 before running the appropriate "java" command. This
fixes an occasional bug where Java locks up at exiting. Again, this is only
required for Java with faked times in the future. Thanks to Jamie Cameron for
reporting this issue and finding a workaround!
However, the performance penalty for this might be an issue for some
applications. If this is the case, you can try using an unsynchronized time()
intercept by removing the -DPTHREAD_SINGLETHREADED_TIME from the Makefile and
rebuilding libfaketimeMT.so.1
* Java-/JVM-based applications work but you need to pass in an extra argument
(FAKETIME_DONT_FAKE_MONOTONIC). See usage basics below for details. Without
this argument the java command usually hangs.
* libfaketime will eventually be bypassed by applications that dynamically load
system libraries, such as librt, explicitly themselves instead of relying on
the linker to do so at application start time. libfaketime will not work with
those applications unless you can modify them.
This apparently happens a lot in complex run-time environments, e.g., for
programs written in golang, for some Java Virtual Machine implementations,
etc. Since libfaketime is effectively bypassed in such situations, there's
nothing we can do about it. Please consider asking the appropriate developers
and vendors to implement their runtime environment in a way that supports
intercepting selected system calls through LD_PRELOAD.
* Applications can explicitly be designed to prevent libfaketime from working,
e.g., by checking whether certain environment variables are set or whether
libfaketime-specific files are present.
* CLOCK_MONOTONIC test: Running "make test" performs a series of tests after
successful compilation of the libfaketime library. On some platforms, the
"CLOCK_MONOTONIC test" will apparently hang forever. If and only if this
happens on your platform, add the CFLAG -DFORCE_MONOTONIC_FIX to
src/Makefile and recompile libfaketime. Do not set FORCE_MONOTONIC_FIX on
platforms where the test does not hang.
If you observe hangs on the CLOCK_REALTIME test, add the CFLAG
-DFORCE_PTHREAD_NONVER. Also set this FORCE_PTHREAD_NONVER flag in case
FORCE_MONOTONIC_FIX alone does not solve the hang on the MONOTONIC_CLOCK
test.
3. Installation
---------------
Running "make" should compile both library versions and a test program, which
it then also executes.
This library supports GNU autotools, so you should be able to build it with:
If the test works fine, you should copy the FTPL libraries (libfaketime.so.1,
and libfaketimeMT.so.1) to the place you want them in. Running "make install"
will attempt to place them in /usr/local/lib/faketime and will install the wrapper
shell script "faketime" in /usr/local/bin, both of which most likely will require
root privileges; however, from a technical point of view, there is no
necessity for a system-wide installation, so you can use FTPL also on machines
where you do not have root privileges. You may want to adjust the PREFIX
variable in the Makefiles accordingly.
sh ./build.sh init
./configure
make
Since version 0.6, system calls to file timestamps are also intercepted now,
After you have built the library, you may--optionally--run the tests with:
cd test
make test
If the test works fine, you should copy the libfaketime libraries
(libfaketime.so.1, and libfaketimeMT.so.1) to the place you want them in.
Running "make install" will attempt to place them in /usr/local/lib/faketime
and will install the wrapper shell script "faketime" in /usr/local/bin, both of
which most likely will require root privileges. However, from a technical point
of view, there is no necessity for a system-wide installation, so you can use
libfaketime also on machines where you do not have root privileges. You may
want to adjust the PREFIX variable in the Makefiles accordingly.
By default, the Makefile compiles/links libfaketime for your default system
architecture. If you need to build, e.g., 32-bit files on a 64-bit platform,
please see the notes about CFLAGS and LDFLAGS in src/Makefile.
Since version 0.6, system calls to file timestamps are also intercepted,
thanks to a contribution by Philipp Hachtmann. This is especially useful in
combination with relative time offsets as explained in section 4d) below, if a
program writes and reads files whose timestamps also shall be faked. If you do
@@ -98,12 +138,16 @@ not need this feature or if it confuses the application you want to use FTPL
with, define the environment variable NO_FAKE_STAT, and the intercepted stat
calls will be passed through unaltered.
On MacOS, it is necessary to compile differently, due to the different
behavior dyld has. Use the Makefile.MacOS provided to compile
libfaketime.dylib.1. Additionally, instead of using LD_PRELOAD,
the variable DYLD_INSERT_LIBRARIES should be set to the path to
libfaketime.dylib.1, and the variable DYLD_FORCE_FLAT_NAMESPACE should be
set (to anything).
On macOS, instead of using LD_PRELOAD, the variable DYLD_INSERT_LIBRARIES
should be set to the path to libfaketime.0.dylib, and the variable
DYLD_FORCE_FLAT_NAMESPACE should be set (to anything). macOS users should
read README.OSX for additional details.
NOTE: When committing, clean up potentially non-portable files with:
sh build.sh clean
This will clean up the build files which we don't want to version-control.
4. Usage
--------
@@ -111,59 +155,69 @@ set (to anything).
4a) Usage basics
----------------
Using FTPL on a program of your choice consists of two steps:
Using libfaketime on a program of your choice consists of two steps:
1. Making sure FTPL gets loaded.
1. Making sure libfaketime gets loaded by the system's linker.
2. Specify the faked time.
As an example, we want the "date" command to report our faked time. To do so,
we could use the following command line:
we could use the following command line on Linux:
user@host> date
Tue Nov 23 12:01:05 CEST 2007
Tue Nov 23 12:01:05 CEST 2016
user@host> LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="-15d" date
Mon Nov 8 12:01:12 CEST 2007
Mon Nov 8 12:01:12 CEST 2016
user@host> LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="-15d"
FAKETIME_DONT_FAKE_MONOTONIC=1 java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
The basic way of running any command/program with FTPL enabled is to make sure
the environment variable LD_PRELOAD contains the full path and filename of the
FTPL library. This can either be done by setting it once beforehand:
The basic way of running any command/program with libfaketime enabled is to
make sure the environment variable LD_PRELOAD contains the path and
filename of the libfaketime library. This can either be done by setting it once
beforehand:
export LD_PRELOAD=/path/to/libfaketime.so.1
(now run any command you want)
Or it can be done by specifying it on the command line itself:
LD_PRELOAD=/path/to/libfaketime.so.1 your_command_here
(These examples are for the bash shell; how environment variables are set may
(These examples are for the bash shell; how environment variables are set may
vary on your system.)
On Linux, library search paths can be set as part of the linker configuration.
LD_PRELOAD then also works with relative paths. For example, when libfaketime.so.1
is installed as /path/to/libfaketime.so.1, you can add /path/to to an appropriate
linker configuration file, e.g., /etc/ld.so.conf.d/local.conf, and then run
the "ldconfig" command. Afterwards, using LD_PRELOAD=libfaketime.so.1 suffices.
However, also the faked time should be specified; otherwise, FTPL will be
loaded, but just report the real system time. There are three ways to specify
the faked time:
However, also the faked time should be specified; otherwise, libfaketime will
be loaded, but just report the real system time. There are three ways to
specify the faked time:
a) By setting the environment variable FAKETIME.
b) By using the file .faketimerc in your home directory.
c) By using the file /etc/faketimerc for a system-wide default.
b) By using the file given in the environment variable FAKETIME_TIMESTAMP_FILE
c) By using the file .faketimerc in your home directory.
d) By using the file /etc/faketimerc for a system-wide default.
If you want to use b) or c), $HOME/.faketimerc or /etc/faketimerc consist of
only one line of text with exactly the same content as the FAKETIME environment
If you want to use b) c) or d), $HOME/.faketimerc or /etc/faketimerc consist of
only one line of text with exactly the same content as the FAKETIME environment
variable, which is described below. Note that /etc/faketimerc will only be used
if there is no $HOME/.faketimerc, and the FAKETIME environment variable always
has priority over the files.
if there is no $HOME/.faketimerc and no FAKETIME_TIMESTAMP_FILE file exists.
Also, the FAKETIME environment variable _always_ has priority over the files.
4b) Using absolute dates
------------------------
The format which _must_ be used for _absolute_ dates is "YYYY-MM-DD hh:mm:ss".
For example, the 24th of December, 2002, 8:30 PM would have to be specified as
FAKETIME="2002-12-24 20:30:00".
The format that _must_ be used for _absolute_ dates is "YYYY-MM-DD hh:mm:ss".
For example, the 24th of December, 2020, 8:30 PM would have to be specified as
FAKETIME="2020-12-24 20:30:00".
4c) Using 'start at' dates
@@ -171,15 +225,31 @@ FAKETIME="2002-12-24 20:30:00".
(Thanks to a major contribution by David North, TDI in version 0.7)
The format which _must_ be used for _start_at_ dates is "@YYYY-MM-DD hh:mm:ss".
For example, the 24th of December, 2002, 8:30 PM would have to be specified as
FAKETIME="@2002-12-24 20:30:00".
The format that _must_ be used for _start_at_ dates is "@YYYY-MM-DD hh:mm:ss".
For example, the 24th of December, 2020, 8:30 PM would have to be specified as
FAKETIME="@2020-12-24 20:30:00".
The absolute dates described in 4b simulate a STOPPED system clock at the
The absolute dates described in 4b) simulate a STOPPED system clock at the
specified absolute time. The 'start at' format allows a 'relative' clock
operation as described below in section 4d, but using a 'start at' time
operation as described below in section 4d), but using a 'start at' time
instead of an offset time.
If the started process itself starts other (child) processes, they by default
will start with the specified start-at-date again. If this is not what you need,
set the environment variable FAKETIME_DONT_RESET=1. Try these examples to see
the difference:
LD_PRELOAD=src/libfaketime.so.1 FAKETIME="@2000-01-01 11:12:13" \
FAKETIME_DONT_RESET=1 \
/bin/bash -c 'while [ $SECONDS -lt 5 ]; do date; sleep 1; done'
LD_PRELOAD=src/libfaketime.so.1 FAKETIME="@2000-01-01 11:12:13" \
/bin/bash -c 'while [ $SECONDS -lt 5 ]; do date; sleep 1; done'
In the second example, the "date" command will always print the same time,
while in the first example, with FAKETIME_DONT_RESET set, time will increment
even though all the "date" commands are new processes.
4d) Using offsets for relative dates
------------------------------------
@@ -188,30 +258,34 @@ Relative date offsets can be positive or negative, thus what you put into
FAKETIME _must_ either start with a + or a -, followed by a number, and
optionally followed by a multiplier:
- by default, the offset you specify is in seconds. Example:
- By default, the offset you specify is in seconds. Example:
export FAKETIME="-120" will set the faked time 2 minutes (120 seconds) behind
the real time.
- the multipliers "m", "h", "d" and "y" can be used to specify the offset in
- The multipliers "m", "h", "d" and "y" can be used to specify the offset in
minutes, hours, days and years (365 days each), respectively. Examples:
export FAKETIME="-10m" sets the faked time 10 minutes behind the real time.
export FAKETIME="+14d" sets the faked time to 14 days in the future.
Please note that if you need other multipliers (weeks, months etc.) or higher
precision (e.g., correct leap year handling), you should use either the
faketime wrapper or the GNU date command as shown in the first of the three
examples below.
You now should understand the complete example we've used before:
LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="-15d" date
This command line makes sure FTPL gets loaded and sets the faked time to
This command line makes sure libfaketime gets loaded and sets the faked time to
15 days in the past.
Moreno Baricevic has contributed support for the FAKETIME_FMT environment
variable, which allows to optionally set the strptime() format:
variable, which allows you to optionally set the strptime() format:
Some simple examples:
LD_PRELOAD=./libfaketime.so.1 FAKETIME_FMT=%s FAKETIME="`date +%s -d'1 year ago'`" date
LD_PRELOAD=./libfaketime.so.1 FAKETIME_FMT=%s FAKETIME="`date +%s -d'1 year ago'`" date
LD_PRELOAD=./libfaketime.so.1 FAKETIME_FMT=%s FAKETIME="`stat -c %Y somefile`" date
LD_PRELOAD=./libfaketime.so.1 FAKETIME_FMT=%c FAKETIME="`date`" date
@@ -232,11 +306,13 @@ depends on your locale settings, so actually you might need to use
FAKETIME="+1.5h"
You should figure out the proper delimiter, e.g. by using FTPL on a command
like /bin/date where you immediately can verify whether it worked as expected.
You should figure out the proper delimiter, e.g., by using libfaketime on
a command like /bin/date where you immediately can verify whether it worked as
expected.
Also contributed by Karl Chen in v0.8 is the option to speed up or slow down
the wall clock time for the program which is executed using FTPL. For example,
Also contributed by Karl Chen in v0.8 is the option to speed up or slow
down the wall clock time for the program which is executed using libfaketime.
For example,
FAKETIME="+1y x2"
@@ -246,67 +322,188 @@ twice as fast. Similarly,
FAKETIME="+1y x0,5"
will make the clock run only half as fast. As stated above, the fraction
delimiter depends on your locale.
delimiter depends on your locale. Furthermore,
FAKETIME="+1y i2,0"
will make the clock step two seconds per each time(), etc. call, being
completely independently of the system clock. It helps running programs
with some determinism. In this single case all spawned processes will use
the same global clock without restarting it at the start of each process.
Please note that using "x" or "i" in FAKETIME still requires giving an offset
(see section 4d). This means that "+1y x2" will work, but "x2" only will not.
If you do not want to fake the time, but just modify clock speed, use something
like "+0 x2", i.e., use an explizit zero offset as a prefix in your FAKETIME.
For testing, your should run a command like
LD_PRELOAD=./libfaketime.so.1 FAKETIME="+1,5y x10,0" \
/bin/bash -c 'while true; do echo $SECONDS ; sleep 1 ; done'
For each second that the endless loop sleeps, the executed bash shell will
think that 10 seconds have passed ($SECONDS is a bash-internal variable
For each second that the endless loop sleeps, the executed bash shell will
think that 10 seconds have passed ($SECONDS is a bash-internal variable
measuring the time since the shell was started).
(Please note that replacing "echo $SECONDS" e.g. with a call to "/bin/date"
will not give the expected result, since /bin/date will always be started
as a new process for which also FTPL will be re-initialized. It will show
the correct offset (1.5 years in the future), but no speed-ups or
slow-downs.)
will not give the expected result, since /bin/date will always be started as a
new process for which also libfaketime will be re-initialized. It will show the
correct offset (1.5 years in the future), but no speed-ups or slow-downs.)
For applications that should use a different date & time each time they are
run, consider using the included timeprivacy wrapper shellscript (contributed
by adrelanos at riseup dot net).
Caveats:
--------
Whenever possible, you should use relative offsets or 'start at' dates, and not
use absolute dates.
Whenever possible, you should use relative offsets or 'start at' dates,
and not use absolute dates.
Why? Because the absolute date/time you set is fixed, i.e. if a program
Why? Because the absolute date/time you set is fixed, i.e., if a program
retrieves the current time, and retrieves the current time again 5 minutes
later, it will still get the same result twice. This is likely to break
programs which measure the time passing by (e.g. a mail program which checks
programs which measure the time passing by (e.g., a mail program which checks
for new mail every X minutes).
Using relative offsets or 'start at' dates solves this problem. FTPL then will
always report the faked time based on the real current time and the offset
you've specified.
Using relative offsets or 'start at' dates solves this problem.
libfaketime then will always report the faked time based on the real
current time and the offset you've specified.
Please also note that your specification of the fake time is cached for 10
seconds in order to enhance the library's performance. Thus, if you change the
Please also note that your default specification of the fake time is cached for
10 seconds in order to enhance the library's performance. Thus, if you change the
content of $HOME/.faketimerc or /etc/faketimerc while a program is running, it
may take up to 10 seconds before the new fake time is applied. If this is a
problem in your scenario, you can disable caching at compile time by adding the
command line option -DNO_CACHING to this library's Makefile.
problem in your scenario, you can change number of seconds before the file is read
again with environment variable FAKETIME_CACHE_DURATION, or disable caching at all
with FAKETIME_NO_CACHE=1. Remember that disabling the cache may negatively
influence the performance.
Setting FAKETIME by means of a file timestamp
---------------------------------------------
Based on a proposal by Hitoshi Harada (umitanuki), the "start at" time can now be
set through any file in the file system by setting the FAKETIME environment variable
to "%" (a percent sign) and FAKETIME_FOLLOW_FILE to the name of the file whose
modification timestamp shall be used as source for the "start at" time.
Usage example:
# create any file with December 24th, 2009, 12:34:56 as timestamp
touch -t 0912241234.56 /tmp/my-demo-file.tmp
# run a bash shell with an endless loop printing the current time
LD_PRELOAD=/path/to/libfaketime.so.1 \
FAKETIME='%' FAKETIME_FOLLOW_FILE=/tmp/my-demo-file.tmp \
FAKETIME_DONT_RESET=1 \
bash -c 'while true ; do date ; sleep 1 ; done'
# now, while the above is running, change the file's timestamp
# (in a different terminal window or whatever)
touch -t 2002290123.45 /tmp/my-demo-file.tmp
Changing the 'x' modifier during run-time
-----------------------------------------
Using FAKETIME_TIMESTAMP_FILE allows for easily changing the FAKETIME setting
while a program is running:
echo "+0 x1" > /tmp/my-faketime.rc
LD_PRELOAD=libfaketime.so.1 FAKETIME_TIMESTAMP_FILE="/tmp/my-faketime.rc" \
FAKETIME_NO_CACHE=1 ./some-program &
sleep 10 ; echo "+0 x10" > /tmp/my-faketime.rc
Changing the speed of the wall clock time, i.e., using a different 'x' modifier
during run-time, by default can lead to greater jumps that may confuse the
program. For example, if the program has been running for 10 seconds on 'x1',
and then the setting is changed to 'x10', the faked time will look to the
program as if it has been running for more than 100 instead of just more than
10 seconds.
By setting the environment variable FAKETIME_XRESET to any value, transitions
between different 'x' modifier values will be significantly smoothed:
LD_PRELOAD=libfaketime.so.1 FAKETIME_TIMESTAMP_FILE="/tmp/my-faketime.rc" \
FAKETIME_NO_CACHE=1 FAKETIME_XRESET=1 ./some-program &
Setting FAKETIME_XRESET ensures that wall clock time begins to run faster
only after the 'x' modifier has been changed (when increasing it) and also
ensures that the reported faked time does not jump back to past values
(when decreasing it).
Please note that FAKETIME_XRESET internally works by resetting libfaketime's
internal time-keeping data structures, which may have side effects on reported
file timestamps. Using FAKETIME_XRESET should be considered experimental at
the moment.
Cleaning up shared memory
-------------------------
libfaketime uses semaphores and shared memory on platforms that support it in
order to sync faketime settings across parent-child processes. It will clean
up when it exits properly. However, when processes are terminated (e.g., by
Ctrl-C on command line), shared memory cannot be cleaned up properly. In such
cases, you should occasionally delete
/dev/shm/faketime_shm_* and
/dev/shm/sem.faketime_sem_*
manually (or properly automated). Leftover files there from processes that
already have been terminated are not a problem in general, but result in a
libfaketime error the next time a process is started with a process id for
which such a stale semaphore/shared memory exists. Thus, if you run across
the following error message
libfaketime: In ft_shm_create(), shm_open failed: File exists
please cleanup /dev/shm as described above. This is especially relevant
for long-running systems (servers with high uptime) and systems on which
a lot of processes are started (e.g., servers handling many containers
or similar virtualization mechanisms).
Intercepting time-setting calls
-------------------------------
libfaketime can be compiled with the CFLAG "-DFAKE_SETTIME" in order
to also intercept time-setting functions, i.e., clock_settime(),
settimeofday(), and adjtime(). Instead of passing the timestamp a
program sets through to the system, only the FAKETIME environment
variable will be adjusted accordingly.
4f) Faking the date and time system-wide
----------------------------------------
David Burley of SourceForge, Inc. reported an interesting use case of applying
FTPL system-wide: Currently, all virtual machines running inside an OpenVZ host
have the same system date and time. In order to use multiple sandboxes with
different system dates, the FTPL library can be put into /etc/ld.so.preload;
it will then be applied to all commands and programs automatically. This is
of course best used with a system-wide /etc/faketimerc file. Kudos to
SourceForge, Inc. for providing the patch!
David Burley of SourceForge, Inc. reported an interesting use case of applying
libfaketime system-wide: Currently, all virtual machines running inside
an OpenVZ host have the same system date and time. In order to use multiple
sandboxes with different system dates, the libfaketime library can be put into
/etc/ld.so.preload; it will then be applied to all commands and programs
automatically. This is of course best used with a system-wide /etc/faketimerc
file. Kudos to SourceForge, Inc. for providing the patch!
Caveat: If you run a virtual machine, its real-time clock might be reset to the
real world date & time when you reboot. Depending on your FAKETIME setting,
this may lead to side effects, such as forced file system checks on each reboot.
System-wide faked time may also lead to unexpected side effects with software
auto-update tools, if the offset between real world time and faked system time
is too large. If in doubt, set your system's date to the faked time and try out
whether everything still works as expected before applying libfaketime
system-wide.
4g) Using the "faketime" wrapper script
---------------------------------------
4g) Using the "faketime" wrapper
--------------------------------
As of version 0.8, FTPL provides a shell script named "faketime" which is
As of version 0.8, libfaketime provides a command named "faketime", which is
placed into /usr/bin by "make install". It spares the hassle of setting
the LD_PRELOAD and FAKETIME environment variables manually, but only exposes
a subset of FTPL's functionality. On the other hand, it uses the date
a subset of libfaketime's functionality. On the other hand, it uses the date
interpretation function by /bin/date in order to provide higher flexibility
regarding the specification of the faked date and time. For example, you
can use
@@ -315,16 +512,19 @@ faketime 'last Friday 5 pm' /your/command/here
Of course, also absolute dates can be used, such as in
faketime '2008-12-24 08:15:42' /bin/date
faketime '2018-12-24 08:15:42' /bin/date
Thanks to Daniel Kahn Gillmor for providing these suggestions!
Balint Reczey has rewritten the wrapper in 0.9.5 from a simple shell script
to an efficient wrapper application.
4h) "Limiting" libfaketime
--------------------------
4h) "Limiting" libfaketime based on elapsed time or number of calls
-------------------------------------------------------------------
Starting with version 0.9, libfaketime can be configured to not be continuously
active, but only during a certain time interval.
active, but only during a certain time interval.
For example, you might want to start a program with the real current time, but
after 5 minutes of usage, you might want it to see a faked time, e.g., a year
@@ -335,12 +535,12 @@ Dynamic changes to the faked time are alternatively possible by
- changing the FAKETIME environment variable at run-time; this is the preferred
way if you use libfaketime for debugging and testing as a programmer, as it
gives you the most direct control of libfaketime without any performance
penalities.
penalties.
- not using the FAKETIME environment variable, but specifying the fake time in a
file (such as ~/.faketimerc). You can change the content of this file at
run-time. This works best with caching disabled (see Makefile), but comes at a
performance cost because this file has to be read and evaluated each time.
- not using the FAKETIME environment variable, but specifying the fake time in
a file (such as ~/.faketimerc). You can change the content of this file at
run-time. This works best with caching disabled, but comes at a performance
cost because this file has to be read and evaluated each time.
The feature described here works based on two pairs of environment variables,
@@ -348,7 +548,7 @@ The feature described here works based on two pairs of environment variables,
FAKETIME_START_AFTER_NUMCALLS and FAKETIME_STOP_AFTER_NUMCALLS
The default value for each of these environment variables is -1, which means
"ignore this value".
"ignore this value".
If you want libfaketime to be only active during the run-time minutes 2 to 5
of your application, you would set
@@ -359,7 +559,7 @@ of your application, you would set
This means that your application will work with the real time from start (second
0) up to second 60. It will then see a faked time from run-time seconds 60 to
300 (minutes 2, 3, 4, and 5). After run-time second 600, it will again see the
real (not-faked) time.
real (not-faked) time.
This approach is not as flexible as changing the FAKETIME environment variable
during runtime, but may be easier to use, works on a per-program (and not a
@@ -368,9 +568,9 @@ per-user or system-wide) scope, and has only a minor performance overhead.
Using the other pair of environment variables, you can limit the activity time
of libfaketime not based on wall-clock seconds, but on the number of
time-related function calls the started program performs. This alternative is
probably only suitable for programmers who either know the code of the program
in order to determine useful start/stop values or want to perform fuzzing
tests.
probably only suitable for programmers who either know the code of the program
in order to determine useful start/stop values or want to perform fuzzing
tests.
Both pairs of environment variables can be combined to further restrict
libfaketime activity, although this is only useful in very few scenarios.
@@ -379,18 +579,46 @@ Limiting libfaketime activity in this way is not recommended in general. Many
programs will break when they are subject to sudden changes in time, especially
if they are started using the current (real) time and are then sent back into
the past after, e.g., 5 minutes. For example, they may appear to be frozen or
stuck because they are waiting until a certain point in time that, however, is
never reached due to the delayed libfaketime activity. Avoid using this
functionality unless you are sure you really need it and know what you are
stuck because they are waiting until a certain point in time that, however, is
never reached due to the delayed libfaketime activity. Avoid using this
functionality unless you are sure you really need it and know what you are
doing.
4i) Spawning an external process
4i) "Limiting" libfaketime per process
--------------------------------------
faketime can be instructed to fake time related calls only for selected
commands or to fake time for each command except for a certain subset of
commands.
The environment variables are FAKETIME_ONLY_CMDS and FAKETIME_SKIP_CMDS
respectively.
Example:
FAKETIME_ONLY_CMDS=javadoc faketime '2008-12-24 08:15:42' make
will run the "make" command but the time faking will only be applied
to javadoc processes.
Multiple commands are separated by commas.
Example:
FAKETIME_SKIP_CMDS="javadoc,ctags" faketime '2008-12-24 08:15:42' make
will run the "make" command and apply time faking for everything "make"
does except for javadoc and ctags processes.
FAKETIME_ONLY_CMDS and FAKETIME_SKIP_CMDS are mutually exclusive, i.e.,
you cannot set them both at the same time. faketime will terminate with
an error message if both environment variables are set.
4j) Spawning an external process
--------------------------------
From version 0.9 on, libfaketime can execute a shell command once after an
arbitrary number of seconds or number of time-related system calls of the
program started. This has two limitations one needs to be aware of:
From version 0.9 on, libfaketime can execute a shell command once after a) an
arbitrary number of seconds has passed or b) a number of time-related system
calls has been made by the program since it started. This has two limitations
one needs to be aware of:
* Spawning the external process happens during a time-related system call
of the original program. If you want the external process to be started
@@ -401,7 +629,7 @@ program started. This has two limitations one needs to be aware of:
* The original program is blocked until the external process is finished,
because the intercepting time-related system call will not return earlier. If
you need to start a long-running external process, make sure it forks into the
background.
background.
Spawning the external process is controlled using three environment variables:
FAKETIME_SPAWN_TARGET, FAKETIME_SPAWN_SECONDS, FAKETIME_SPAWN_NUMCALLS.
@@ -415,24 +643,42 @@ export FAKETIME_SPAWN_SECONDS=5
This will run the "echo" command with the given parameter during the first
time-related system function call that "myprogram" performs after running for 5
seconds.
seconds.
4k) Saving timestamps to file, loading them from file
-----------------------------------------------------
faketime can save faked timestamps to a file specified by FAKETIME_SAVE_FILE
environment variable. It can also use the file specified by FAKETIME_LOAD_FILE
to replay timestamps from it. After consuming the whole file, libfaketime
returns to using the rule set in FAKETIME variable, but the timestamp processes
will start counting from will be the last timestamp in the file.
The file stores each timestamp in a stream of saved_timestamp structs
without any metadata or padding:
/* Storage format for timestamps written to file. Big endian. */
struct saved_timestamp {
int64_t sec;
uint64_t nsec;
};
faketime needs to be run using the faketime wrapper to use these files. This
functionality has been added by Balint Reczey in v0.9.5.
5. License
----------
FTPL has been released under the GNU Public License, GPL. Please see the
included COPYING file.
libfaketime has been released under the GNU General Public License, GPL.
Please see the included COPYING file.
6. Contact
-----------
Bug reports, feature suggestions, success reports and patches are highly
appreciated.
Please send an email to: wolf /at/ code-wizards.com
git pull requests are welcome, see https://github.com/wolfcw/libfaketime
Bug reports, feature suggestions, success reports, and patches/pull
requests are highly appreciated:
https://github.com/wolfcw/libfaketime

View File

@@ -1,52 +1,92 @@
README file for libfaketime on Mac OS X
=======================================
README file for libfaketime on macOS
====================================
Support for Mac OS X is still preliminary. Development and tests are
done under 10.7 Lion only currently.
Support for macOS has meanwhile matured and many command line and
GUI applications will run stable.
Compiling and using libfaketime on OS X is slightly different than
Developments and tests are done on Mojave currently.
Version 0.9.5 and higher no longer work with OSX <= 10.6 due to
changes in the underlying system libraries. If you need libfaketime
on OSX <= 10.6, please use libfaketime version 0.9.
Installing and using libfaketime on macOS is slightly different than
on Linux. Please make sure to read the README file for general
setup and usage, and refer to this file only about OS X specifics.
setup and usage, and refer to this file only about macOS specifics.
1) Compiling libfaketime on OS X
--------------------------------
1) Installing libfaketime on macOS
----------------------------------
Use the OSX-specific Makefiles that are provided, e.g.:
If you use MacPorts, libfaketime can be installed on the command line
as follows:
cd src/
make -f Makefile.MacOS
sudo port install libfaketime
The resulting library will be named libfaketime.dylib.1
Or, if you use Fink, install using:
fink install libfaketime
Or, if you use Homebrew, install using:
brew install libfaketime
Please inform the respective package maintainers if the latest release
is not yet available this way. With homebrew, you can typically use
"brew install --HEAD" to install from the latest source automatically.
Otherwise, you have to compile and install libfaketime manually; this
will require a working installation of Xcode and its command line tools
on your machine.
This library now supports GNU autotools, so you can build it using:
sh build.sh init
./configure
make
The resulting library will be named libfaketime.1.dylib ; to check
whether it works properly, run the test suite and verify whether its
output is correct:
cd test
make test
NOTE: When committing, be sure to clean up potentially
system-dependent files by running:
sh build.sh clean
2) Using libfaketime from the command line on OS X
--------------------------------------------------
2) Using libfaketime from the command line on macOS
---------------------------------------------------
You will need to set three environment variables. In a Terminal.app
or iTerm session, the following commands can be used:
You will need to set three environment variables. In a Terminal.app
or any other CLI session, the following commands can be used:
export DYLD_FORCE_FLAT_NAMESPACE=1
export DYLD_INSERT_LIBRARIES=/path/to/libfaketime.dylib.1
export DYLD_INSERT_LIBRARIES=/path/to/libfaketime.1.dylib
export FAKETIME="your favorite faketime-spec here"
Please refer to the general README file concerning the format
of the FAKETIME environment variable value and other environment
variables that are related to it.
The "faketime" wrapper shell script has been adapted to OS X;
The "faketime" wrapper application has been adapted to macOS;
it offers the same limited libfaketime functionality as on Linux
in a simple-to-use manner without the need to manually set
those environment variables.
those environment variables. Run "faketime" without parameters
for help and use "man faketime" for details.
3) Integrating libfaketime with applications
--------------------------------------------
Given the limited number of system calls libfaketime intercepts,
it does not work too well with GUI applications on OS X. Crashes
after a random time are common issues, some applications will
not or at least not always see the faked time, and so on.
it may not work too well with specific GUI applications on macOS.
This can result in crashes after a seemingly random time, or an
application will not or at least not always see the faked time,
and so on.
A safe way to try out whether a specific application works fine
with libfaketime is to start it from the command line. Perform
@@ -59,7 +99,7 @@ following command:
the name of your actual application.)
If it works fine, you can configure the application to permanently
run with libfaketime by editing its Info.plist file. Add the
run with libfaketime by editing its Info.plist file. Add the
LSEnvironment key unless it is already there and add a dictionary
with the three keys like this:
@@ -68,7 +108,7 @@ with the three keys like this:
<key>DYLD_FORCE_FLAT_NAMESPACE</key>
<string>1</string>
<key>DYLD_INSERT_LIBRARIES</key>
<string>/path/to/libfaketime.dylib.1</string>
<string>/path/to/libfaketime.1.dylib</string>
<key>FAKETIME</key>
<string>value of FAKETIME here</string>
</dict>
@@ -80,19 +120,40 @@ use appropriate editing or conversion tools.)
Afterwards, you will probably need to run
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/ApplicationName.app
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/ApplicationName.app
to make sure the change to Info.plist does not go unnoticed.
Please note that modifications to Info.plist will be lost when the
application is updated, so this process needs to be repeated after
Please note that modifications to Info.plist will be lost when the
application is updated, so this process needs to be repeated after
such updates, including own new builds when using Xcode.
Please feel free to report non-working applications on the Github
libfaketime issues website. This may help us to identify further
time-related system calls that need to be intercepted on macOS.
4) Notes for developers of OS X applications
--------------------------------------------
https://github.com/wolfcw/libfaketime/issues
However, there are two important aspects:
- When reporting non-working applications, please make sure that your issue is
not related to SIP (system integrity protection). For example, on a
SIP-enabled, default macOS installation, libfaketime will not work for
programs like /bin/bash because the path /bin is SIP-protected. Copy your
application to a non-SIP-protected path, and if libfaketime still does not
work, feel free to report it.
- We cannot and will not help with using libfaketime for proprietary or
commercial software unless you are its developer trying to integrate
libfaketime. Please contact the developers or the vendor directly if
you have problems using libfaketime with non-free / not open sourced
macOS applications.
4) Notes for developers of macOS applications
---------------------------------------------
The environment variable FAKETIME can be changed at application run-time
and always takes precedence over other user-controlled settings. It can
be re-set to 0 (zero) to work around potential incompatibilities.
be re-set to 0 (zero) to work around potential incompatibilities or if
you do not want libfaketime applied to your software.

113
README.developers Normal file
View File

@@ -0,0 +1,113 @@
This file contains information for libfaketime developers and contributors.
GENERAL
=======
Starting with libfaketime v0.9.5, development and issue handling is
completely done via Github:
https://github.com/wolfcw/libfaketime
- Official releases are tagged.
- Code contributions and bugfixes should be submitted to and then merged into
the "development" branch, which is considered unstable and may contain code
that is not yet fully tested.
- The "master" branch is updated with tested code only; it is ensured that
it compiles and works cleanly at least on current Linux and macOS systems.
Code contributions are highly welcome, preferably via pull requests on Github.
Please have a look at issues labelled as "help wanted" in the Github issue
tracker. If you are interested in contributing to libfaketime, helping with
these issues is not only much appreciated, but also a good way to familiarize
yourself with the overall codebase.
CODE STYLE
==========
Please try to stick to the following code formatting style guidelines:
- No tabs, only spaces for indentation.
- Avoid trailing whitespace.
- Indentation is 2 spaces for each level.
- Opening and closing curly brackets have to be on lines of their own.
- Use under_score_names for function and variable names; avoid using camelCase.
- // and /*...*/ style comments may and shall be used.
Example:
/* This function will do nothing */
void do_nothing(int how_often)
{
int counter;
for (counter = 0; counter < how_often; counter++)
{
counter = counter; // our do-nothing algorithm
}
}
- Use -DDEBUG and #ifdef DEBUG for development and testing. Avoid printing to
stdout or stderr outside "#ifdef DEBUG"; if it is necessary to inform the
user a run-time, prefix your output with "libfaketime" or make otherwise sure
that the user knows where the message is coming from.
- If you add new functions to libfaketime.c, try placing them somewhere
where they fit will: Usually, functions are grouped by functionality
(e.g., all functions related to faking file timestamps). If that's not
possible, group them by contributor, or document your placement strategy
in the commit message.
DEVELOPMENT, BUILDING, AND TESTING
==================================
- Don't break existing behaviour. Backward compatibility matters (unless
the modification fixes bugs :-)).
- Add tests for new features. Extend test/timetest.c appropriately and
try to use the functional testing framework wherever possible.
- Compiler and linker warnings are treated as errors and not acceptable.
- If you cannot test the code on both Linux and macOS yourself, please
let us know and consider wrapping your code in #ifdef / #ifndef __APPLE__
statements.
DOCUMENTATION
=============
For anything more than small bugfixes, please update the user documentation
and credits appropriately:
- The NEWS file should mention the change and your credits.
- The README and README.OSX files should be updated whenever functionality
is added or modified.
- The manpage man/faketime.1 should be updated when the wrapper application
is modified.
For credits, please either mention your real name, your Github username, or
your email address.
In your own interest, please be verbose on user documentation and comments
in the source code. Users will not know about new features unless they are
documented. Other authors and maintainers will need to understand your code
easily.
RELEASES
========
Official new releases are created whenever a significant amount of changes
(bugfixes or new functionality) has piled up; on average, there is one new
official release per 1-2 years. Users who need to stick to the bleeding edge
are supposed to use the current state of the "master" branch at any time.
libfaketime maintainers for several Linux distributions are informed about
release candidates and new releases by email. Contact wolfcw on Github if
you are interested in receiving notifications, or use Github functionality
to get informed about updates.

63
README.packagers Normal file
View File

@@ -0,0 +1,63 @@
README for packagers of libfaketime
First, thank you for your efforts to make libfaketime packages available
on your platform / distribution!
libfaketime has tagged releases about once every 1-2 years, made available
through github.com/wolfcw/libfaketime, but usually it is also safe (i.e.,
stable) to use the latest HEAD of the master branch, which contains bug
fixes since the last tagged release.
You may want to familiarize yourself with the options you can set into
src/Makefile, but sane defaults for stable operations have been chosen.
Currently, libfaketime does not use autotools yet, so there is
_no_ ./configure step, but "make" and "make test" will work as expected.
However, one problem makes it somewhat difficult to get libfaketime
working on different platforms:
libfaketime currently has the challenge that depending on the version
of glibc and the platform (e.g., x86_64 or aarch64) certain compiler
CFLAGS have to be set manually, as we have not yet found a way to
safely determine behavior at run-time automatically.
Please proceed as follows:
- run "make test". If everything runs through smoothly and you do not
encounter any hangs or test failure reports, use the binaries as
they are.
- If you encounter endless hangs during the CLOCK_REALTIME test,
add -DFORCE_PTHREAD_NONVER to the CFLAGS.
- If you encounter endless hangs during the CLOCK_MONOTONIC test,
add -DFORCE_MONOTONIC_FIX to the CFLAGS. If it works with that,
it's fine, otherwise additionally use -DFORCE_PTHREAD_NONVER.
CFLAGS can also be passed through the FAKETIME_COMPILE_CFLAGS environment
variable, so for example
FAKETIME_COMPILE_CFLAGS="-DFORCE_PTHREAD_NONVER" make test
would create the libfaketime binaries and run the tests with the
FORCE_PTHREAD_NONVER flag set in a single step. Likewise there is
FAKETIME_LINK_FLAGS.
Please do not use FORCE_MONOTONIC_FIX by default, as it would result
in incorrect operations on platforms that do not need it.
Our observations with a limited number of Linux distributions is that
libfaketime may require different compile flags per platform even
if the same distribution and glibc version is used across these
platforms.
As soon as we have found a reliable way to automatically choose the
correct compile-time flags, we will remove this burden from you as
packager for obvious reasons. Until then, please feel free to report
your experiences with different platforms and distribution versions
through the issue tracker on Github.
Again, thanks for your time and effort to make libfaketime available
easily for everyone else!

18
TODO
View File

@@ -1,7 +1,15 @@
Open issues / next steps for libfaketime development
Open issues / next steps for libfaketime development:
- add more functional tests that check more than the basic functionality
- use the new testing framework to also implement unit tests
- make the new "limiting" and "spawning" features more flexible to use
and available through the wrapper shell script
Please see the issue tracker on Github - https://github.com/wolfcw/libfaketime
- New features, such as additional system calls to intercept, are labelled
"feature request" when they are considered for implementation
- Issues labelled "help wanted" should be your starting point if you are
interested in contributing to libfaketime
Besides the open issues, two major changes are planned for the next release:
- integrate manchicken's autoconf/automake support to get rid of separate Makefile.OSX
- use the testing framework to also implement unit tests

270
ar-lib Executable file
View File

@@ -0,0 +1,270 @@
#! /bin/sh
# Wrapper for Microsoft lib.exe
me=ar-lib
scriptversion=2012-03-01.08; # UTC
# Copyright (C) 2010-2018 Free Software Foundation, Inc.
# Written by Peter Rosin <peda@lysator.liu.se>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
# func_error message
func_error ()
{
echo "$me: $1" 1>&2
exit 1
}
file_conv=
# func_file_conv build_file
# Convert a $build file to $host form and store it in $file
# Currently only supports Windows hosts.
func_file_conv ()
{
file=$1
case $file in
/ | /[!/]*) # absolute file, and not a UNC file
if test -z "$file_conv"; then
# lazily determine how to convert abs files
case `uname -s` in
MINGW*)
file_conv=mingw
;;
CYGWIN*)
file_conv=cygwin
;;
*)
file_conv=wine
;;
esac
fi
case $file_conv in
mingw)
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
;;
cygwin)
file=`cygpath -m "$file" || echo "$file"`
;;
wine)
file=`winepath -w "$file" || echo "$file"`
;;
esac
;;
esac
}
# func_at_file at_file operation archive
# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE
# for each of them.
# When interpreting the content of the @FILE, do NOT use func_file_conv,
# since the user would need to supply preconverted file names to
# binutils ar, at least for MinGW.
func_at_file ()
{
operation=$2
archive=$3
at_file_contents=`cat "$1"`
eval set x "$at_file_contents"
shift
for member
do
$AR -NOLOGO $operation:"$member" "$archive" || exit $?
done
}
case $1 in
'')
func_error "no command. Try '$0 --help' for more information."
;;
-h | --h*)
cat <<EOF
Usage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...]
Members may be specified in a file named with @FILE.
EOF
exit $?
;;
-v | --v*)
echo "$me, version $scriptversion"
exit $?
;;
esac
if test $# -lt 3; then
func_error "you must specify a program, an action and an archive"
fi
AR=$1
shift
while :
do
if test $# -lt 2; then
func_error "you must specify a program, an action and an archive"
fi
case $1 in
-lib | -LIB \
| -ltcg | -LTCG \
| -machine* | -MACHINE* \
| -subsystem* | -SUBSYSTEM* \
| -verbose | -VERBOSE \
| -wx* | -WX* )
AR="$AR $1"
shift
;;
*)
action=$1
shift
break
;;
esac
done
orig_archive=$1
shift
func_file_conv "$orig_archive"
archive=$file
# strip leading dash in $action
action=${action#-}
delete=
extract=
list=
quick=
replace=
index=
create=
while test -n "$action"
do
case $action in
d*) delete=yes ;;
x*) extract=yes ;;
t*) list=yes ;;
q*) quick=yes ;;
r*) replace=yes ;;
s*) index=yes ;;
S*) ;; # the index is always updated implicitly
c*) create=yes ;;
u*) ;; # TODO: don't ignore the update modifier
v*) ;; # TODO: don't ignore the verbose modifier
*)
func_error "unknown action specified"
;;
esac
action=${action#?}
done
case $delete$extract$list$quick$replace,$index in
yes,* | ,yes)
;;
yesyes*)
func_error "more than one action specified"
;;
*)
func_error "no action specified"
;;
esac
if test -n "$delete"; then
if test ! -f "$orig_archive"; then
func_error "archive not found"
fi
for member
do
case $1 in
@*)
func_at_file "${1#@}" -REMOVE "$archive"
;;
*)
func_file_conv "$1"
$AR -NOLOGO -REMOVE:"$file" "$archive" || exit $?
;;
esac
done
elif test -n "$extract"; then
if test ! -f "$orig_archive"; then
func_error "archive not found"
fi
if test $# -gt 0; then
for member
do
case $1 in
@*)
func_at_file "${1#@}" -EXTRACT "$archive"
;;
*)
func_file_conv "$1"
$AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $?
;;
esac
done
else
$AR -NOLOGO -LIST "$archive" | sed -e 's/\\/\\\\/g' | while read member
do
$AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
done
fi
elif test -n "$quick$replace"; then
if test ! -f "$orig_archive"; then
if test -z "$create"; then
echo "$me: creating $orig_archive"
fi
orig_archive=
else
orig_archive=$archive
fi
for member
do
case $1 in
@*)
func_file_conv "${1#@}"
set x "$@" "@$file"
;;
*)
func_file_conv "$1"
set x "$@" "$file"
;;
esac
shift
shift
done
if test -n "$orig_archive"; then
$AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $?
else
$AR -NOLOGO -OUT:"$archive" "$@" || exit $?
fi
elif test -n "$list"; then
if test ! -f "$orig_archive"; then
func_error "archive not found"
fi
$AR -NOLOGO -LIST "$archive" || exit $?
fi

46
build.sh Normal file
View File

@@ -0,0 +1,46 @@
#!/bin/sh
#autoreconf --install
# Thanks, https://github.com/raywill/automake
export AUTOM4TE="autom4te"
export AUTOCONF="autoconf"
# On OSX, it's glibtoolize
LIBTOOLIZE=$(which libtoolize)
if [ "$LIBTOOLIZE" = "" ]; then
LIBTOOLIZE=$(which glibtoolize)
fi
if [ "$LIBTOOLIZE" = "" ]; then
echo "CANNOT CONTINUE! MISSING (G)LIBTOOLIZE! Install libtool!" >&2
exit 2
fi
case "x$1" in
xinit)
[ -d m4 ] || mkdir m4
set -x
autoheader
aclocal
$LIBTOOLIZE --force --copy --automake
autoconf --force
automake --foreign --copy --add-missing -Woverride
;;
xclean)
echo 'cleaning...'
make distclean >/dev/null 2>&1
rm -rf autom4te.cache
for fn in aclocal.m4 configure config.guess config.sub depcomp install-sh \
ltmain.sh libtool missing mkinstalldirs config.log config.status Makefile; do
rm -f $fn
done
find . -name Makefile.in -exec rm -f {} \;
find . -name Makefile -exec rm -f {} \;
find . -name .deps -prune -exec rm -rf {} \;
echo 'done'
;;
*)
./configure
;;
esac

62
configure.ac Normal file
View File

@@ -0,0 +1,62 @@
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
m4_define([lft_major_version], [0])
m4_define([lft_minor_version], [9])
m4_define([lft_micro_version], [8])
m4_define([libfaketime_version],
[lft_major_version.lft_minor_version.lft_micro_version])
AC_PREREQ([2.68])
AC_INIT([libfaketime], [libfaketime_version])
AC_SUBST([LIBTOOL_DEPS])
#AC_CONFIG_MACRO_DIRS([m4])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AM_CONDITIONAL(MACOS, test `uname` = "Darwin")
AM_CONDITIONAL(SOLARIS, test `uname` = "SunOS")
eval PREFIX=`test "$prefix" = NONE && prefix=$ac_default_prefix; eval echo "${prefix}"`
eval LIBPREFIX="$PREFIX/lib"
LIBFAKETIME_MAJOR_VERSION=lft_major_version
AC_SUBST(PREFIX)
AC_SUBST(LIBPREFIX)
AC_SUBST(LIBVERSION)
AC_DEFINE_UNQUOTED(PREFIX, "$PREFIX", [The install prefix for the package])
AC_DEFINE_UNQUOTED(LIBPREFIX, "$LIBPREFIX", [The install prefix for libraries])
AC_DEFINE(LIBVERSION, ["lft_major_version"], [The library version number])
AC_CONFIG_SRCDIR([src])
AC_CONFIG_HEADERS([config.h])
# libtool versioning
LIBFAKETIME_VERSION=libfaketime_version
AC_SUBST(LIBFAKETIME_VERSION)
# Checks for programs.
AC_PROG_CC
AM_PROG_AR
# Checks for libraries.
AC_CHECK_LIB([c], [timespecadd], [timespecmul])
## FORESHADOWING...
## AC_CHECK_LIB([cunit], [CU_assertImplementation])
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h sys/param.h unistd.h stdbool.h time.h netinet/in.h math.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT32_T
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([memset])
LT_INIT
AC_CONFIG_FILES([Makefile src/Makefile test/Makefile man/Makefile])
AC_OUTPUT

View File

@@ -1,14 +0,0 @@
INSTALL = install
PREFIX = /usr/local
all:
install:
$(INSTALL) -Dm0644 faketime.1 "${DESTDIR}${PREFIX}/share/man/man1/faketime.1"
gzip -f "${DESTDIR}${PREFIX}/share/man/man1/faketime.1"
uninstall:
rm -f "${DESTDIR}${PREFIX}/share/man/man1/faketime.1.gz"
.PHONY: all install uninstall

18
man/Makefile.am Normal file
View File

@@ -0,0 +1,18 @@
ACLOCAL_AMFLAGS=-I m4
dist_man_MANS = faketime.1
# INSTALL ?= install
#
# PREFIX ?= /usr/local
#
# all:
#
# install:
# $(INSTALL) -Dm0644 faketime.1 "${DESTDIR}${PREFIX}/share/man/man1/faketime.1"
# gzip -f "${DESTDIR}${PREFIX}/share/man/man1/faketime.1"
#
# uninstall:
# rm -f "${DESTDIR}${PREFIX}/share/man/man1/faketime.1.gz"
#
# .PHONY: all install uninstall

View File

@@ -1,4 +1,4 @@
.TH FAKETIME "1" "August 2008" "faketime 0.8" W.Hommel
.TH FAKETIME "1" "August 2019" "faketime 0.9.8" wolfcw
.SH NAME
faketime \- manipulate the system time for a given command
.SH SYNOPSIS
@@ -7,11 +7,11 @@ faketime \- manipulate the system time for a given command
.SH DESCRIPTION
.\" \fIfaketime\fR will trick the given program into seeing the specified timestamp as its starting date and time.
.PP
The given command will be tricked into believing that the current system time is the one specified in the timestamp. The wall clock will continue to run
from this date and time unless specified otherwise (see advanced options). Actually, faketime is a simple wrapper for libfaketime, which uses the LD_PRELOAD
mechanism to load a small library which intercepts system calls to functions such as
\fItime(2)\fR and \fIfstat(2)\fR. This wrapper exposes only a subset of libfaketime's functionality; please refer to the README file that came with faketime
for more details and advanced options.
The given command will be tricked into believing that the current system time is the one specified in the timestamp. Filesystem timestamps will also be
reported relative to this timestamp. The wall clock will continue to run from this date and time unless specified otherwise (see advanced options).
Actually, faketime is a simple wrapper for libfaketime, which uses the LD_PRELOAD mechanism to load a small library which intercepts system calls to
functions such as \fItime(2)\fR and \fIfstat(2)\fR. This wrapper exposes only a subset of libfaketime's functionality; please refer to the README file
that came with faketime for more details and advanced options, or have a look at http://github.com/wolfcw/libfaketime
.SH OPTIONS
.TP
\fB\-\-help\fR
@@ -25,6 +25,9 @@ use the multi-threading variant of libfaketime.
.TP
\fB\-f\fR
use the advanced timestamp specification format.
.TP
\fB\--exclude-monotonic\fR
Do not fake time when the program makes a call to clock_gettime with a CLOCK_MONOTONIC clock.
.SH EXAMPLES
.nf
@@ -32,38 +35,43 @@ faketime 'last Friday 5 pm' /bin/date
faketime '2008-12-24 08:15:42' /bin/date
faketime -f '+2,5y x10,0' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'
faketime -f '+2,5y x0,50' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'
faketime -f '+2,5y i2,0' /bin/bash -c 'while true; do date ; sleep 1 ; done'
In this single case all spawned processes will use the same global clock without restarting it at the start of each process.
(Please note that it depends on your locale settings whether . or , has to be used for fractional offsets)
.fi
.SH ADVANCED TIMESTAMP FORMAT
The simple timestamp format used by default applies the \fB/bin/date -d\fR command to parse user-friendly specifications such as 'last friday'. When using
the faketime option \fB\-f\fR, the timestamp specified on the command line is directly passed to libfaketime, which enables a couple of additional features
such as speeding the clock up or slowing it down for the target program. It is strongly recommended that you have a look at the README file that came with
faketime for the details. Summary:
such as speeding the clock up or slowing it down for the target program. It is strongly recommended that you have a look at the libfaketime documentation. Summary:
.TP
Freeze clock at absolute timestamp: \fB"YYYY-MM-DD hh:mm:ss"\fR
If you want to specify an absolute point in time, exactly this format must be used. Please note that freezing the clock is usually not what you want and may break the application. Only use if you know what you're doing!
.TP
Relative time offset: \fB"[+/-]123[m/h/d/y]\fR, e.g. "+60m", "+2y"
This is the most often used format and specifies the faked time relatively to the current real time. The first character of the format string \fBmust\fR be a + or a -. The numeric value by default represents seconds, but the modifiers m, h, d, and y can be used to specify minutes, hours, days, or years, respectively. For example, "-2y" means "two years ago". Fractional time offsets can be used, e.g. "+2,5y", which means "two and a half years in the future". Please note that the fraction delimiter depends on your locale settings, so if "+2,5y" does not work, you might want to try "+2.5y".
This is the most often used format and specifies the faked time relatively to the current real time. The first character of the format string \fBmust\fR be a + or a -. The numeric value by default represents seconds, but the modifiers m, h, d, and y can be used to specify minutes, hours, days, or years, respectively. For example, "-2y" means "two years ago". Fractional time offsets can be used, e.g. "+2,5y", which means "two and a half years in the future". Please note that the fraction delimiter depends on your locale settings, so if "+2,5y" does not work, you might want to try "+2.5y".
.TP
Start-at timestamps: \fB"@YYYY-MM-DD hh:mm:ss"\fR
The wall clock will start counting at the given timestamp for the program. This can be used for specifying absolute timestamps without freezing the clock.
The wall clock will start counting at the given timestamp for the program. This can be used for specifying absolute timestamps without freezing the clock.
.SH ADVANCED USAGE
When using relative time offsets or start-at timestamps (see ADVANCED TIMESTAMP FORMAT above and option \fB\-f\fR), the clock speed can be adjusted, i.e. time may run faster or slower for the executed program. For example, \fB"+5y x10"\fR will set the faked time 5 years into the future and make the time pass 10 times as fast (one real second equals 10 seconds measured by the program). Similarly, the flow of time can be slowed, e.g. using \fB"-7d x0,2"\fR, which will set the faked time 7 days in the past and set the clock speed to 20 percent, i.e. it takes five real world seconds for one second measured by the program. Again, depending on your locale, either "x2.0" or "x2,0" may be required regarding the delimiter.
When using relative time offsets or start-at timestamps (see ADVANCED TIMESTAMP FORMAT above and option \fB\-f\fR), the clock speed can be adjusted, i.e. time may run faster or slower for the executed program. For example, \fB"+5y x10"\fR will set the faked time 5 years into the future and make the time pass 10 times as fast (one real second equals 10 seconds measured by the program). Similarly, the flow of time can be slowed, e.g. using \fB"-7d x0,2"\fR, which will set the faked time 7 days in the past and set the clock speed to 20 percent, i.e. it takes five real world seconds for one second measured by the program. Again, depending on your locale, either "x2.0" or "x2,0" may be required regarding the delimiter. You can also make faketime to advance the reported time by a preset interval upon each time() call independently from the system's time using \fB"-7d i2,0"\fR, where
\fB"i"\fR is followed by the increase interval in seconds.
.PP
Faking times for multiple programs or even system-wide can be simplified by using ~/.faketimerc files and /etc/faketimerc. Please refer to the README that came with faketime for warnings and details.
.PP
Faking of filesystem timestamps may be disabled by setting the NO_FAKE_STAT environment variable to a non-empty value.
.SH AUTHOR
Maintained by Wolfgang Hommel <wolf@code-wizards.com>. Please see the README and Changelog files for contributers.
Please see the README and NEWS files for contributors.
.SH BUGS
Due to limitations of the LD_PRELOAD mechanism, faketime will not work with suidroot and statically linked programs.
Due to limitations of the LD_PRELOAD mechanism, faketime will not work with suidroot and statically linked programs.
While timestamps and time offsets will work for child processes, speeding the clock up or slowing it down might not
work for child processes spawned by the executed program as expected; a new instance of libfaketime is used for each
child process, which means that the libfaketime start time, which is used in speed adjustments, will also be
re-initialized.
child process, which means that the libfaketime start time, which is used in speed adjustments, will also be
re-initialized. Some programs may dynamically load system libraries, such as librt, at run-time and therefore bypass libfaketime. You may report programs that do not work with libfaketime, but only if they are available as open source.
.SH "REPORTING BUGS"
Please send an e-mail to Wolfgang Hommel <wolf@code-wizards.com>
Please use https://github.com/wolfcw/libfaketime/issues
.SH COPYRIGHT
Copyright \(co 2003-2008 by Wolfgang Hommel.
Copyright \(co 2003-2013 by the libfaketime authors.
.PP
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. You may redistribute copies of faketime under the

View File

@@ -1,92 +0,0 @@
#
# Notes:
#
# * Compilation Defines:
#
# FAKE_STAT
# - Enables time faking also for files' timestamps.
#
# NO_ATFILE
# - Disables support for the fstatat() group of functions
#
# PTHREAD
# - Define this to enable multithreading support.
#
# PTHREAD_SINGLETHREADED_TIME
# - Define this if you want to single-thread time() ... there ARE
# possibile caching side-effects in a multithreaded environment
# without this, but the performance impact may require you to
# try it unsynchronized.
#
# FAKE_INTERNAL_CALLS
# - Also intercept libc internal __functions, e.g. not just time(),
# but also __time(). Enhances compatibility with applications
# that make use of low-level system calls, such as Java Virtual
# Machines.
#
# NO_CACHING
# - Disables the caching of the fake time offset. Only disable caching
# if you change the fake time offset during program runtime very
# frequently. Disabling the cache may negatively influence the
# performance.
#
# LIMITEDFAKING
# - Support environment variables that limit time faking to certain
# time intervals or number of function calls.
#
# SPAWNSUPPORT
# - Enable support for spawning an external process at a given
# timestamp.
#
# * Compilation addition: second libMT target added for building the pthread-
# enabled library as a separate library
#
# * Compilation switch change: previous versions compiled using '-nostartfiles'
# This is no longer the case since there is a 'startup' constructor for the library
# which is used to activate the start-at times when specified. This also initializes
# the dynamic disabling of the FAKE_STAT calls.
#
CC = gcc
INSTALL = install
PREFIX = /usr/local
CFLAGS += -std=gnu99 -Wall -DFAKE_STAT -DFAKE_INTERNAL_CALLS -fPIC -DPOSIX_REALTIME -DLIMITEDFAKING -DSPAWNSUPPORT
LDFLAGS += -shared -ldl -lm -lpthread
SRC = faketime.c
OBJ = faketime.o faketimeMT.o
SONAME = 1
LIBS = libfaketime.so.${SONAME} libfaketimeMT.so.${SONAME}
all: ${LIBS}
faketimeMT.o: EXTRA_FLAGS := -DPTHREAD -DPTHREAD_SINGLETHREADED_TIME
${OBJ}: faketime.c
${CC} -o $@ -c ${CFLAGS} ${EXTRA_FLAGS} $<
lib%.so.${SONAME}: %.o
${CC} -o $@ -Wl,-soname,$@ ${LDFLAGS} $<
clean:
@rm -f ${OBJ} ${LIBS}
distclean: clean
@echo
install: ${LIBS}
@echo
@echo "Copying the faketime libraries to ${DESTDIR}${PREFIX}/lib/faketime and the faketime wrapper script to ${DESTDIR}${PREFIX}/bin ..."
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/lib/faketime/"
$(INSTALL) -m0644 ${LIBS} "${DESTDIR}${PREFIX}/lib/faketime/"
$(INSTALL) -Dm0755 faketime "${DESTDIR}${PREFIX}/bin/faketime"
uninstall:
for f in ${LIBS}; do rm -f "${DESTDIR}${PREFIX}/lib/faketime/$$f"; done
rmdir "${DESTDIR}${PREFIX}/lib/faketime"
rm -f "${DESTDIR}${PREFIX}/bin/faketime"
.PHONY: all clean distclean install uninstall

View File

@@ -1,91 +0,0 @@
#
# Notes:
#
# * Compilation Defines:
#
# FAKE_STAT
# - Enables time faking also for files' timestamps.
#
# NO_ATFILE
# - Disables support for the fstatat() group of functions
#
# PTHREAD
# - Define this to enable multithreading support.
#
# PTHREAD_SINGLETHREADED_TIME
# - Define this if you want to single-thread time() ... there ARE
# possibile caching side-effects in a multithreaded environment
# without this, but the performance impact may require you to
# try it unsynchronized.
#
# FAKE_INTERNAL_CALLS
# - Also intercept libc internal __functions, e.g. not just time(),
# but also __time(). Enhances compatibility with applications
# that make use of low-level system calls, such as Java Virtual
# Machines.
#
# NO_CACHING
# - Disables the caching of the fake time offset. Only disable caching
# if you change the fake time offset during program runtime very
# frequently. Disabling the cache may negatively influence the
# performance.
#
# LIMITEDFAKING
# - Support environment variables that limit time faking to certain
# time intervals or number of function calls.
#
# SPAWNSUPPORT
# - Enable support for spawning an external process at a given
# timestamp.
#
#
# * Compilation addition: second libMT target added for building the pthread-
# enabled library as a separate library
#
# * Compilation switch change: previous versions compiled using '-nostartfiles'
# This is no longer the case since there is a 'startup' constructor for the library
# which is used to activate the start-at times when specified. This also initializes
# the dynamic disabling of the FAKE_STAT calls.
#
CC = gcc
INSTALL = install
PREFIX = /usr/local
# If you get an error about an unsupported architecture, remove it. Some
# versions of XCode support different subsets of architectures, depending on
# age.
# 10.5
#CFLAGS = -dynamiclib -DFAKE_INTERNAL_CALLS -arch i386 -arch ppc
# 10.6
CFLAGS = -dynamiclib -DFAKE_INTERNAL_CALLS -arch i386 -arch x86_64 -DLIMITEDFAKING -DSPAWNSUPPORT
SRC = faketime.c
SONAME = 1
LIBS = libfaketime.dylib.${SONAME}
all: ${LIBS}
libfaketime.dylib.${SONAME}: ${SRC}
${CC} -o $@ ${CFLAGS} $<
clean:
@rm -f ${OBJ} ${LIBS}
distclean: clean
@echo
install: ${LIBS}
@echo
@echo "Copying the faketime libraries to ${DESTDIR}${PREFIX}/lib/faketime and the faketime wrapper script to ${DESTDIR}${PREFIX}/bin ..."
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/lib/faketime/"
$(INSTALL) -m0644 ${LIBS} "${DESTDIR}${PREFIX}/lib/faketime/"
$(INSTALL) -Dm0755 faketime "${DESTDIR}${PREFIX}/bin/faketime"
uninstall:
for f in ${LIBS}; do rm -f "${DESTDIR}${PREFIX}/lib/faketime/$$f"; done
rmdir "${DESTDIR}${PREFIX}/lib/faketime"
rm -f "${DESTDIR}${PREFIX}/bin/faketime"
.PHONY: all clean distclean install uninstall

39
src/Makefile.am Normal file
View File

@@ -0,0 +1,39 @@
ACLOCAL_AMFLAGS=-I m4
LIBTOOL_DEPS = @LIBTOOL_DEPS@
LIBOBJDIR = "."
libtool: $(LIBTOOL_DEPS)
$(SHELL) ./config.status libtool
AM_CFLAGS =-DFAKE_SLEEP -DFAKE_INTERNAL_CALLS
AM_LDFLAGS =
if SOLARIS
AM_CFLAGS += -D__EXTENSIONS__ -D_XOPEN_SOURCE=600
AM_LDFLAGS += -Wl,--version-script=@srcdir@/libfaketime.map
endif
if !MACOS
AM_CFLAGS += -std=gnu99 -Wall -Wextra -Werror -DFAKE_STAT -DFAKE_PTHREAD -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -Wno-nonnull-compare
endif
LTCFLAGS=""
EXTRA_DIST=libfaketime.map
lib_LTLIBRARIES = libfaketime.la libfaketimeMT.la
libfaketime_la_SOURCES = libfaketime.c
libfaketimeMT_la_SOURCES = libfaketime.c
noinst_HEADERS = faketime_common.h sunos_endian.h time_ops.h uthash.h
bin_PROGRAMS = faketime
faketime_SOURCES = faketime.c
if MACOS
libfaketime_la_LDFLAGS = -dynamiclib -current_version 0.9.8 -compatibility_version 0.7
else
libfaketime_la_LIBADD = -ldl -lm -lrt -lpthread
libfaketime_la_LDFLAGS = -shared -Wl,--version-script=@srcdir@/libfaketime.map
libfaketimeMT_la_LIBADD = -ldl -lm -lrt -lpthread
libfaketimeMT_la_CFLAGS = -DPTHREAD_SINGLETHREADED_TIME
libfaketimeMT_la_LDFLAGS = -shared -Wl,--version-script=@srcdir@/libfaketime.map -DPTHREAD_SINGLETHREADED_TIME
faketime_LDADD = -ldl -lm -lrt -lpthread
endif

128
src/Makefile.default Normal file
View File

@@ -0,0 +1,128 @@
#
# Notes:
#
# * Compilation Defines:
#
# FAKE_STAT
# - Enables time faking also for files' timestamps.
#
# NO_ATFILE
# - Disables support for the fstatat() group of functions
#
# 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_INTERNAL_CALLS
# - Also intercept libc internal __functions, e.g. not just time(),
# but also __time(). Enhances compatibility with applications
# that make use of low-level system calls, such as Java Virtual
# Machines.
#
# FAKE_SLEEP
# - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll()
#
# FAKE_TIMERS
# - Also intercept timer_settime() and timer_gettime()
#
# FAKE_PTHREAD
# - Intercept pthread_cond_timedwait
#
# FAKE_SETTIME
# - Intercept clock_settime(), settimeofday(), and adjtime()
#
# FORCE_MONOTONIC_FIX
# - If the test program hangs forever on
# " pthread_cond_timedwait: CLOCK_MONOTONIC test
# (Intentionally sleeping 1 second...) "
# then add -DFORCE_MONOTONIC_FIX to CFLAGS and recompile.
# (This is a platform-specific issue we cannot handle at run-time.)
#
# MULTI_ARCH
# - If MULTI_ARCH is set, the faketime wrapper program will put a literal
# $LIB into the LD_PRELOAD environment variable it creates, which makes
# ld automatically choose the correct library version to use for the
# target binary. Use for Linux platforms with Multi-Arch support only!
#
# * Compilation addition: second libMT target added for building the pthread-
# enabled library as a separate library
#
# * Compilation switch change: previous versions compiled using '-nostartfiles'
# This is no longer the case since there is a 'startup' constructor for the library
# which is used to activate the start-at times when specified. This also initializes
# the dynamic disabling of the FAKE_STAT calls.
#
# By default, libfaketime will be compiled for your system's default architecture.
# To build 32-bit libraries and binaries, add -m32 to CFLAGS and LDFLAGS.
#
# Change PREFIX to where you want libfaketime (libraries and wrapper binary) installed.
# LIBDIRNAME is relative to PREFIX. The default is to install into $PREFIX/lib/faketime,
# but you can set LIBDIRNAME to, e.g., /lib64 if you want to install it elsewhere.
# LIBDIRNAME has been introduced to support MultiLib systems. Please do not change the
# default value on MultiArch systems.
#
# For testing in the current directory without installation, try make PREFIX= LIBDIRNAME='.'
CC ?= gcc
INSTALL ?= install
PREFIX ?= /usr/local
LIBDIRNAME ?= /lib/faketime
PLATFORM ?=$(shell uname)
CFLAGS += -std=gnu99 -Wall -Wextra -Werror -Wno-nonnull-compare -DFAKE_PTHREAD -DFAKE_STAT -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'$(PREFIX)'"' -DLIBDIRNAME='"'$(LIBDIRNAME)'"' $(FAKETIME_COMPILE_CFLAGS)
ifeq ($(PLATFORM),SunOS)
CFLAGS += -D__EXTENSIONS__ -D_XOPEN_SOURCE=600
endif
LIB_LDFLAGS += -shared
LDFLAGS += $(FAKETIME_LINK_FLAGS) -lpthread
ifneq ($(PLATFORM),SunOS)
LDFLAGS += -Wl,--version-script=libfaketime.map
endif
LDADD += -ldl -lm -lrt
BIN_LDFLAGS += -lrt
SRC = libfaketime.c
LIBS_OBJ = libfaketime.o libfaketimeMT.o
BINS = faketime
SONAME = 1
LIBS = libfaketime.so.${SONAME} libfaketimeMT.so.${SONAME}
all: ${LIBS} ${BINS}
libfaketimeMT.o: EXTRA_FLAGS := -DPTHREAD_SINGLETHREADED_TIME
${LIBS_OBJ}: libfaketime.c
${CC} -o $@ -c ${CFLAGS} ${CPPFLAGS} ${EXTRA_FLAGS} $<
%.so.${SONAME}: %.o libfaketime.map
${CC} -o $@ -Wl,-soname,$@ ${LDFLAGS} ${LIB_LDFLAGS} $< ${LDADD}
${BINS}: faketime.c
${CC} -o $@ ${CFLAGS} ${CPPFLAGS} ${EXTRA_FLAGS} $< ${LDFLAGS} ${BIN_LDFLAGS}
clean:
@rm -f ${LIBS_OBJ} ${LIBS} ${BINS}
distclean: clean
@echo
install: ${LIBS} ${BINS}
@echo
@echo "Copying the faketime libraries to ${DESTDIR}${PREFIX}${LIBDIRNAME} and the faketime wrapper script to ${DESTDIR}${PREFIX}/bin ..."
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}${LIBDIRNAME}/"
$(INSTALL) -m0644 ${LIBS} "${DESTDIR}${PREFIX}${LIBDIRNAME}/"
$(INSTALL) -Dm0755 faketime "${DESTDIR}${PREFIX}/bin/faketime"
uninstall:
for f in ${LIBS}; do rm -f "${DESTDIR}${PREFIX}${LIBDIRNAME}/$$f"; done
rmdir "${DESTDIR}${PREFIX}${LIBDIRNAME}"
rm -f "${DESTDIR}${PREFIX}/bin/faketime"
.PHONY: all clean distclean install uninstall

View File

@@ -1,114 +0,0 @@
#!/bin/sh
# Simple wrapper shell script for FTPL (faketime preload library)
# Thanks to Daniel Kahn Gillmor for improvement suggestions.
# It allows you to modify the date and time a program sees when using
# system library calls such as time() and fstat().
# This wrapper exposes only a small subset of the FTPL functionality.
# Please see FTPL's README file for more details
# Acknowledgment: Parts of the functionality of this wrapper have been
# inspired by Matthias Urlichs' datefudge 1.14.
# Configuration: Path where the libfaketime libraries can be found on Linux/UNIX.
FTPL_PATH=/usr/lib/faketime
# For Mac OS X users: Full path and name to libfaketime.dylib.1
MAC_FTPL_PATH=./libfaketime.dylib.1
offset="$1"
DATE_CMD=date
USEMT=0
USEDIRECT=0
if [ "$offset" = "-v" -o "$offset" = "--version" ] ; then
echo ""
echo "$0: Version 0.8"
echo "For usage information please use '$0 --help'."
echo ""
exit 0
fi
if [ "$offset" = "-m" ] ; then USEMT=1; shift; offset="$1"; fi
if [ "$offset" = "-f" ] ; then USEDIRECT=1; shift; offset="$1"; fi
if [ "$offset" = "-m" ] ; then USEMT=1; shift; offset="$1"; fi
if [ -z "$offset" -o "$offset" = "-h" -o "$offset" = "-?" -o "$offset" = "--help" ] ; then
echo ""
echo "Usage: $0 [switches] timestamp program arguments"
echo ""
echo "This will run the specified 'program' with the given 'arguments'."
echo "The program will be tricked into seeing the given 'timestamp' as its starting date and time."
echo "The clock will continue to run from this timestamp. Please see the manpage (man faketime)"
echo "for advanced options, such as stopping the wall clock and make it run faster or slower."
echo ""
echo "The optional switches are:"
echo " -m : Use the multi-threaded version of libfaketime"
echo " -f : Use the advanced timestamp specification format (see manpage)"
echo ""
echo "Examples:"
echo "$0 'last friday 5 pm' /bin/date"
echo "$0 '2008-12-24 08:15:42' /bin/date"
echo "$0 -f '+2,5y x10,0' /bin/bash -c 'date; while true; do echo \$SECONDS ; sleep 1 ; done'"
echo "$0 -f '+2,5y x0,50' /bin/bash -c 'date; while true; do echo \$SECONDS ; sleep 1 ; done'"
echo "(Please note that it depends on your locale settings whether . or , has to be used for fractions)"
echo ""
if [ -z "$offset" ] ; then
exit 1;
fi
exit 0
fi
shift
# Check whether we are on Mac OS X (Darwin)
UNAME=$(uname)
if [ "$UNAME" = "Darwin" ] ; then
export DYLD_FORCE_FLAT_NAMESPACE=1
export DYLD_INSERT_LIBRARIES=$MAC_FTPL_PATH
DATE_CMD=gdate
fi
# Setting LD_PRELOAD ...
if [ "$USEMT" -eq 0 ] ; then
export LD_PRELOAD="${LD_PRELOAD}${LD_PRELOAD:+:}$FTPL_PATH/libfaketime.so.1"
fi
if [ "$USEMT" -eq 1 ] ; then
export LD_PRELOAD="${LD_PRELOAD}${LD_PRELOAD:+:}$FTPL_PATH/libfaketimeMT.so.1"
fi
###
# Setting FAKETIME ...
if [ "$USEDIRECT" -eq 0 ] ; then
seconds=$($DATE_CMD -d "$offset" '+%s')
if [ $? -ne 0 ] ; then
echo "Error: Timestamp to fake not recognized, please re-try with a different timestamp."
exit 1
fi
offset=$(expr $seconds - $($DATE_CMD '+%s'))
if [ $? -ne 0 ] ; then
echo "Error: Cannot calculate the faketime offset in seconds, please re-try with a different timestamp."
exit 1
fi
FAKETIMEPREFIX=""
if [ "$offset" -ge 0 ] ; then
FAKETIMEPREFIX="+"
fi
export FAKETIME="$FAKETIMEPREFIX$offset"
fi
if [ "$USEDIRECT" -eq 1 ] ; then
export FAKETIME="$offset"
fi
###
# Executing the user-specified command ...
exec "$@"

File diff suppressed because it is too large Load Diff

85
src/faketime_common.h Normal file
View File

@@ -0,0 +1,85 @@
/*
* Faketime's common definitions
*
* Copyright 2013 Balint Reczey <balint@balintreczey.hu>
*
* This file is part of the libfaketime.
*
* libfaketime is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License v2 as published by the Free
* Software Foundation.
*
* libfaketime is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License v2 along
* with libfaketime; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef FAKETIME_COMMON_H
#define FAKETIME_COMMON_H
#include <stdint.h>
struct system_time_s
{
/* System time according to CLOCK_REALTIME */
struct timespec real;
/* System time according to CLOCK_MONOTONIC */
struct timespec mon;
/* System time according to CLOCK_MONOTONIC_RAW */
struct timespec mon_raw;
#ifdef CLOCK_BOOTTIME
/* System time according to CLOCK_BOOTTIME */
struct timespec boot;
#endif
};
/* Data shared among faketime-spawned processes */
struct ft_shared_s
{
/*
* When advancing time linearly with each time(), etc. call, the calls are
* counted here */
uint64_t ticks;
/* Index of timstamp to be loaded from file */
uint64_t file_idx;
/* System time Faketime started at */
struct system_time_s start_time;
};
/* These are all needed in order to properly build on OSX */
#ifdef __APPLE__
#include <mach/clock.h>
#include <mach/mach_host.h>
#include <mach/mach_port.h>
#endif
#ifdef FAKE_SLEEP
#include <time.h>
#include <poll.h>
#include <sys/types.h>
#include <semaphore.h>
/*
* Fake sleep prototypes!
*/
struct pollfd;
int nanosleep(const struct timespec *req, struct timespec *rem);
int usleep(useconds_t usec);
unsigned int sleep(unsigned int seconds);
unsigned int alarm(unsigned int seconds);
int ppoll(struct pollfd *fds, nfds_t nfds,
const struct timespec *timeout_ts, const sigset_t *sigmask);
int poll(struct pollfd *fds, nfds_t nfds, int timeout);
int select(int nfds, fd_set *readfds,
fd_set *writefds,
fd_set *errorfds,
struct timeval *timeout);
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);
#endif /* FAKE_SLEEP */
#endif

3473
src/libfaketime.c Normal file

File diff suppressed because it is too large Load Diff

21
src/libfaketime.map Normal file
View File

@@ -0,0 +1,21 @@
GLIBC_2.2 {
global:
timer_gettime; timer_settime;
local: timer_settime_*; timer_gettime_*;
};
GLIBC_2.3.3 {
# Changed timer_t.
timer_gettime; timer_settime;
} GLIBC_2.2;
GLIBC_2.2.5 {
global: pthread_cond_timedwait;
local: pthread_cond_timedwait_*; pthread_cond_init_*; pthread_cond_destroy*;
};
GLIBC_2.3.2 {
pthread_cond_timedwait; pthread_cond_init; pthread_cond_destroy;
} GLIBC_2.2.5;

12
src/sunos_endian.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef SUN_OS_ENDIAN_H
#define SUN_OS_ENDIAN_H
#include <sys/byteorder.h>
#define htobe64(x) BE_64(x)
#define be64toh(x) BE_64(x)
#define htole64(x) LE_64(x)
#define le64toh(x) LE_64(x)
#endif /* SUN_OS_ENDIAN_H */

116
src/time_ops.h Normal file
View File

@@ -0,0 +1,116 @@
/*
* Time operation macros based on sys/time.h
* Copyright 2013 Balint Reczey <balint@balintreczey.hu>
*
* This file is part of libfaketime.
*
* libfaketime is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License v2 as published by the Free
* Software Foundation.
*
* libfaketime is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License v2 along
* with libfaketime; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TIME_OPS_H
#define TIME_OPS_H
#include <time.h>
#define SEC_TO_uSEC 1000000
#define SEC_TO_nSEC 1000000000
/* Convenience macros for operations on timevals.
NOTE: `timercmp' does not work for >= or <=. */
#define timerisset2(tvp, prefix) ((tvp)->tv_sec || (tvp)->tv_##prefix##sec)
#define timerclear2(tvp, prefix) ((tvp)->tv_sec = (tvp)->tv_##prefix##sec = 0)
#define timercmp2(a, b, CMP, prefix) \
(((a)->tv_sec == (b)->tv_sec) ? \
((a)->tv_##prefix##sec CMP (b)->tv_##prefix##sec) : \
((a)->tv_sec CMP (b)->tv_sec))
#define timeradd2(a, b, result, prefix) \
do \
{ \
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(result)->tv_##prefix##sec = (a)->tv_##prefix##sec + \
(b)->tv_##prefix##sec; \
if ((result)->tv_##prefix##sec >= SEC_TO_##prefix##SEC) \
{ \
++(result)->tv_sec; \
(result)->tv_##prefix##sec -= SEC_TO_##prefix##SEC; \
} \
} while (0)
#define timersub2(a, b, result, prefix) \
do \
{ \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_##prefix##sec = (a)->tv_##prefix##sec - \
(b)->tv_##prefix##sec; \
if ((result)->tv_##prefix##sec < 0) \
{ \
--(result)->tv_sec; \
(result)->tv_##prefix##sec += SEC_TO_##prefix##SEC; \
} \
} while (0)
#define timermul2(tvp, c, result, prefix) \
do \
{ \
int64_t tmp_time; \
tmp_time = (c) * (int64_t) ((tvp)->tv_sec * SEC_TO_##prefix##SEC + \
(int64_t) (tvp)->tv_##prefix##sec); \
(result)->tv_##prefix##sec = tmp_time % SEC_TO_##prefix##SEC; \
(result)->tv_sec = (tmp_time - (result)->tv_##prefix##sec) / \
SEC_TO_##prefix##SEC; \
if ((result)->tv_##prefix##sec < 0) \
{ \
(result)->tv_##prefix##sec += SEC_TO_##prefix##SEC; \
(result)->tv_sec -= 1; \
} \
} while (0)
/* ops for microsecs */
#ifndef timerisset
#define timerisset(tvp) timerisset2(tvp,u)
#endif
#ifndef timerclear
#define timerclear(tvp) timerclear2(tvp, u)
#endif
#ifndef timercmp
#define timercmp(a, b, CMP) timercmp2(a, b, CMP, u)
#endif
#ifndef timeradd
#define timeradd(a, b, result) timeradd2(a, b, result, u)
#endif
#ifndef timersub
#define timersub(a, b, result) timersub2(a, b, result, u)
#endif
#ifndef timermul
#define timermul(a, c, result) timermul2(a, c, result, u)
#endif
/* ops for nanosecs */
#ifndef timespecisset
#define timespecisset(tvp) timerisset2(tvp,n)
#endif
#ifndef timespecclear
#define timespecclear(tvp) timerclear2(tvp, n)
#endif
#ifndef timespeccmp
#define timespeccmp(a, b, CMP) timercmp2(a, b, CMP, n)
#endif
#ifndef timespecadd
#define timespecadd(a, b, result) timeradd2(a, b, result, n)
#endif
#ifndef timespecsub
#define timespecsub(a, b, result) timersub2(a, b, result, n)
#endif
#ifndef timespecmul
#define timespecmul(a, c, result) timermul2(a, c, result, n)
#endif
#endif

270
src/timeprivacy Normal file
View File

@@ -0,0 +1,270 @@
#!/bin/bash
## Copyright (c) 2013, adrelanos at riseup dot net
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions are met:
##
## 1. Redistributions of source code must retain the above copyright notice, this
## list of conditions and the following disclaimer.
## 2. Redistributions in binary form must reproduce the above copyright notice,
## this list of conditions and the following disclaimer in the documentation
## and/or other materials provided with the distribution.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
## (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#set -x
SCRIPTNAME="$(basename $0)"
usage() {
echo "$SCRIPTNAME
Usage: $SCRIPTNAME [-h help] [-d day] [-m month] [-y year] [-i increment in seconds (0-60)] [-r random increment in seconds (0-60)] [-f history folder]
Example: $SCRIPTNAME -d 30 -m 12 -y 2013 -i 10 -f /tmp/$SCRIPTNAMEtest
sudo $SCRIPTNAME -d 30 -m 12 -y 2013 -r -f /tmp/$SCRIPTNAMEtest"
}
_randomincrement="none"
_increment="none"
while [ -n "$1" ]; do
case "$1" in
-h)
usage
exit 0
;;
-d)
_day="$2"
shift
;;
-m)
_month="$2"
shift
;;
-y)
_year="$2"
shift
;;
-i)
_increment="$2"
shift
;;
-r)
_randomincrement="$2"
shift
;;
-f)
TIMEDIR="$2"
shift
;;
*)
command="$(which $1)"
## From now on the complete to-be wrapped command + its args
## are stored in $@, which will expand like we want it for
## handling quoted arguments with whitespaces in it, etc.
break
esac
shift
done
if [ -z "$_day" ]; then
_day="$(date +"%d")"
fi
if [ -z "$_month" ]; then
_month="$(date +"%m")"
fi
if [ -z "$_year" ]; then
_year="$(date +"%Y")"
fi
if [ "$_randomincrement" = "none" ] && [ "$_increment" = "none" ]; then
_increment="1"
fi
if [ "$_randomincrement" = "none" ]; then
if [ -z "$_increment" ]; then
_increment="1"
fi
elif [ "$_increment" = "none" ]; then
if [ "$_randomincrement" = "" ]; then
echo "randomincrement must be a positive number."
exit 1
else
## random number between 1 and $_randomincrement
random_number="$(( 0+($(od -An -N2 -i /dev/random) )%($_randomincrement-0+1) ))"
_increment="$random_number"
fi
else
echo "You can not combine -r and -i."
exit 1
fi
if [ -z "$TIMEDIR" ]; then
TIMEDIR=~/.timeprivacy
fi
nodigits="$(echo $_increment | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "increment is not a digit."
exit 1
fi
nodigits="$(echo $_year | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "_day is not a digit."
exit 1
fi
nodigits="$(echo $_year | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "year is not a digit."
exit 1
fi
nodigits="$(echo $_month | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "month is not a digit."
exit 1
fi
nodigits="$(echo $_day | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "day is not a digit."
exit 1
fi
nodigits="$(echo $_increment | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
echo "increment is not a digit."
exit 1
fi
SECONDS_FILE="$TIMEDIR/seconds_file"
MINUTES_FILE="$TIMEDIR/minutes_file"
HOURS_FILE="$TIMEDIR/hours_file"
#DAYS_FILE="$TIMEDIR/days_file"
#MONTHS_FILE="$TIMEDIR/months_file"
#YEARS_FILE="$TIMEDIR/years_file"
#true "TIMEDIR: $TIMEDIR"
#true "year: $_year"
#true "month: $_month"
#true "day: $_day"
#true "_randomincrement: $_randomincrement"
#true "_increment: $_increment"
read_date_file() {
if [ ! -d "$TIMEDIR" ]; then
mkdir -p "$TIMEDIR"
fi
if [ ! -f "$SECONDS_FILE" ]; then
echo "0" > "$SECONDS_FILE"
fi
if [ ! -f "$MINUTES_FILE" ]; then
echo "0" > "$MINUTES_FILE"
fi
if [ ! -f "$HOURS_FILE" ]; then
echo "0" > "$HOURS_FILE"
fi
#if [ ! -f "$DAYS_FILE" ]; then
#echo "1" > "$DAYS_FILE"
#fi
#if [ ! -f "$MONTHS_FILE" ]; then
#echo "1" > "$MONTHS_FILE"
#fi
#if [ ! -f "$YEARS_FILE" ]; then
#echo "2013" > "$YEARS_FILE"
#fi
SECONDS="$(cat "$SECONDS_FILE")"
MINUTES="$(cat "$MINUTES_FILE")"
HOURS="$(cat "$HOURS_FILE")"
if [ -z "$SECONDS" ]; then
SECONDS="0"
fi
if [ -z "$MINUTES" ]; then
MINUTES="0"
fi
if [ -z "$HOURS" ]; then
HOURS="0"
fi
local nodigits="$(echo $SECONDS | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
SECONDS="0"
fi
local nodigits="$(echo $MINUTES | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
MINUTES="0"
fi
local nodigits="$(echo $HOURS | sed 's/[[:digit:]]//g')"
if [ ! -z "$nodigits" ]; then
HOURS="0"
fi
SECONDS="$(expr "$SECONDS" + "$_increment")" || true
if [ "$SECONDS" -ge "60" ]; then
SECONDS="0"
MINUTES="$(expr "$MINUTES" + "1")" || true
if [ "$MINUTES" -ge "60" ]; then
MINUTES="0"
HOURS="$(expr "$HOURS" + "1")" || true
if [ "$HOURS" -ge "24" ]; then
HOURS="0"
fi
echo "$HOURS" > "$HOURS_FILE"
fi
echo "$MINUTES" > "$MINUTES_FILE"
fi
echo "$SECONDS" > "$SECONDS_FILE"
#echo "$HOURS $MINUTES $SECONDS"
}
need_new_date() {
## Testing
#while [ 1 ]; do
# read_date_file
#done
read_date_file
## Testing
#echo "faketime '$_year-$_month-$_day $HOURS:$MINUTES:$SECONDS' /bin/date"
#faketime "$_year-$_month-$_day $HOURS:$MINUTES:$SECONDS" /bin/date
echo "$_year-$_month-$_day $HOURS:$MINUTES:$SECONDS"
}
need_new_date

1208
src/uthash.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,31 +0,0 @@
CC = gcc
CFLAGS = -std=gnu99 -Wall -DFAKE_STAT
LDFLAGS = -lrt
SRC = timetest.c
OBJ = ${SRC:.c=.o}
all: timetest test
.c.o:
${CC} -c ${CFLAGS} $<
timetest: ${OBJ}
${CC} -o $@ ${OBJ} ${LDFLAGS}
test: timetest functest
@echo
@./test.sh
# run functional tests
functest:
./testframe.sh functests
clean:
@rm -f ${OBJ} timetest
distclean: clean
@echo
.PHONY: all test clean distclean

View File

@@ -1,31 +0,0 @@
CC = gcc
CFLAGS = -std=gnu99 -Wall -DFAKE_STAT
LDFLAGS =
SRC = timetest.c
OBJ = ${SRC:.c=.o}
all: timetest test
.c.o:
${CC} -c ${CFLAGS} $<
timetest: ${OBJ}
${CC} -o $@ ${OBJ} ${LDFLAGS}
test: timetest functest
@echo
@./test.sh
# run functional tests
functest:
./testframe.sh functests
clean:
@rm -f ${OBJ} timetest
distclean: clean
@echo
.PHONY: all test clean distclean

29
test/Makefile.am Normal file
View File

@@ -0,0 +1,29 @@
AM_CPPFLAGS =-DFAKE_SLEEP -DFAKE_INTERNAL_CALLS -I@top_srcdir@/src
AM_CFLAGS =
AM_LDFLAGS =
# functests.sh fail for me, test.sh hangs for me.
# TESTS = test.sh functests.sh
check_PROGRAMS = timetest
timetest_SOURCES = timetest.c
check_SCRIPTS = functests.sh testframe.sh test.sh
EXTRA_DIST = $(check_SCRIPTS) \
functests/common.inc \
functests/dont_test_false.sh \
functests/test_exclude_mono.sh \
functests/test_null.sh \
functests/test_true.sh \
functests/test_walkone.sh
if SOLARIS
AM_CPPFLAGS += -D__EXTENSIONS__ -D_XOPEN_SOURCE=600
AM_LDFLAGS += -Wl,--version-script=libfaketime.map
endif
if !MACOS
AM_CPPFLAGS += -DFAKE_STAT -DFAKE_PTHREAD -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS
AM_CFLAGS += -std=gnu99 -Wall -Wextra -Werror -fPIC -Wno-nonnull-compare
timetest_LDADD = -ldl -lm -lrt -lpthread
endif

View File

@@ -24,7 +24,7 @@
# testsuite script can make use of any functions defined
# in these inc files. the environment variable
# TESTSUITE_NAME is set to the filename of the testsuite
# script, for possible use in warning or info messages.
# script, for possible use in warning or info messages.
#
# see functests/test_true.sh for a simple example of
# a test suite script.
@@ -35,5 +35,5 @@
# 3. create DIR/test_XXX.sh.
# 4. write a run function and testcase functions in DIR/test_XXX.sh.
# 5. within the run function, call run_testcase for each testcase function.
# 6. within each testcase funtion, call assertneq or asserteq, or do
# 6. within each testcase function, call assertneq or asserteq, or do
# the equivalent.

7
test/functests.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
set -e
[ "${srcdir}" ] || srcdir=.
# run functional tests
# cd "${srcdir}/"
${srcdir}/testframe.sh ${srcdir}/functests

View File

@@ -1,5 +1,8 @@
# libfaketime-specific common support routines for tests
LIB_BUILD_PATH="../src/$(grep 'LT_OBJDIR' ../config.h | cut -d'"' -f2)"
LIBFAKETIME_LA=$(find "$LIB_BUILD_PATH" | grep 'libfaketime\.\(dylib\|so\)$')
# say which *_fakecmd wrapper to use
platform()
{
@@ -8,6 +11,8 @@ platform()
case "$out" in
*Darwin*) echo "mac" ;;
*Linux*) echo "linuxlike" ;;
GNU|GNU/kFreeBSD) echo "linuxlike" ;;
*SunOS*) echo "sunos" ;;
*) echo 1>&2 unsupported platform, uname=\"$out\" ;;
esac
}
@@ -17,18 +22,27 @@ platform()
mac_fakecmd()
{
typeset timestring="$1"; shift
typeset fakelib=../src/libfaketime.dylib.1
typeset fakelib="$LIBFAKETIME_LA"
export DYLD_INSERT_LIBRARIES=$fakelib
export DYLD_FORCE_FLAT_NAMESPACE=1
FAKETIME="$timestring" \
"$@"
}
sunos_fakecmd()
{
typeset timestring="$1"; shift
typeset fakelib="$LIBFAKETIME_LA"
export LD_PRELOAD=$fakelib
FAKETIME="$timestring" \
"$@"
}
# run faked command on linuxlike OS
linuxlike_fakecmd()
{
typeset timestring="$1"; shift
typeset fakelib=../src/libfaketime.so.1
typeset fakelib="$LIBFAKETIME_LA"
export LD_PRELOAD=$fakelib
FAKETIME="$timestring" \
"$@"

View File

@@ -4,4 +4,3 @@ run()
{
run_testcase false
}

View File

@@ -0,0 +1,88 @@
# Checks that setting FAKETIME_DONT_FAKE_MONOTONIC actually prevent
# libfaketime from faking monotonic clocks.
#
# We do this by freezing time at a specific and arbitrary date with faketime,
# and making sure that if we set FAKETIME_DONT_FAKE_MONOTONIC to 1, calling
# clock_gettime(CLOCK_MONOTONIC) returns two different values.
#
# We also make sure that if we don't set FAKETIME_DONT_FAKE_MONOTONIC to 1,
# in other words when we use the default behavior, two subsequent calls to
# clock_gettime(CLOCK_MONOTONIC) do return different values.
init()
{
typeset testsuite="$1"
PLATFORM=$(platform)
if [ -z "$PLATFORM" ]; then
echo "$testsuite: unknown platform! quitting"
return 1
fi
echo "# PLATFORM=$PLATFORM"
return 0
}
run()
{
init
run_testcase dont_fake_mono
# run_testcase fake_mono
}
get_token()
{
string=$1
token_index=$2
separator=$3
echo $string | cut -d "$separator" -f $token_index
}
assert_timestamps_neq()
{
timestamps=$1
msg=$2
first_timestamp=$(get_token "${timestamps}" 1 ' ')
second_timestamp=$(get_token "${timestamps}" 2 ' ')
assertneq "${first_timestamp}" "${second_timestamp}" "${msg}"
}
assert_timestamps_eq()
{
timestamps=$1
msg=$2
first_timestamp=$(get_token "${timestamps}" 1 ' ')
second_timestamp=$(get_token "${timestamps}" 2 ' ')
asserteq "${first_timestamp}" "${second_timestamp}" "${msg}"
}
get_monotonic_time()
{
dont_fake_mono=$1; shift;
clock_id=$1; shift;
FAKETIME_DONT_FAKE_MONOTONIC=${dont_fake_mono} \
fakecmd "2014-07-21 09:00:00" \
/bin/bash -c "for i in 1 2; do \
perl -w -MTime::HiRes=clock_gettime,${clock_id} -E \
'say clock_gettime(${clock_id})'; \
sleep 1; \
done"
}
dont_fake_mono()
{
timestamps=$(get_monotonic_time 1 CLOCK_MONOTONIC)
msg="When not faking monotonic time, timestamps should be different"
assert_timestamps_neq "${timestamps}" "${msg}"
}
fake_mono()
{
timestamps=$(get_monotonic_time 0 CLOCK_MONOTONIC)
msg="When faking monotonic, timestamps should be equal"
assert_timestamps_eq "${timestamps}" "${msg}"
}

View File

@@ -1,8 +1,7 @@
# test suite that always succeds - for testing framework
# test suite that always succeeds - for testing framework
run()
{
run_testcase true
return 0
}

View File

@@ -37,7 +37,15 @@ fakedate()
#
typeset fmt='%s'
export FAKETIME_FMT=$fmt
fakecmd "$1" date +$fmt
if [ "mac" == "$PLATFORM" ]; then
if [ -x /usr/local/bin/gdate ] ; then
fakecmd "$1" gdate +$fmt
else
echo "<skip>"
fi
else
fakecmd "$1" date +$fmt
fi
}
#
@@ -63,5 +71,14 @@ test_with_i()
typeset i="$1"
typeset t=$(pow 2 $i)
asserteq $(fakedate $t) $t "(secs since Epoch)"
if [ "mac" == "$PLATFORM" ]; then
if [ -x /usr/local/bin/gdate ] ; then
asserteq $(fakedate $t) $t "(secs since Epoch)"
else
asserteq $t $t "(skipping test, install gdate)"
fi
else
asserteq $(fakedate $t) $t "(secs since Epoch)"
fi
}

View File

@@ -1,40 +1,104 @@
#!/bin/sh
##################################################################
# NOTICE: #
# When you edit this script, maintain compatibility with BASH 3. #
# This is the version that Apple distributes. #
##################################################################
LIB_BUILD_PATH="../src/$(grep 'LT_OBJDIR' ../config.h | cut -d'"' -f2)"
LIBFAKETIME_LA=$(find "$LIB_BUILD_PATH" | grep 'libfaketime\.\(dylib\|so\)$')
set_libfaketime() {
the_path="$LIBFAKETIME_LA"
if [ "$(uname)" = "Darwin" ]; then
export DYLD_INSERT_LIBRARIES="$the_path"
export DYLD_FORCE_FLAT_NAMESPACE=1
else
export LD_PRELOAD="$the_path"
fi
}
echo $(set_libfaketime)
if [ -f /etc/faketimerc ] ; then
echo "Running the test program with your system-wide default in /etc/faketimerc"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 ./timetest
echo "\$ $(set_libfaketime) ./timetest"
set_libfaketime
./timetest
echo
else
echo "Running the test program with no faked time specified"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 ./timetest
echo "\$ $(set_libfaketime) ./timetest"
set_libfaketime
./timetest
echo
fi
echo "============================================================================="
echo
echo "Running the test program with absolute date 2003-01-01 10:00:05 specified"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"2003-01-01 10:00:05\" ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="2003-01-01 10:00:05" ./timetest
echo "\$ $(set_libfaketime) FAKETIME=\"2003-01-01 10:00:05\" ./timetest"
set_libfaketime
export FAKETIME="2003-01-01 10:00:05"
./timetest
echo
echo "============================================================================="
echo
echo "Running the test program with START date @2005-03-29 14:14:14 specified"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"@2005-03-29 14:14:14\" ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="@2005-03-29 14:14:14" ./timetest
echo "\$ $(set_libfaketime) FAKETIME=\"@2005-03-29 14:14:14\" ./timetest"
set_libfaketime
export FAKETIME="@2005-03-29 14:14:14"
./timetest
echo
echo "============================================================================="
echo
echo "Running the test program with 10 days negative offset specified"
echo "LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-10d\" ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-10d" ./timetest
echo "$(set_libfaketime) FAKETIME=\"-10d\" ./timetest"
set_libfaketime
export FAKETIME="-10d"
./timetest
echo
echo "============================================================================="
echo
echo "Running the test program with 10 days negative offset specified, and FAKE_STAT disabled"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-10d\" NO_FAKE_STAT=1 ./timetest"
LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-10d" NO_FAKE_STAT=1 ./timetest
echo "\$ $(set_libfaketime) FAKETIME=\"-10d\" NO_FAKE_STAT=1 ./timetest"
set_libfaketime
export FAKETIME="-10d"
export NO_FAKE_STAT=1
./timetest
echo
echo "============================================================================="
echo
echo "Running the test program with 10 days positive offset specified, and sped up 2 times"
echo "\$ $(set_libfaketime) FAKETIME=\"+10d x2\" ./timetest"
set_libfaketime
export FAKETIME="+10d x2"
export NO_FAKE_STAT=1
./timetest
echo
echo "============================================================================="
echo
echo "Running the 'date' command with 15 days negative offset specified"
echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-15d\" date"
LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-15d" date
echo "\$ $(set_libfaketime) FAKETIME=\"-15d\" date"
set_libfaketime
export FAKETIME="-15d"
date
echo
echo "============================================================================="
echo "Testing finished."
exit 0

View File

@@ -6,6 +6,8 @@
# see README.testframe.txt for details.
#
testframedir="${BASH_SOURCE%/*}"
# echo labelled error/warning message to stderr
report()
{
@@ -33,7 +35,7 @@ run_testsuite()
# add testsuite dir to PATH for convenience
typeset dir=$(dirname $testsuite)
PATH=$dir:$PATH
. testframe.inc
. $testframedir/testframe.inc
if [ -f $dir/common.inc ]; then
. $dir/common.inc
fi

View File

@@ -3,13 +3,13 @@
*
* This file is part of the FakeTime Preload Library.
*
* The FakeTime Preload Library is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* The FakeTime Preload Library is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The FakeTime Preload Library is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* The FakeTime Preload Library is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
@@ -18,30 +18,201 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <sys/timeb.h>
#ifndef __APPLE__
#ifdef FAKE_STAT
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#else
#include <unistd.h>
#endif
#ifndef __APPLE__
#include <pthread.h>
#include <errno.h>
#include <signal.h>
#define VERBOSE 0
#define SIG SIGUSR1
static void
handler(int sig, siginfo_t *si, void *uc)
{
/* Note: calling printf() from a signal handler is not
strictly correct, since printf() is not async-signal-safe;
see signal(7) */
if ((si == NULL) || (si != uc))
{
printf("Caught signal %d\n", sig);
}
}
void* pthread_test(void* args)
{
pthread_mutex_t fakeMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t fakeCond = PTHREAD_COND_INITIALIZER;
pthread_cond_t monotonic_cond;
pthread_condattr_t attr;
struct timespec timeToWait, now;
int rt;
args = args; // silence compiler warning about unused argument
clock_gettime(CLOCK_REALTIME, &now);
timeToWait.tv_sec = now.tv_sec+1;
timeToWait.tv_nsec = now.tv_nsec;
printf("pthread_cond_timedwait: CLOCK_REALTIME test\n");
printf("(Intentionally sleeping 1 second...)\n");
fflush(stdout);
pthread_mutex_lock(&fakeMutex);
rt = pthread_cond_timedwait(&fakeCond, &fakeMutex, &timeToWait);
if (rt != ETIMEDOUT)
{
printf("pthread_cond_timedwait failed\n");
exit(EXIT_FAILURE);
}
pthread_mutex_unlock(&fakeMutex);
int main (int argc, char **argv) {
pthread_condattr_init(&attr);
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
pthread_cond_init(&monotonic_cond, &attr);
clock_gettime(CLOCK_MONOTONIC, &now);
timeToWait.tv_sec = now.tv_sec+1;
timeToWait.tv_nsec = now.tv_nsec;
printf("pthread_cond_timedwait: CLOCK_MONOTONIC test\n");
printf("(Intentionally sleeping 1 second..., see docs about CLOCK_MONOTONIC test)\n");
fflush(stdout);
pthread_mutex_lock(&fakeMutex);
rt = pthread_cond_timedwait(&monotonic_cond, &fakeMutex, &timeToWait);
if (rt != ETIMEDOUT)
{
printf("pthread_cond_timedwait failed\n");
exit(EXIT_FAILURE);
}
pthread_mutex_unlock(&fakeMutex);
pthread_cond_destroy(&monotonic_cond);
return NULL;
}
#endif
#include "faketime_common.h"
int main (int argc, char **argv)
{
time_t now;
struct timeb tb;
struct timeval tv;
#ifndef __APPLE__
struct timespec ts;
timer_t timerid1 = 0, timerid2;
struct sigevent sev;
struct itimerspec its;
sigset_t mask;
struct sigaction sa;
#endif
#ifndef __APPLE__
#ifdef FAKE_STAT
struct stat buf;
#endif
#endif
/* silence compiler warnings */
printf("%s", 0 == 1 ? argv[0] : "");
#ifndef __APPLE__
pthread_t thread;
void *ret;
pthread_create(&thread, NULL, pthread_test, NULL);
pthread_join(thread, &ret);
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = handler;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGUSR1, &sa, NULL) == -1)
{
perror("sigaction");
exit(EXIT_FAILURE);
}
/* Block timer signal temporarily */
printf("Blocking signal %d\n", SIGUSR1);
sigemptyset(&mask);
sigaddset(&mask, SIGUSR1);
if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1)
{
perror("sigaction");
exit(EXIT_FAILURE);
}
/* Create the timer */
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIGUSR1;
sev.sigev_value.sival_ptr = &timerid1;
if (timer_create(CLOCK_REALTIME, &sev, &timerid1) == -1)
{
perror("timer_create");
exit(EXIT_FAILURE);
}
/* Start timer1 */
/* start timer ticking after one second */
its.it_value.tv_sec = 1;
its.it_value.tv_nsec = 0;
/* fire in every 0.3 seconds */
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 300000000;
if (timer_settime(timerid1, 0, &its, NULL) == -1)
{
perror("timer_settime");
exit(EXIT_FAILURE);
}
sev.sigev_value.sival_ptr = &timerid2;
if (timer_create(CLOCK_REALTIME, &sev, &timerid2) == -1)
{
perror("timer_create");
exit(EXIT_FAILURE);
}
/* Start timer2 */
clock_gettime(CLOCK_REALTIME, &its.it_value);
/* start timer ticking after one second */
its.it_value.tv_sec += 3;
/* fire once */
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0;
if (timer_settime(timerid2, TIMER_ABSTIME, &its, NULL) == -1)
{
perror("timer_settime");
exit(EXIT_FAILURE);
}
#endif
time(&now);
printf("time() : Current date and time: %s", ctime(&now));
@@ -52,20 +223,75 @@ int main (int argc, char **argv) {
printf("(Intentionally sleeping 2 seconds...)\n");
fflush(stdout);
sleep(2);
if (argc < 3)
{
sleep(1);
usleep(1000000);
}
gettimeofday(&tv, NULL);
printf("gettimeofday() : Current date and time: %s", ctime(&tv.tv_sec));
#ifndef __APPLE__
if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1)
{
perror("sigprocmask");
exit(EXIT_FAILURE);
}
clock_gettime(CLOCK_REALTIME, &ts);
printf("clock_gettime(): Current date and time: %s", ctime(&ts.tv_sec));
int timer_getoverrun_timerid1 = timer_getoverrun(timerid1);
if (timer_getoverrun_timerid1 != 3)
{
printf("timer_getoverrun(timerid1) FAILED, must be 3 but got: %d\n", timer_getoverrun_timerid1);
}
timer_gettime(timerid1, &its);
if (VERBOSE == 1)
{
printf("timer_gettime(timerid1, &its); its = {{%ld, %ld}, {%ld, %ld}}}\n",
(long)its.it_interval.tv_sec, (long)its.it_interval.tv_nsec,
(long)its.it_value.tv_sec, (long)its.it_value.tv_nsec);
}
int timer_getoverrun_timerid2 = timer_getoverrun(timerid2);
if (timer_getoverrun_timerid2 != 0)
{
printf("timer_getoverrun(timerid2) FAILED, must be 0 but got: %d\n", timer_getoverrun_timerid2);
}
timer_gettime(timerid2, &its);
if (VERBOSE == 1)
{
printf("timer_gettime(timerid2, &its); its = {{%ld, %ld}, {%ld, %ld}}}\n",
(long)its.it_interval.tv_sec, (long)its.it_interval.tv_nsec,
(long)its.it_value.tv_sec, (long)its.it_value.tv_nsec);
}
#endif
#ifndef __APPLE__
#ifdef FAKE_STAT
lstat(argv[0], &buf);
printf("stat(): mod. time of file '%s': %s", argv[0], ctime(&buf.st_mtime));
#endif
#endif
return 0;
}
/*
* Editor modelines
*
* Local variables:
* c-basic-offset: 2
* tab-width: 2
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=2 tabstop=2 expandtab:
* :indentSize=2:tabSize=2:noTabs=true:
*/
/* eof */