mirror of
https://github.com/wolfcw/libfaketime.git
synced 2026-06-06 18:42:39 +03:00
Compare commits
104 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9a681c3e3 | ||
|
|
4ce283594f | ||
|
|
d42a2a9ec7 | ||
|
|
5d41d41da8 | ||
|
|
46aa5773c7 | ||
|
|
3fe3cf1536 | ||
|
|
b23fbd5c5e | ||
|
|
fa88a28c4d | ||
|
|
6e4037768a | ||
|
|
fa91edb0a3 | ||
|
|
725c80673c | ||
|
|
4a9c93475e | ||
|
|
842c2e4269 | ||
|
|
af0b2f85a7 | ||
|
|
120f6898f4 | ||
|
|
3c0ce9c885 | ||
|
|
2c78776aaf | ||
|
|
5dd65efa14 | ||
|
|
d1fdfb1950 | ||
|
|
57b098c98a | ||
|
|
47e958b753 | ||
|
|
1d5976d1ab | ||
|
|
582ae36e1d | ||
|
|
8fb6330a28 | ||
|
|
da778084e5 | ||
|
|
9220b5c58e | ||
|
|
b68f2820c4 | ||
|
|
4786b94f8e | ||
|
|
0d790dabb6 | ||
|
|
6de283f621 | ||
|
|
7f907c32fc | ||
|
|
0af6be50cb | ||
|
|
b193c95475 | ||
|
|
d95d96f5ea | ||
|
|
904cc5007d | ||
|
|
811b7916ad | ||
|
|
74425d76e1 | ||
|
|
3a26d7b3bb | ||
|
|
4398deaa3d | ||
|
|
18f5ec0671 | ||
|
|
638a535b5f | ||
|
|
cc4c1c3a29 | ||
|
|
6357820d52 | ||
|
|
64cb35857c | ||
|
|
28d0acfedb | ||
|
|
3ed13f498c | ||
|
|
afbb1f20c2 | ||
|
|
68772ec36a | ||
|
|
3bb30f74b3 | ||
|
|
0bde083556 | ||
|
|
10b479cf29 | ||
|
|
75896bdd32 | ||
|
|
6c207c9c68 | ||
|
|
527478d318 | ||
|
|
48ef50f6c3 | ||
|
|
035add4eff | ||
|
|
455261985d | ||
|
|
e680ca9bce | ||
|
|
1c5a717528 | ||
|
|
bdd0f0aea9 | ||
|
|
7c26cffac6 | ||
|
|
cac3dc732a | ||
|
|
c7d7eeb49d | ||
|
|
cae9387908 | ||
|
|
a6c8bb4636 | ||
|
|
95b70c7acc | ||
|
|
841b782a4c | ||
|
|
03da54787c | ||
|
|
d19da98bb4 | ||
|
|
3bed636a41 | ||
|
|
70aa6b394d | ||
|
|
1faf137f72 | ||
|
|
7d1a8307e1 | ||
|
|
7fdcd1adaf | ||
|
|
c3e4760338 | ||
|
|
740e2858dc | ||
|
|
1b6cdf3d0f | ||
|
|
a34c2bd8c3 | ||
|
|
b28b5c3a5d | ||
|
|
106818614d | ||
|
|
e653c388bf | ||
|
|
64519e28e0 | ||
|
|
0d04c87755 | ||
|
|
c2ca839b6a | ||
|
|
368f58c0f8 | ||
|
|
04ae576541 | ||
|
|
2d0cc5d86b | ||
|
|
3a8a2b0351 | ||
|
|
1f938d9642 | ||
|
|
5fb86ae178 | ||
|
|
27a4e3a7ad | ||
|
|
23200c4321 | ||
|
|
76edab7837 | ||
|
|
3ac3286356 | ||
|
|
bb278fc159 | ||
|
|
1bb5ee3920 | ||
|
|
d1e7781db6 | ||
|
|
9c2b1a6295 | ||
|
|
3a2d8e2ccc | ||
|
|
c719a977a7 | ||
|
|
c1cc101f91 | ||
|
|
cd3597174c | ||
|
|
458c6d693d | ||
|
|
a8f8378e77 |
23
Makefile
23
Makefile
@@ -1,31 +1,34 @@
|
||||
INSTALL ?= install
|
||||
|
||||
UNAME=$(shell uname)
|
||||
SELECTOR:=$(shell if test "${UNAME}" = "Darwin" ; then echo "-f Makefile.OSX" ; fi)
|
||||
|
||||
all:
|
||||
$(MAKE) -C src all
|
||||
$(MAKE) $(SELECTOR) -C src all
|
||||
|
||||
test:
|
||||
$(MAKE) -C test all
|
||||
$(MAKE) $(SELECTOR) -C test all
|
||||
|
||||
install:
|
||||
$(MAKE) -C src install
|
||||
$(MAKE) -C man install
|
||||
$(MAKE) $(SELECTOR) -C src install
|
||||
$(MAKE) $(SELECTOR) -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
|
||||
$(MAKE) $(SELECTOR) -C src uninstall
|
||||
$(MAKE) $(SELECTOR) -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
|
||||
$(MAKE) $(SELECTOR) -C src clean
|
||||
$(MAKE) $(SELECTOR) -C test clean
|
||||
|
||||
distclean:
|
||||
$(MAKE) -C src distclean
|
||||
$(MAKE) -C test distclean
|
||||
$(MAKE) $(SELECTOR) -C src distclean
|
||||
$(MAKE) $(SELECTOR) -C test distclean
|
||||
|
||||
.PHONY: all test install uninstall clean distclean
|
||||
|
||||
33
Makefile.OSX
33
Makefile.OSX
@@ -1,33 +0,0 @@
|
||||
INSTALL ?= install
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
|
||||
all:
|
||||
$(MAKE) -f Makefile.OSX -C src all
|
||||
|
||||
test:
|
||||
$(MAKE) -f Makefile.OSX -C test all
|
||||
|
||||
install:
|
||||
$(MAKE) -f Makefile.OSX -C src install
|
||||
$(MAKE) -f Makefile.OSX -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) -f Makefile.OSX -C src uninstall
|
||||
$(MAKE) -f Makefile.OSX -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) -f Makefile.OSX -C src clean
|
||||
$(MAKE) -f Makefile.OSX -C test clean
|
||||
|
||||
distclean:
|
||||
$(MAKE) -f Makefile.OSX -C src distclean
|
||||
$(MAKE) -f Makefile.OSX -C test distclean
|
||||
|
||||
.PHONY: all test install uninstall clean distclean
|
||||
18
NEWS
18
NEWS
@@ -1,3 +1,19 @@
|
||||
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.
|
||||
@@ -41,7 +57,7 @@ Since 0.8.2:
|
||||
|
||||
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!
|
||||
|
||||
240
README
240
README
@@ -1,7 +1,5 @@
|
||||
=======================================================
|
||||
libfaketime, version 0.9.5 (October 2013)
|
||||
(previously also know as FakeTime Preload Library)
|
||||
=======================================================
|
||||
libfaketime, version 0.9.7 (November 2017)
|
||||
==========================================
|
||||
|
||||
|
||||
Content of this file:
|
||||
@@ -18,63 +16,63 @@ 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
|
||||
j) Saving timestamps to file, loading them from file
|
||||
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
|
||||
---------------
|
||||
|
||||
libfaketime 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.
|
||||
|
||||
libfaketime allows you to specify both absolute dates (e.g., 01/01/2004) and
|
||||
relative dates (e.g., 10 days ago).
|
||||
|
||||
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
|
||||
-----------------------
|
||||
|
||||
* libfaketime has been designed on and for Linux, but is supposed and has been
|
||||
reported to work on other *NIXes as well, including Mac OS X.
|
||||
- libfaketime is supposed to work on Linux and macOS.
|
||||
Your mileage may vary; some other *NIXes have been reported to work as well.
|
||||
|
||||
* libfaketime uses the library preload mechanism and thus cannot work with
|
||||
- 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 (man ld).
|
||||
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
|
||||
(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
|
||||
@@ -86,21 +84,20 @@ libfaketime might be used for various purposes, for example
|
||||
libfaketime-specific files are present.
|
||||
|
||||
|
||||
|
||||
3. Installation
|
||||
---------------
|
||||
|
||||
Running "make" should compile both library versions and a test program, which
|
||||
it then also executes.
|
||||
Running "make" compiles both library versions and a test program, which it then
|
||||
also executes.
|
||||
|
||||
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
|
||||
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.
|
||||
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,
|
||||
@@ -114,16 +111,15 @@ 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 OS X, it is necessary to compile differently, due to the different
|
||||
behavior dyld has. Use the Makefile.MacOS provided to compile
|
||||
On macOS, it is necessary to compile differently, due to the different
|
||||
behavior dyld has. Use the Makefile.OSX file provided to compile
|
||||
libfaketime.1.dylib. Additionally, instead of using LD_PRELOAD,
|
||||
the variable DYLD_INSERT_LIBRARIES should be set to the path to
|
||||
libfaketime.1.dylib, and the variable DYLD_FORCE_FLAT_NAMESPACE should be
|
||||
set (to anything). Mac OS X users should read README.OSX for additional
|
||||
set (to anything). macOS users should read README.OSX for additional
|
||||
details.
|
||||
|
||||
|
||||
|
||||
4. Usage
|
||||
--------
|
||||
|
||||
@@ -135,26 +131,29 @@ Using libfaketime on a program of your choice consists of two steps:
|
||||
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 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"
|
||||
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 libfaketime enabled is to
|
||||
make sure the environment variable LD_PRELOAD contains the full path and
|
||||
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
|
||||
@@ -162,28 +161,34 @@ LD_PRELOAD=/path/to/libfaketime.so.1 your_command_here
|
||||
(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, libfaketime
|
||||
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
|
||||
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
|
||||
@@ -191,13 +196,13 @@ 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.
|
||||
|
||||
|
||||
@@ -208,27 +213,26 @@ 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.
|
||||
|
||||
|
||||
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
|
||||
@@ -252,7 +256,7 @@ 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 libfaketime on
|
||||
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.
|
||||
|
||||
@@ -268,14 +272,14 @@ 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, running
|
||||
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 restaring it at the start of each process.
|
||||
the same global clock without restarting it at the start of each process.
|
||||
|
||||
For testing, your should run a command like
|
||||
|
||||
@@ -287,10 +291,9 @@ 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
|
||||
@@ -304,8 +307,8 @@ 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
|
||||
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
|
||||
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
|
||||
for new mail every X minutes).
|
||||
|
||||
@@ -313,12 +316,14 @@ 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.
|
||||
|
||||
|
||||
4f) Faking the date and time system-wide
|
||||
@@ -357,7 +362,7 @@ 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!
|
||||
|
||||
@@ -365,8 +370,8 @@ 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.
|
||||
@@ -380,12 +385,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,
|
||||
|
||||
@@ -430,12 +435,40 @@ 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
|
||||
@@ -463,10 +496,10 @@ time-related system function call that "myprogram" performs after running for 5
|
||||
seconds.
|
||||
|
||||
|
||||
4j) Saving timestamps to file, loading them from file
|
||||
4k) Saving timestamps to file, loading them from file
|
||||
-----------------------------------------------------
|
||||
|
||||
Faketime can save faked timestamps to a file specified by FAKETIME_SAVE_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
|
||||
@@ -481,15 +514,15 @@ struct saved_timestamp {
|
||||
uint64_t nsec;
|
||||
};
|
||||
|
||||
Faketime needs to be run using the faketime wrapper to use these files. This
|
||||
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
|
||||
----------
|
||||
|
||||
libfaketime 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
|
||||
@@ -499,4 +532,3 @@ Bug reports, feature suggestions, success reports, and patches/pull
|
||||
requests are highly appreciated:
|
||||
|
||||
https://github.com/wolfcw/libfaketime
|
||||
|
||||
|
||||
58
README.OSX
58
README.OSX
@@ -1,15 +1,15 @@
|
||||
README file for libfaketime on Mac OS X
|
||||
=======================================
|
||||
README file for libfaketime on macOS
|
||||
====================================
|
||||
|
||||
Support for Mac OS X is still considered preliminary, although many
|
||||
command line and GUI applications will run stable.
|
||||
Support for macOS has meanwhile matured and many command line and
|
||||
GUI applications will run stable.
|
||||
|
||||
Developments and tests are done on OSX 10.8+ currently, although the
|
||||
current version will also work with OSX 10.7.
|
||||
Developments and tests are done on High Sierra currently.
|
||||
Use libfaketime 0.9.6 or earlier on OS X (i.e., before Sierra).
|
||||
|
||||
Version 0.9.5 no longer works 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.
|
||||
Version 0.9.5 and higher no longer works 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 OS X is slightly different than
|
||||
@@ -17,21 +17,31 @@ 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.
|
||||
|
||||
|
||||
1) Installing libfaketime on OS X
|
||||
---------------------------------
|
||||
1) Installing libfaketime on macOS
|
||||
----------------------------------
|
||||
|
||||
If you use MacPorts, libfaketime can be installed on the command line
|
||||
as follows:
|
||||
|
||||
sudo port install libfaketime
|
||||
|
||||
Otherwise, you have to compile and install libfaketime manually; this
|
||||
Or, if you use Fink, install using:
|
||||
|
||||
fink install libfaketime
|
||||
|
||||
Or, if you use Homebrew, install using:
|
||||
|
||||
brew install libfaketime
|
||||
|
||||
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.
|
||||
|
||||
Use the OSX-specific Makefile that is provided:
|
||||
You can compile libfaketime by running the command
|
||||
|
||||
make -f Makefile.OSX
|
||||
make
|
||||
|
||||
in libfaketime's top-level directory.
|
||||
|
||||
The resulting library will be named libfaketime.1.dylib ; to check
|
||||
whether it works properly, run the test suite and verify whether its
|
||||
@@ -41,8 +51,8 @@ output is correct:
|
||||
make -f Makefile.OSX
|
||||
|
||||
|
||||
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 iTerm2 session, the following commands can be used:
|
||||
@@ -55,7 +65,7 @@ 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 application 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. Run "faketime" without parameters
|
||||
@@ -113,13 +123,21 @@ 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 OS X.
|
||||
time-related system calls that need to be intercepted on macOS.
|
||||
|
||||
https://github.com/wolfcw/libfaketime/issues
|
||||
|
||||
Important: 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.
|
||||
|
||||
4) Notes for developers of OS X 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
|
||||
|
||||
@@ -16,7 +16,7 @@ completely done via Github:
|
||||
- The "master" branch is updated with tested code only; it is ensured that
|
||||
it compiles and works cleanly at least on current Linux and OS X systems.
|
||||
|
||||
Code contributions are highly welcome, preferrably via pull requests on Github.
|
||||
Code contributions are highly welcome, preferably via pull requests on Github.
|
||||
|
||||
|
||||
CODE STYLE
|
||||
|
||||
4
TODO
4
TODO
@@ -2,10 +2,8 @@ Open issues / next steps for libfaketime development
|
||||
|
||||
- add more functional tests that check more than the basic functionality
|
||||
- use the 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
|
||||
- fake timer_create and friends
|
||||
- handle CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE
|
||||
- work around thread local storage issue, e.g., by using pthreads
|
||||
- add autoconf/automake support to get rid of separate Makefile.OSX
|
||||
- improve pthread support
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ PREFIX ?= /usr/local
|
||||
all:
|
||||
|
||||
install:
|
||||
$(INSTALL) -dm0644 "${DESTDIR}${PREFIX}/share/man/man1"
|
||||
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/share/man/man1"
|
||||
$(INSTALL) -m0644 faketime.1 "${DESTDIR}${PREFIX}/share/man/man1/faketime.1"
|
||||
gzip -f "${DESTDIR}${PREFIX}/share/man/man1/faketime.1"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.TH FAKETIME "1" "October 2013" "faketime 0.9.5" wolfcw
|
||||
.TH FAKETIME "1" "November 2017" "faketime 0.9.7" 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, or have a look at http://github.com/wolfcw/libfaketime
|
||||
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
|
||||
@@ -33,7 +36,7 @@ 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 restaring it at the start of each process.
|
||||
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
|
||||
@@ -51,12 +54,14 @@ This is the most often used format and specifies the faked time relatively to th
|
||||
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.
|
||||
.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. 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
|
||||
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
|
||||
Please see the README and NEWS 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.
|
||||
While timestamps and time offsets will work for child processes, speeding the clock up or slowing it down might not
|
||||
|
||||
25
packaging/Linux/Arch/PKGBUILD-32bit.txt
Normal file
25
packaging/Linux/Arch/PKGBUILD-32bit.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
# Maintainer: Robert Orzanna <orschiro@gmail.com>
|
||||
|
||||
_pkgbasename=libfaketime
|
||||
pkgname=lib32-$_pkgbasename
|
||||
pkgver=0.9.5
|
||||
pkgrel=1
|
||||
pkgdesc='Report fake dates and times to programs without having to change the system-wide time.'
|
||||
arch=('x86_64')
|
||||
url='http://www.code-wizards.com/projects/libfaketime/'
|
||||
license=('GPL2')
|
||||
source=("http://www.code-wizards.com/projects/${_pkgbasename}/${_pkgbasename}-${pkgver}.tar.gz"
|
||||
'lib32.patch')
|
||||
md5sums=('89b5c71e6c6a93b1c6feba374ac37719'
|
||||
'0a01f842df4c8acbd2b081be046e8d67')
|
||||
|
||||
build() {
|
||||
cd "${_pkgbasename}-${pkgver}"
|
||||
patch -p1 -i ../lib32.patch
|
||||
make
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "${_pkgbasename}-${pkgver}"
|
||||
make PREFIX=/usr DESTDIR="${pkgdir}" install
|
||||
}
|
||||
30
packaging/Linux/Debian/avoid-spurious-lrt.patch
Normal file
30
packaging/Linux/Debian/avoid-spurious-lrt.patch
Normal file
@@ -0,0 +1,30 @@
|
||||
Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
|
||||
|
||||
On i386 systems, for some reason if i do not clean up this extra -lrt, i get the following error:
|
||||
|
||||
[...]
|
||||
make[1]: Entering directory `/home/dkg/src/faketime/faketime/src'
|
||||
cc -o libfaketime.o -c -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -std=gnu99 -Wall -Wextra -Werror -DFAKE_STAT -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'/usr/local'"' -DLIBDIRNAME='"'/lib/faketime'"' -DMULTI_ARCH libfaketime.c
|
||||
cc -o libfaketime.so.1 -Wl,-soname,libfaketime.so.1 -Wl,-z,relro -Wl,--version-script=libfaketime.map -lrt -shared libfaketime.o -ldl -lm -lpthread -lrt
|
||||
libfaketime.o: In function `ft_cleanup':
|
||||
/home/dkg/src/faketime/faketime/src/libfaketime.c:1277: multiple definition of `timer_gettime'
|
||||
/home/dkg/src/faketime/faketime/src/libfaketime.c:1277: multiple definition of `timer_settime'
|
||||
collect2: error: ld returned 1 exit status
|
||||
make[1]: *** [libfaketime.so.1] Error 1
|
||||
[...]
|
||||
|
||||
I confess i don't really understand why removing this would fix
|
||||
things, but i also don't see the need to have multiple attempts to
|
||||
link to librt.
|
||||
|
||||
--- a/src/Makefile
|
||||
+++ b/src/Makefile
|
||||
@@ -69,7 +69,7 @@
|
||||
|
||||
CFLAGS += -std=gnu99 -Wall -Wextra -Werror -DFAKE_STAT -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'$(PREFIX)'"' -DLIBDIRNAME='"'$(LIBDIRNAME)'"'
|
||||
LIB_LDFLAGS += -shared
|
||||
-LDFLAGS += -Wl,--version-script=libfaketime.map -lrt
|
||||
+LDFLAGS += -Wl,--version-script=libfaketime.map
|
||||
LDADD += -ldl -lm -lpthread -lrt
|
||||
|
||||
SRC = libfaketime.c
|
||||
40
packaging/Linux/Debian/control
Normal file
40
packaging/Linux/Debian/control
Normal file
@@ -0,0 +1,40 @@
|
||||
Source: faketime
|
||||
Section: utils
|
||||
Priority: extra
|
||||
Maintainer: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
|
||||
Build-Depends:
|
||||
debhelper (>= 9),
|
||||
dh-exec (>= 0.3)
|
||||
Standards-Version: 3.9.4
|
||||
Homepage: http://www.code-wizards.com/projects/libfaketime/
|
||||
Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/faketime.git
|
||||
Vcs-Git: git://anonscm.debian.org/collab-maint/faketime.git
|
||||
|
||||
Package: faketime
|
||||
Architecture: any
|
||||
Pre-Depends: multiarch-support
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}, libfaketime (= ${binary:Version})
|
||||
Multi-Arch: foreign
|
||||
Description: report faked system time to programs
|
||||
The Fake Time Preload Library (FTPL, a.k.a. libfaketime) 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. FTPL allows you to specify both absolute dates (e.g.,
|
||||
2004-01-01) and relative dates (e.g., 10 days ago).
|
||||
|
||||
Package: libfaketime
|
||||
Architecture: any
|
||||
Pre-Depends: multiarch-support
|
||||
Multi-Arch: same
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||
Description: report faked system time to programs
|
||||
The Fake Time Preload Library (FTPL, a.k.a. libfaketime) 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. FTPL allows you to specify both absolute dates (e.g.,
|
||||
2004-01-01) and relative dates (e.g., 10 days ago).
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
From: Gerardo Malazdrewicz <gerardo@malazdrewicz.com.ar>
|
||||
To: 699559@bugs.debian.org
|
||||
Subject: Avoiding loop (very dirty patch)
|
||||
Date: Tue, 26 Mar 2013 01:18:05 +0100
|
||||
|
||||
[Message part 1 (text/plain, inline)]
|
||||
|
||||
Attached patch works for me, but it is very very dirty.
|
||||
|
||||
Possibly side effects.
|
||||
|
||||
Alternative seems to be to protect the call to real_clock_gettime so it is
|
||||
executed just once (to validate the parameters). Subsequent calls are not
|
||||
needed (parameters have been validated).
|
||||
|
||||
Thanks,
|
||||
Gerardo
|
||||
|
||||
--- a/src/libfaketime.c
|
||||
+++ b/src/libfaketime.c
|
||||
@@ -1380,7 +1380,7 @@ void __attribute__ ((constructor)) ftpl_init(void)
|
||||
real_clock_get_time = dlsym(RTLD_NEXT, "clock_get_time");
|
||||
real_clock_gettime = apple_clock_gettime;
|
||||
#else
|
||||
- real_clock_gettime = dlsym(RTLD_NEXT, "clock_gettime");
|
||||
+ real_clock_gettime = dlsym(RTLD_NEXT, "__clock_gettime");
|
||||
#ifdef FAKE_TIMERS
|
||||
real_timer_settime_22 = dlvsym(RTLD_NEXT, "timer_settime","GLIBC_2.2");
|
||||
real_timer_settime_233 = dlvsym(RTLD_NEXT, "timer_settime","GLIBC_2.3.3");
|
||||
3
packaging/Linux/Debian/libfaketime.install
Executable file
3
packaging/Linux/Debian/libfaketime.install
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/dh-exec
|
||||
src/libfaketime.so.1 usr/lib/${DEB_HOST_MULTIARCH}/faketime/
|
||||
src/libfaketimeMT.so.1 usr/lib/${DEB_HOST_MULTIARCH}/faketime/
|
||||
17
packaging/Linux/Debian/rules
Executable file
17
packaging/Linux/Debian/rules
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
# Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
|
||||
# Date: Tue, 26 Aug 2008 14:24:50 -0400
|
||||
|
||||
export DEB_CFLAGS_MAINT_APPEND=-DMULTI_ARCH
|
||||
|
||||
# make sure dh_makeshlibs does not modify post{inst,rm} scripts:
|
||||
# (avoids lintian's postinst-has-useless-call-to-ldconfig)
|
||||
override_dh_makeshlibs:
|
||||
dh_makeshlibs --noscripts
|
||||
|
||||
override_dh_installchangelogs:
|
||||
dh_installchangelogs NEWS
|
||||
|
||||
%:
|
||||
PREFIX=/usr dh $@
|
||||
@@ -0,0 +1,13 @@
|
||||
diff --git a/src/libfaketime.c b/src/libfaketime.c
|
||||
index 3ec372b..f70283b 100644
|
||||
--- a/src/libfaketime.c
|
||||
+++ b/src/libfaketime.c
|
||||
@@ -1380,7 +1380,7 @@ void __attribute__ ((constructor)) ftpl_init(void)
|
||||
real_clock_get_time = dlsym(RTLD_NEXT, "clock_get_time");
|
||||
real_clock_gettime = apple_clock_gettime;
|
||||
#else
|
||||
- real_clock_gettime = dlsym(RTLD_NEXT, "clock_gettime");
|
||||
+ real_clock_gettime = dlsym(RTLD_NEXT, "__clock_gettime");
|
||||
#ifdef FAKE_TIMERS
|
||||
real_timer_settime_22 = dlvsym(RTLD_NEXT, "timer_settime","GLIBC_2.2");
|
||||
real_timer_settime_233 = dlvsym(RTLD_NEXT, "timer_settime","GLIBC_2.3.3");
|
||||
55
packaging/Linux/Redhat/libfaketime.spec.txt
Normal file
55
packaging/Linux/Redhat/libfaketime.spec.txt
Normal file
@@ -0,0 +1,55 @@
|
||||
Summary: Manipulate system time per process for testing purposes
|
||||
Name: libfaketime
|
||||
Version: 0.9.5
|
||||
Release: 4%{?dist}
|
||||
License: GPLv2+
|
||||
Url: http://www.code-wizards.com/projects/%{name}/
|
||||
Source: http://www.code-wizards.com/projects/%{name}/%{name}-%{version}.tar.gz
|
||||
Group: System Environment/Libraries
|
||||
Patch1: libfaketime-0.9.5-fix-infinite-recursion-on-real_clock_gettime.patch
|
||||
|
||||
%description
|
||||
libfaketime 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.
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
%patch1 -p1
|
||||
# work around from upstream for autodetecting glibc version bug on i686
|
||||
sed -i -e 's/__asm__(".symver timer_gettime_22/\/\/__asm__(".symver timer_gettime_22/' src/libfaketime.c
|
||||
sed -i -e 's/__asm__(".symver timer_settime_22/\/\/__asm__(".symver timer_settime_22/' src/libfaketime.c
|
||||
|
||||
|
||||
%build
|
||||
cd src ; CFLAGS="$RPM_OPT_FLAGS -Wno-strict-aliasing" make %{?_smp_mflags} \
|
||||
PREFIX="%{_prefix}" LIBDIRNAME="/%{_lib}/faketime" all
|
||||
|
||||
%check
|
||||
make %{?_smp_mflags} -C test all
|
||||
|
||||
%install
|
||||
make PREFIX="%{_prefix}" DESTDIR=%{buildroot} LIBDIRNAME="/%{_lib}/faketime" install
|
||||
rm -r %{buildroot}/%{_docdir}/faketime
|
||||
|
||||
%files
|
||||
%{_bindir}/faketime
|
||||
%{_libdir}/faketime/libfaketime*so.*
|
||||
%doc README COPYING NEWS README README.developers
|
||||
%{_mandir}/man1/*
|
||||
|
||||
%changelog
|
||||
* Tue Oct 15 2013 Paul Wouters <pwouters@redhat.com> - 0.9.5-4
|
||||
- Infinite recursion patch is still needed, make test causes
|
||||
segfaults otherwise.
|
||||
|
||||
* Mon Oct 14 2013 Paul Wouters <pwouters@redhat.com> - 0.9.5-3
|
||||
- Work around from upstream for autodetecting glibc version bug on i686
|
||||
|
||||
* Mon Oct 14 2013 Paul Wouters <pwouters@redhat.com> - 0.9.5-2
|
||||
- Remove use of ifarch for _lib macro for multilib
|
||||
|
||||
* Sun Oct 13 2013 Paul Wouters <pwouters@redhat.com> - 0.9.5-1
|
||||
- Initial package
|
||||
53
packaging/OSX/Fink/libfaketime.info
Normal file
53
packaging/OSX/Fink/libfaketime.info
Normal file
@@ -0,0 +1,53 @@
|
||||
Package: libfaketime
|
||||
Version: 0.9.7
|
||||
Revision: 1
|
||||
|
||||
Source: http://www.code-wizards.com/projects/%n/%n-%v.tar.gz
|
||||
Source-MD5: PLACEHOLDER
|
||||
|
||||
Maintainer: Wolfgang Hommel <wolf@fink.code-wizards.com>
|
||||
HomePage: https://github.com/wolfcw/libfaketime
|
||||
License: GPL
|
||||
|
||||
Description: Modify system time for single applications
|
||||
|
||||
DescDetail: <<
|
||||
libfaketime is a library that is dynamically linked to applications
|
||||
or system commands at run-time by using the DYLD_INSERT_LIBRARIES
|
||||
mechanism. It then intercepts various system calls, which programs
|
||||
use to retrieve the current date and time. libfaketime can then
|
||||
report faked dates and times to these programs. This means you can
|
||||
modify the system time a program uses without having to change the
|
||||
date and time system-wide.
|
||||
<<
|
||||
|
||||
DescUsage: <<
|
||||
libfaketime includes a simple wrapper called faketime. Run the
|
||||
command faketime without any parameters for usage information.
|
||||
For information on how to use libfaketime without the wrapper
|
||||
and access its full raw functionality, please see
|
||||
%p/share/doc/libfaketime/README*
|
||||
<<
|
||||
|
||||
BuildDepends: fink (>= 0.28)
|
||||
Distribution: 10.7, 10.8, 10.9, 10.10, 10.11, 10.12
|
||||
|
||||
CompileScript: <<
|
||||
#! /bin/sh -ev
|
||||
make -f Makefile.OSX -C src PREFIX=%{p}
|
||||
<<
|
||||
|
||||
InfoTest: <<
|
||||
TestScript: make -f Makefile.OSX test || exit 2
|
||||
<<
|
||||
|
||||
InstallScript: <<
|
||||
#! /bin/sh -ev
|
||||
make -f Makefile.OSX -C src install PREFIX=%{i}
|
||||
<<
|
||||
|
||||
DocFiles: COPYING README README.OSX
|
||||
|
||||
Shlibs: <<
|
||||
!%p/lib/faketime/%N.1.dylib
|
||||
<<
|
||||
21
packaging/OSX/Homebrew/libfaketime.rb
Normal file
21
packaging/OSX/Homebrew/libfaketime.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require 'formula'
|
||||
|
||||
class Libfaketime < Formula
|
||||
homepage 'https://github.com/wolfcw/libfaketime'
|
||||
url 'https://github.com/wolfcw/libfaketime/archive/v0.9.7.tar.gz'
|
||||
sha1 'PLACEHOLDER'
|
||||
|
||||
depends_on :macos => :sierra
|
||||
|
||||
fails_with :llvm do
|
||||
build 2336
|
||||
cause 'No thread local storage support'
|
||||
end
|
||||
|
||||
def install
|
||||
system "make", "-C", "src", "-f", "Makefile.OSX", "PREFIX=#{prefix}"
|
||||
bin.install 'src/faketime'
|
||||
(lib/'faketime').install 'src/libfaketime.1.dylib'
|
||||
man1.install 'man/faketime.1'
|
||||
end
|
||||
end
|
||||
45
packaging/OSX/MacPorts/Portfile
Normal file
45
packaging/OSX/MacPorts/Portfile
Normal file
@@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
|
||||
# $Id: Portfile 112093 2013-10-11 19:57:13Z ryandesign@macports.org $
|
||||
|
||||
PortSystem 1.0
|
||||
PortGroup github 1.0
|
||||
|
||||
github.setup wolfcw libfaketime 0.9.7 v
|
||||
|
||||
checksums rmd160 PLACEHOLDER \
|
||||
sha256 PLACEHOLDER
|
||||
|
||||
categories sysutils
|
||||
platforms darwin
|
||||
maintainers code-wizards.com:wolf openmaintainer
|
||||
license GPL-2
|
||||
|
||||
description libfaketime modifies the system time for a single application
|
||||
|
||||
long_description libfaketime intercepts various system calls that applications use to \
|
||||
retrieve the current date and time. It can then report user-specified \
|
||||
faked dates and times to these applications. This allows us to modify \
|
||||
the system time an application sees without having to change the time \
|
||||
system-wide. The faketime wrapper can be used from command line. \
|
||||
Check the documentation on how to integrate into installed applications.
|
||||
|
||||
patchfiles patch-test-Makefile.OSX.diff
|
||||
|
||||
use_configure no
|
||||
|
||||
variant universal {}
|
||||
|
||||
compiler.blacklist *cc* *dragonegg*
|
||||
|
||||
build.args -f Makefile.OSX
|
||||
build.env CC="${configure.cc}" \
|
||||
CFLAGS="[get_canonical_archflags cc]" \
|
||||
LDFLAGS="[get_canonical_archflags ld]" \
|
||||
PREFIX=${prefix}
|
||||
|
||||
test.run yes
|
||||
test.args ${build.args}
|
||||
eval test.env ${build.env}
|
||||
|
||||
destroot.args ${build.args}
|
||||
eval destroot.env ${build.env}
|
||||
12
packaging/OSX/MacPorts/patch-test-Makefile.OSX.diff
Normal file
12
packaging/OSX/MacPorts/patch-test-Makefile.OSX.diff
Normal file
@@ -0,0 +1,12 @@
|
||||
--- test/Makefile.OSX.orig 2013-10-11 09:42:38.000000000 -0500
|
||||
+++ test/Makefile.OSX 2013-10-11 14:46:11.000000000 -0500
|
||||
@@ -1,7 +1,6 @@
|
||||
-CC = gcc
|
||||
+CC ?= clang
|
||||
|
||||
-CFLAGS = -std=gnu99 -Wall -DFAKE_STAT
|
||||
-LDFLAGS =
|
||||
+CFLAGS += -std=gnu99 -Wall -DFAKE_STAT
|
||||
|
||||
SRC = timetest.c
|
||||
OBJ = ${SRC:.c=.o}
|
||||
65
packaging/OSX/README
Normal file
65
packaging/OSX/README
Normal file
@@ -0,0 +1,65 @@
|
||||
# Packaging for OS X
|
||||
|
||||
Several software tools assist with the installation of open source software
|
||||
on OS X. The authors of libfaketime maintain the libfaketime build spec files
|
||||
for MacPorts, Homebrew, and Fink.
|
||||
|
||||
|
||||
## MacPorts
|
||||
|
||||
Installing libfaketime via MacPorts is based on the provided Portfile, which
|
||||
has been included in the official MacPorts distribution since October, 2013.
|
||||
Users therefore can use "sudo port install libfaketime" as installation
|
||||
command.
|
||||
|
||||
Some libfaketime Portfile caveats:
|
||||
|
||||
- Github-based source file distribution
|
||||
- Non-clang-compilers need to be blacklisted
|
||||
- MacPorts folks have requested to avoid a platform-specific Makefile.OSX in
|
||||
the future
|
||||
|
||||
Portfile submission is documented in https://www.macports.org/guide/#project.contributing
|
||||
and handled via a ticketing system:
|
||||
|
||||
- https://trac.macports.org/ticket/40662
|
||||
- https://trac.macports.org/ticket/40748
|
||||
|
||||
|
||||
## Homebrew
|
||||
|
||||
The libfaketime 'formula' for Homebrew is available since November, 2013.
|
||||
Homebrew users can use 'brew install libfaketime' as installation command.
|
||||
|
||||
Some libfaketime formula caveats:
|
||||
|
||||
- "depends_on :macos => :lion" must be set for libfaketime >=0.9.5
|
||||
- :llvm builds <= 2336 must be blacklisted because libfaketime =0.9.5
|
||||
requires a compiler with thread local storage support.
|
||||
|
||||
Formula submission is handled via pull request on Github following the
|
||||
"one formula per commit, one commit per formula" rule, which necessitates
|
||||
squashing commits and forced pushes when applying fixes. Style issues
|
||||
complementary to the documentation have been discussed in
|
||||
|
||||
https://github.com/mxcl/homebrew/pull/23245
|
||||
|
||||
|
||||
## Fink
|
||||
|
||||
A libfaketime.info file is included in the Fink 10.7 tree since October,
|
||||
2013, and installed using
|
||||
|
||||
fink install libfaketime
|
||||
|
||||
Some libfaketime fink info file caveats:
|
||||
|
||||
- The dynamic library must be declared as private Shlib; this also necessitates
|
||||
BuildDepends: fink (>= 0.28)
|
||||
- "Distribution: 10.7, 10.8, 10.9" is required because libfaketime >=0.9.5 does
|
||||
not work on OS X 10.6 or before anymore.
|
||||
- When compiling, PREFIX=%{p} needs to be used because this path is hardcoded
|
||||
into the wrapper. However, "make install" needs to deploy into PREFIX=%{i} to
|
||||
make packaging work.
|
||||
|
||||
Submission is via https://sourceforge.net/p/fink/package-submissions/
|
||||
14
packaging/README
Normal file
14
packaging/README
Normal file
@@ -0,0 +1,14 @@
|
||||
# libfaketime packaging
|
||||
|
||||
Not everyone feels comfortable with installing tools and libraries manually
|
||||
by downloading and building them from source. Luckily enough, voluntary
|
||||
maintainers prepare new libfaketime releases for various platforms and make
|
||||
them available as binary packages or otherwise automatically installable
|
||||
software.
|
||||
|
||||
In this directory, we collect build specification files for the platforms
|
||||
that we are aware of being actively supported. They help us to analyze
|
||||
build issues, create awareness for platform-specific patches that had to
|
||||
be applied and might be merged with our code, and provide the contact
|
||||
information for future "early release warnings".
|
||||
|
||||
27
src/Makefile
27
src/Makefile
@@ -30,12 +30,6 @@
|
||||
# FAKE_TIMERS
|
||||
# - Also intercept timer_settime() and timer_gettime()
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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
|
||||
@@ -66,11 +60,22 @@ INSTALL ?= install
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
LIBDIRNAME ?= /lib/faketime
|
||||
PLATFORM ?=$(shell uname)
|
||||
|
||||
CFLAGS += -std=gnu99 -Wall -Wextra -Werror -Wno-nonnull-compare -DFAKE_STAT -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'$(PREFIX)'"' -DLIBDIRNAME='"'$(LIBDIRNAME)'"'
|
||||
ifeq ($(PLATFORM),SunOS)
|
||||
CFLAGS += -D__EXTENSIONS__ -D_XOPEN_SOURCE=600
|
||||
endif
|
||||
|
||||
CFLAGS += -std=gnu99 -Wall -Wextra -Werror -DFAKE_STAT -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'$(PREFIX)'"' -DLIBDIRNAME='"'$(LIBDIRNAME)'"'
|
||||
LIB_LDFLAGS += -shared
|
||||
LDFLAGS += -Wl,--version-script=libfaketime.map -lrt
|
||||
LDADD += -ldl -lm -lpthread -lrt
|
||||
|
||||
LDFLAGS += -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
|
||||
@@ -81,7 +86,7 @@ LIBS = libfaketime.so.${SONAME} libfaketimeMT.so.${SONAME}
|
||||
|
||||
all: ${LIBS} ${BINS}
|
||||
|
||||
faketimeMT.o: EXTRA_FLAGS := -DPTHREAD -DPTHREAD_SINGLETHREADED_TIME
|
||||
libfaketimeMT.o: EXTRA_FLAGS := -DPTHREAD -DPTHREAD_SINGLETHREADED_TIME
|
||||
|
||||
${LIBS_OBJ}: libfaketime.c
|
||||
${CC} -o $@ -c ${CFLAGS} ${EXTRA_FLAGS} $<
|
||||
@@ -90,7 +95,7 @@ ${LIBS_OBJ}: libfaketime.c
|
||||
${CC} -o $@ -Wl,-soname,$@ ${LDFLAGS} ${LIB_LDFLAGS} $< ${LDADD}
|
||||
|
||||
${BINS}: faketime.c
|
||||
${CC} -o $@ ${CFLAGS} ${EXTRA_FLAGS} $< ${LDFLAGS} ${LDADD}
|
||||
${CC} -o $@ ${CFLAGS} ${EXTRA_FLAGS} $< ${LDFLAGS} ${BIN_LDFLAGS}
|
||||
|
||||
clean:
|
||||
@rm -f ${LIBS_OBJ} ${LIBS} ${BINS}
|
||||
|
||||
@@ -21,12 +21,6 @@
|
||||
# FAKE_SLEEP
|
||||
# - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll()
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# * Compilation addition: second libMT target added for building the pthread-
|
||||
# enabled library as a separate library
|
||||
#
|
||||
@@ -44,8 +38,8 @@ INSTALL ?= install
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
|
||||
CFLAGS += -DFAKE_SLEEP -DPREFIX='"'${PREFIX}'"'
|
||||
LIB_LDFLAGS += -dynamiclib -current_version 0.9.5 -compatibility_version 0.7
|
||||
CFLAGS += -DFAKE_SLEEP -DFAKE_INTERNAL_CALLS -DPREFIX='"'${PREFIX}'"'
|
||||
LIB_LDFLAGS += -dynamiclib -current_version 0.9.7 -compatibility_version 0.7
|
||||
|
||||
SONAME = 1
|
||||
LIBS = libfaketime.${SONAME}.dylib
|
||||
|
||||
125
src/faketime.c
125
src/faketime.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* libfaketime wrapper command
|
||||
*
|
||||
* This file is part of libfaketime, version 0.9.5
|
||||
* This file is part of libfaketime, version 0.9.7
|
||||
*
|
||||
* 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
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
#include "faketime_common.h"
|
||||
|
||||
const char version[] = "0.9.5";
|
||||
const char version[] = "0.9.7";
|
||||
|
||||
#ifdef __APPLE__
|
||||
static const char *date_cmd = "gdate";
|
||||
@@ -61,31 +61,31 @@ static const char *date_cmd = "date";
|
||||
/* semaphore and shared memory names */
|
||||
char sem_name[PATH_BUFSIZE] = {0}, shm_name[PATH_BUFSIZE] = {0};
|
||||
|
||||
|
||||
void usage(const char *name)
|
||||
{
|
||||
printf("\n");
|
||||
printf("Usage: %s [switches] <timestamp> <program with arguments>\n", name);
|
||||
printf("\n");
|
||||
printf("This will run the specified 'program' with the given 'arguments'.\n");
|
||||
printf("The program will be tricked into seeing the given 'timestamp' as its starting date and time.\n");
|
||||
printf("The clock will continue to run from this timestamp. Please see the manpage (man faketime)\n");
|
||||
printf("for advanced options, such as stopping the wall clock and make it run faster or slower.\n");
|
||||
printf("\n");
|
||||
printf("The optional switches are:\n");
|
||||
printf(" -m : Use the multi-threaded version of libfaketime\n");
|
||||
printf(" -f : Use the advanced timestamp specification format (see manpage)\n");
|
||||
printf("\n");
|
||||
printf("Examples:\n");
|
||||
printf("%s 'last friday 5 pm' /bin/date\n", name);
|
||||
printf("%s '2008-12-24 08:15:42' /bin/date\n", name);
|
||||
printf("%s -f '+2,5y x10,0' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'\n", name);
|
||||
printf("%s -f '+2,5y x0,50' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'\n", name);
|
||||
printf("%s -f '+2,5y i2,0' /bin/bash -c 'date; while true; do date; sleep 1 ; done'\n", name);
|
||||
printf("In this single case all spawned processes will use the same global clock\n");
|
||||
printf("without restaring it at the start of each process.\n\n");
|
||||
printf("(Please note that it depends on your locale settings whether . or , has to be used for fractions)\n");
|
||||
printf("\n");
|
||||
printf("\n"
|
||||
"Usage: %s [switches] <timestamp> <program with arguments>\n"
|
||||
"\n"
|
||||
"This will run the specified 'program' with the given 'arguments'.\n"
|
||||
"The program will be tricked into seeing the given 'timestamp' as its starting date and time.\n"
|
||||
"The clock will continue to run from this timestamp. Please see the manpage (man faketime)\n"
|
||||
"for advanced options, such as stopping the wall clock and make it run faster or slower.\n"
|
||||
"\n"
|
||||
"The optional switches are:\n"
|
||||
" -m : Use the multi-threaded version of libfaketime\n"
|
||||
" -f : Use the advanced timestamp specification format (see manpage)\n"
|
||||
" --exclude-monotonic : Prevent monotonic clock from drifting (not the raw monotonic one)\n"
|
||||
"\n"
|
||||
"Examples:\n"
|
||||
"%s 'last friday 5 pm' /bin/date\n"
|
||||
"%s '2008-12-24 08:15:42' /bin/date\n"
|
||||
"%s -f '+2,5y x10,0' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'\n"
|
||||
"%s -f '+2,5y x0,50' /bin/bash -c 'date; while true; do echo $SECONDS ; sleep 1 ; done'\n"
|
||||
"%s -f '+2,5y i2,0' /bin/bash -c 'date; while true; do date; sleep 1 ; done'\n"
|
||||
"In this single case all spawned processes will use the same global clock\n"
|
||||
"without restarting it at the start of each process.\n\n"
|
||||
"(Please note that it depends on your locale settings whether . or , has to be used for fractions)\n"
|
||||
"\n", name, name, name, name, name, name);
|
||||
}
|
||||
|
||||
/** Clean up shared objects */
|
||||
@@ -106,10 +106,10 @@ int main (int argc, char **argv)
|
||||
pid_t child_pid;
|
||||
int curr_opt = 1;
|
||||
bool use_mt = false, use_direct = false;
|
||||
int pfds[2];
|
||||
long offset;
|
||||
|
||||
while(curr_opt < argc) {
|
||||
while(curr_opt < argc)
|
||||
{
|
||||
if (0 == strcmp(argv[curr_opt], "-m"))
|
||||
{
|
||||
use_mt = true;
|
||||
@@ -122,11 +122,17 @@ int main (int argc, char **argv)
|
||||
curr_opt++;
|
||||
continue;
|
||||
}
|
||||
else if (0 == strcmp(argv[curr_opt], "--exclude-monotonic"))
|
||||
{
|
||||
setenv("DONT_FAKE_MONOTONIC", "1", true);
|
||||
curr_opt++;
|
||||
continue;
|
||||
}
|
||||
else if ((0 == strcmp(argv[curr_opt], "-v")) ||
|
||||
(0 == strcmp(argv[curr_opt], "--version")))
|
||||
{
|
||||
printf("\n%s: Version %s\n"
|
||||
"For usage information please use '%s --help\n'.",
|
||||
"For usage information please use '%s --help'.\n",
|
||||
argv[0], version, argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -154,6 +160,7 @@ int main (int argc, char **argv)
|
||||
if (!use_direct)
|
||||
{
|
||||
// TODO get seconds
|
||||
int pfds[2];
|
||||
(void) (pipe(pfds) + 1);
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
@@ -164,7 +171,7 @@ int main (int argc, char **argv)
|
||||
close(pfds[0]); /* we don't need this */
|
||||
if (EXIT_SUCCESS != execlp(date_cmd, date_cmd, "-d", argv[curr_opt], "+%s",(char *) NULL))
|
||||
{
|
||||
perror("Running (g)date failed");
|
||||
perror("Running (g)date failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -176,13 +183,14 @@ int main (int argc, char **argv)
|
||||
waitpid(child_pid, &ret, 0);
|
||||
if (ret != EXIT_SUCCESS)
|
||||
{
|
||||
printf("Error: Timestamp to fake not recognized, please re-try with a "
|
||||
printf("Error: Timestamp to fake not recognized, please re-try with a "
|
||||
"different timestamp.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
offset = atol(buf) - time(NULL);
|
||||
ret = snprintf(buf, sizeof(buf), "%s%ld", (offset >= 0)?"+":"", offset);
|
||||
setenv("FAKETIME", buf, true);
|
||||
close(pfds[0]); /* finished reading */
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -190,6 +198,8 @@ int main (int argc, char **argv)
|
||||
/* simply pass format string along */
|
||||
setenv("FAKETIME", argv[curr_opt], true);
|
||||
}
|
||||
int keepalive_fds[2];
|
||||
(void) (pipe(keepalive_fds) + 1);
|
||||
|
||||
/* we just consumed the timestamp option */
|
||||
curr_opt++;
|
||||
@@ -201,8 +211,15 @@ int main (int argc, char **argv)
|
||||
struct ft_shared_s *ft_shared;
|
||||
char shared_objs[PATH_BUFSIZE];
|
||||
|
||||
snprintf(sem_name, PATH_BUFSIZE -1 ,"/faketime_sem_%d", getpid());
|
||||
snprintf(shm_name, PATH_BUFSIZE -1 ,"/faketime_shm_%d", getpid());
|
||||
/*
|
||||
* Casting of getpid() return value to long needed to make GCC on SmartOS
|
||||
* happy, since getpid's return value's type on SmartOS is long. Since
|
||||
* getpid's return value's type is int on most other systems, and that
|
||||
* sizeof(long) always >= sizeof(int), this works on all platforms without
|
||||
* the need for crazy #ifdefs.
|
||||
*/
|
||||
snprintf(sem_name, PATH_BUFSIZE -1 ,"/faketime_sem_%ld", (long)getpid());
|
||||
snprintf(shm_name, PATH_BUFSIZE -1 ,"/faketime_shm_%ld", (long)getpid());
|
||||
|
||||
if (SEM_FAILED == (sem = sem_open(sem_name, O_CREAT|O_EXCL, S_IWUSR|S_IRUSR, 1)))
|
||||
{
|
||||
@@ -216,7 +233,7 @@ int main (int argc, char **argv)
|
||||
perror("shm_open");
|
||||
if (-1 == sem_unlink(argv[2]))
|
||||
{
|
||||
perror("sem_unlink");
|
||||
perror("sem_unlink");
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -271,7 +288,7 @@ int main (int argc, char **argv)
|
||||
|
||||
snprintf(shared_objs, PATH_BUFSIZE, "%s %s", sem_name, shm_name);
|
||||
setenv("FAKETIME_SHARED", shared_objs, true);
|
||||
|
||||
sem_close(sem);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -280,10 +297,12 @@ int main (int argc, char **argv)
|
||||
ftpl_path = PREFIX "/libfaketime.1.dylib";
|
||||
FILE *check;
|
||||
check = fopen(ftpl_path, "ro");
|
||||
if (check == NULL) {
|
||||
if (check == NULL)
|
||||
{
|
||||
ftpl_path = PREFIX "/lib/faketime/libfaketime.1.dylib";
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
fclose(check);
|
||||
}
|
||||
setenv("DYLD_INSERT_LIBRARIES", ftpl_path, true);
|
||||
@@ -298,7 +317,7 @@ int main (int argc, char **argv)
|
||||
* on MultiArch platforms, such as Debian, we put a literal $LIB into LD_PRELOAD.
|
||||
*/
|
||||
#ifndef MULTI_ARCH
|
||||
ftpl_path = PREFIX LIBDIRNAME "/libfaketimeMT.so.1";
|
||||
ftpl_path = PREFIX LIBDIRNAME "/libfaketimeMT.so.1";
|
||||
#else
|
||||
ftpl_path = PREFIX "/$LIB/faketime/libfaketimeMT.so.1";
|
||||
#endif
|
||||
@@ -306,12 +325,12 @@ int main (int argc, char **argv)
|
||||
else
|
||||
{
|
||||
#ifndef MULTI_ARCH
|
||||
ftpl_path = PREFIX LIBDIRNAME "/libfaketime.so.1";
|
||||
ftpl_path = PREFIX LIBDIRNAME "/libfaketime.so.1";
|
||||
#else
|
||||
ftpl_path = PREFIX "/$LIB/faketime/libfaketime.so.1";
|
||||
#endif
|
||||
}
|
||||
len = (ld_preload)?strlen(ld_preload):0 + 2 + strlen(ftpl_path);
|
||||
len = ((ld_preload)?strlen(ld_preload) + 1: 0) + 1 + strlen(ftpl_path);
|
||||
ld_preload_new = malloc(len);
|
||||
snprintf(ld_preload_new, len ,"%s%s%s", (ld_preload)?ld_preload:"",
|
||||
(ld_preload)?":":"", ftpl_path);
|
||||
@@ -324,6 +343,7 @@ int main (int argc, char **argv)
|
||||
/* run command and clean up shared objects */
|
||||
if (0 == (child_pid = fork()))
|
||||
{
|
||||
close(keepalive_fds[0]); /* only parent needs to read this */
|
||||
if (EXIT_SUCCESS != execvp(argv[curr_opt], &argv[curr_opt]))
|
||||
{
|
||||
perror("Running specified command failed");
|
||||
@@ -333,8 +353,33 @@ int main (int argc, char **argv)
|
||||
else
|
||||
{
|
||||
int ret;
|
||||
char buf;
|
||||
close(keepalive_fds[1]); /* only children need keep this open */
|
||||
waitpid(child_pid, &ret, 0);
|
||||
(void) (read(keepalive_fds[0], &buf, 1) + 1); /* reads 0B when all children exit */
|
||||
cleanup_shobjs();
|
||||
exit(ret);
|
||||
if (WIFSIGNALED(ret))
|
||||
{
|
||||
fprintf(stderr, "Caught %s\n", strsignal(WTERMSIG(ret)));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
exit(WEXITSTATUS(ret));
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 */
|
||||
|
||||
@@ -32,6 +32,10 @@ struct system_time_s
|
||||
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 */
|
||||
@@ -47,4 +51,11 @@ struct ft_shared_s
|
||||
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
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
12
src/sunos_endian.h
Normal file
12
src/sunos_endian.h
Normal 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 */
|
||||
@@ -29,43 +29,48 @@
|
||||
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) : \
|
||||
#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; \
|
||||
} \
|
||||
#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; \
|
||||
} \
|
||||
#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 { \
|
||||
long long tmp_time; \
|
||||
tmp_time = (c) * ((tvp)->tv_sec * SEC_TO_##prefix##SEC + \
|
||||
(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; \
|
||||
} \
|
||||
#define timermul2(tvp, c, result, prefix) \
|
||||
do \
|
||||
{ \
|
||||
long long tmp_time; \
|
||||
tmp_time = (c) * ((tvp)->tv_sec * SEC_TO_##prefix##SEC + \
|
||||
(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 */
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
CC = gcc
|
||||
CC ?= clang
|
||||
|
||||
CFLAGS = -std=gnu99 -Wall -DFAKE_STAT
|
||||
LDFLAGS =
|
||||
CFLAGS += -std=gnu99 -Wall -DFAKE_STAT
|
||||
|
||||
SRC = timetest.c
|
||||
OBJ = ${SRC:.c=.o}
|
||||
|
||||
@@ -9,6 +9,7 @@ platform()
|
||||
*Darwin*) echo "mac" ;;
|
||||
*Linux*) echo "linuxlike" ;;
|
||||
GNU|GNU/kFreeBSD) echo "linuxlike" ;;
|
||||
*SunOS*) echo "sunos" ;;
|
||||
*) echo 1>&2 unsupported platform, uname=\"$out\" ;;
|
||||
esac
|
||||
}
|
||||
@@ -25,6 +26,15 @@ mac_fakecmd()
|
||||
"$@"
|
||||
}
|
||||
|
||||
sunos_fakecmd()
|
||||
{
|
||||
typeset timestring="$1"; shift
|
||||
typeset fakelib=../src/libfaketime.so.1
|
||||
export LD_PRELOAD=$fakelib
|
||||
FAKETIME="$timestring" \
|
||||
"$@"
|
||||
}
|
||||
|
||||
# run faked command on linuxlike OS
|
||||
linuxlike_fakecmd()
|
||||
{
|
||||
|
||||
87
test/functests/test_exclude_mono.sh
Normal file
87
test/functests/test_exclude_mono.sh
Normal file
@@ -0,0 +1,87 @@
|
||||
# Checks that setting 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 DONT_FAKE_MONOTONIC to 1, calling
|
||||
# clock_gettime(CLOCK_MONOTONIC) returns two different values.
|
||||
#
|
||||
# We also make sure that if we don't set 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;
|
||||
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}"
|
||||
}
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
#define VERBOSE 0
|
||||
|
||||
#define SIG SIGUSR1
|
||||
|
||||
static void
|
||||
handler(int sig, siginfo_t *si, void *uc)
|
||||
{
|
||||
@@ -46,12 +48,11 @@ handler(int sig, siginfo_t *si, void *uc)
|
||||
{
|
||||
printf("Caught signal %d\n", sig);
|
||||
}
|
||||
signal(sig, SIG_IGN);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
time_t now;
|
||||
struct timeb tb;
|
||||
struct timeval tv;
|
||||
@@ -71,25 +72,28 @@ int main (int argc, char **argv) {
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sa.sa_sigaction = handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
if (sigaction(SIGRTMIN, &sa, NULL) == -1) {
|
||||
if (sigaction(SIGUSR1, &sa, NULL) == -1)
|
||||
{
|
||||
perror("sigaction");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* Block timer signal temporarily */
|
||||
|
||||
printf("Blocking signal %d\n", SIGRTMIN);
|
||||
/* Block timer signal temporarily */
|
||||
printf("Blocking signal %d\n", SIGUSR1);
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGRTMIN);
|
||||
if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) {
|
||||
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 = SIGRTMIN;
|
||||
sev.sigev_signo = SIGUSR1;
|
||||
sev.sigev_value.sival_ptr = &timerid1;
|
||||
if (timer_create(CLOCK_REALTIME, &sev, &timerid1) == -1) {
|
||||
if (timer_create(CLOCK_REALTIME, &sev, &timerid1) == -1)
|
||||
{
|
||||
perror("timer_create");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -103,13 +107,15 @@ int main (int argc, char **argv) {
|
||||
its.it_interval.tv_sec = 0;
|
||||
its.it_interval.tv_nsec = 300000000;
|
||||
|
||||
if (timer_settime(timerid1, 0, &its, NULL) == -1) {
|
||||
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) {
|
||||
if (timer_create(CLOCK_REALTIME, &sev, &timerid2) == -1)
|
||||
{
|
||||
perror("timer_create");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -123,7 +129,8 @@ int main (int argc, char **argv) {
|
||||
its.it_interval.tv_sec = 0;
|
||||
its.it_interval.tv_nsec = 0;
|
||||
|
||||
if (timer_settime(timerid2, TIMER_ABSTIME, &its, NULL) == -1) {
|
||||
if (timer_settime(timerid2, TIMER_ABSTIME, &its, NULL) == -1)
|
||||
{
|
||||
perror("timer_settime");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -148,7 +155,8 @@ int main (int argc, char **argv) {
|
||||
printf("gettimeofday() : Current date and time: %s", ctime(&tv.tv_sec));
|
||||
|
||||
#ifndef __APPLE__
|
||||
if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1) {
|
||||
if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1)
|
||||
{
|
||||
perror("sigprocmask");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -157,27 +165,31 @@ int main (int argc, char **argv) {
|
||||
printf("clock_gettime(): Current date and time: %s", ctime(&ts.tv_sec));
|
||||
|
||||
int timer_getoverrun_timerid1 = timer_getoverrun(timerid1);
|
||||
if (timer_getoverrun_timerid1 != 3) {
|
||||
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) {
|
||||
if (VERBOSE == 1)
|
||||
{
|
||||
printf("timer_gettime(timerid1, &its); its = {{%ld, %ld}, {%ld, %ld}}}\n",
|
||||
its.it_interval.tv_sec, its.it_interval.tv_nsec,
|
||||
its.it_value.tv_sec, its.it_value.tv_nsec);
|
||||
(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) {
|
||||
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) {
|
||||
if (VERBOSE == 1)
|
||||
{
|
||||
printf("timer_gettime(timerid2, &its); its = {{%ld, %ld}, {%ld, %ld}}}\n",
|
||||
its.it_interval.tv_sec, its.it_interval.tv_nsec,
|
||||
its.it_value.tv_sec, its.it_value.tv_nsec);
|
||||
(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
|
||||
|
||||
@@ -188,3 +200,18 @@ int main (int argc, char **argv) {
|
||||
|
||||
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 */
|
||||
|
||||
Reference in New Issue
Block a user