pax_global_header00006660000000000000000000000064142104641430014511gustar00rootroot0000000000000052 comment=d475b925943ad404c6c728ac868dc73949e7281c libfaketime-0.9.10/000077500000000000000000000000001421046414300140545ustar00rootroot00000000000000libfaketime-0.9.10/.github/000077500000000000000000000000001421046414300154145ustar00rootroot00000000000000libfaketime-0.9.10/.github/workflows/000077500000000000000000000000001421046414300174515ustar00rootroot00000000000000libfaketime-0.9.10/.github/workflows/make-test.yml000066400000000000000000000006171421046414300220720ustar00rootroot00000000000000name: 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: FAKETIME_COMPILE_CFLAGS="-DFORCE_MONOTONIC_FIX" make - name: make test run: make test libfaketime-0.9.10/.gitignore000066400000000000000000000003501421046414300160420ustar00rootroot00000000000000*.o *.so.1 timetest test/getrandom_test test/lib*.so test/use_lib_* test/run_* test/repeat_random test/getentropy_test test/syscall_test test/variadic_promotion src/libfaketime.dylib.1 src/libfaketime.1.dylib src/core src/faketime libfaketime-0.9.10/.travis.yml000066400000000000000000000006621421046414300161710ustar00rootroot00000000000000language: c matrix: include: - os: linux arch: amd64 compiler: gcc - os: linux arch: ppc64le compiler: gcc - os: osx osx_image: xcode11 script: - cd ${TRAVIS_BUILD_DIR} - if [ "$TRAVIS_ARCH" = ppc64le ]; then FAKETIME_COMPILE_CFLAGS="-DFORCE_MONOTONIC_FIX -DFORCE_PTHREAD_NONVER" make; else FAKETIME_COMPILE_CFLAGS="-DFORCE_MONOTONIC_FIX" make; fi - make test libfaketime-0.9.10/COPYING000066400000000000000000000432541421046414300151170ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 of the License, 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. libfaketime-0.9.10/Makefile000066400000000000000000000017561421046414300155250ustar00rootroot00000000000000INSTALL ?= install UNAME=$(shell uname) SELECTOR:=$(shell if test "${UNAME}" = "Darwin" ; then echo "-f Makefile.OSX" ; fi) PREFIX ?= /usr/local all: $(MAKE) $(SELECTOR) -C src all test: $(MAKE) $(SELECTOR) -C src all $(MAKE) $(SELECTOR) -C test all 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) $(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) $(SELECTOR) -C src clean $(MAKE) $(SELECTOR) -C test clean distclean: $(MAKE) $(SELECTOR) -C src distclean $(MAKE) $(SELECTOR) -C test distclean .PHONY: all test install uninstall clean distclean libfaketime-0.9.10/NEWS000066400000000000000000000233321421046414300145560ustar00rootroot00000000000000Since 0.9.9: - improved macOS Monterey support through dyld interposing - changed interception hooks for stat() and similar functions, refactored to use a common handler (@sirainen) - added support for timespec_get, timerfd_{get,set} (@sliquister) - generic syscall() interception for selected syscalls (@dkg) - improved testing system (@dkg) Since 0.9.8: - When compiled with the CFLAG FAKE_RANDOM set, libfaketime will intercept calls to getrandom() and return pseudorandom numbers for determinism. The mechanism needs to be activated by setting the environment variable FAKERANDOM_SEED to a 64-bit seed value, e.g., "0x12345678DEADBEEF". Please note that this completely breaks the security of random numbers for cryptographic purposes and should only be used for deterministic tests. Never use this in production! - When the environment variable FAKETIME_TIMESTAMP_FILE is set, points to a writeable (creatable) custom config file and the environment variable FAKETIME_UPDATE_TIMESTAMP_FILE is "1", then the file also is updated on each call. By this, a common "virtual time" can be shared by several processes, where each can adjust the time for all. - Additional link-time LDFLAGS can be passed via the environment variable FAKETIME_LINK_FLAGS when running 'make'. - 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 returned timestamps and when it shall stop doing so. For example, 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. - 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. Since 0.8.1: - Added a MacOS port. 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! Since 0.8: - Changed directory layout and Makefile structure. Thanks to Lukas Fleischer! Since 0.7: - Added support for fstatat() and fstatat64() which were introduced in Linux kernel 2.6.16 and used in recent coreutils. Thanks to Daniel Kahn Gillmor for the report! This can be disabled by passing -DNO_ATFILE in the Makefile. - Added a simple wrapper shell script and a man page for it. Makes it easier to run commands under faked system times. It assumes that the libraries will be copied to /usr/lib/faketime during installation, please adjust this path if necessary. The "install" target in the Makefile has been adapted accordingly. - Added support for fractional time offsets, such as FAKETIME="+1,5h". Please note that either , or . has to be used as a delimiter depending on your locale. Thanks to Karl Chen! - Added support for speeding the clock up or slowing it down. For example, FAKETIME="+5d x2,0" will set the faked time 5 days into the future and make the clock run twice as fast for the specified program. Slowing it down can be done e.g. by using FAKETIME="+0 x0,5". Again, the delimiter to use for the fraction depends on your locale. Thanks to Karl Chen! Since 0.6: Main version 0.7 contributions by David North, TDI: - Added ability to 'start clock at' a specific time. - Added pthread synchronization support - Added a 2 second delay to timetest.c so one can observe if the clock is relative or absolute - Added test.sh example of 'start clock at' - Added ability to disable the FAKE_STAT functionality at library-start in the case that the library was compiled -DFAKE_STAT, and added another test case for demonstrating this - Repaired a bug w.r.t. strptime/mktime wherein 'isdst' was uninitialized which led to pseudorandom +/- 1 hour results being returned in 'start at' or absolute time modes Other enhancements: - Fixed missing interceptions to libc-internal functions and added notes about a workaround for running Java programs with faked times in the future (they worked properly, but often locked up at exiting). Thanks to Jamie Cameron of Google for in-depth analysis and prototype solution! Since 0.5: - Performance enhancements by means of caching the data read e.g. from $HOME/.faketimerc for 10 seconds. - Several file timestamp related system calls such as fstat() will be intercepted now. See the README file on how to turn this off if you do not need it. Thanks to Philipp Hachtmann! - A system-wide /etc/faketimerc file will now be used if no FAKETIME environment variable has been set and no $HOME/.faketimerc is present. Thanks to David Burley, Jacob Moorman, and Wayne Davison of SourceForge, Inc.! - Added trivial Makefile targets clean/distclean/install - Changed Makefile target test to run new test.sh script - Added new test cases to timetest.c Since 0.4: - Allow "y" for years of offset specification. Thanks to Bas ten Berge! Since 0.3: - Support for FAKETIME_FMT environment variable. Thanks to Moreno Baricevic! Since 0.2: - Intercept clock_gettime(). Thanks to Andreas Thienemann! Since 0.1: - Fixed segfault when calling time(NULL). Thanks to Andres Ojamaa! - Added additional sanity checks. libfaketime-0.9.10/README000066400000000000000000001020751421046414300147410ustar00rootroot00000000000000libfaketime, version 0.9.10 (March 2022) ======================================== Content of this file: --------------------- 1. Introduction 2. Compatibility issues 3. Installation 4. Usage a) Basics b) Using absolute dates c) Using 'start at' dates d) Using offsets for relative dates e) Advanced features and caveats f) Faking the date and time system-wide g) Using the "faketime" wrapper script 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 l) Replacing random numbers with deterministic number sequences 5. License 6. Contact 1. Introduction --------------- 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 - deterministic build processes - debugging time-related issues, such as expired SSL certificates - 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 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 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. - 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. 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. If FORCE_MONOTONIC_FIX was not set as a compile-time flag, you can also set an environment variable FAKETIME_FORCE_MONOTONIC_FIX=1 if you want to enable the fix at run-time, or to 0 if you explicitly want to disable it. The fix is automatically enabled if libfaketime was compiled on a system with glibc as the underlying libc implementation, and a glibc version is detected at run-time that is assumed to need this workaround. Please use Github issues at https://github.com/wolfcw/libfaketime/issues to report any observed hangs during CLOCK_MONOTONIC tests and report your CPU architecture, libc implementation (e.g., glibc 2.30) and any other details that might help (e.g., Linux distribution, use within, e.g., Docker containers etc.). Please try to avoid compiling with FORCE_MONOTONIC_FIX on platforms that do not need it. While it won't make a difference in most cases, depending on the specific FAKETIME settings in use, it would cause certain intercepted functions such as pthread_cond_timedwait() return with a time-out too early or too late, which could break some applications. Try compiling without FORCE_MONOTONIC_FIX first and check whether the tests appear to hang. If they do, you can either set the FAKETIME_FORCE_MONOTONIC_FIX environment variable to 1, or re-compile with FORCE_MONOTONIC_FIX set. 3. Installation --------------- 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 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 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.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). macOS users should read README.OSX for additional details. 4. Usage -------- 4a) Usage basics ---------------- 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 2016 user@host> LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="-15d" date 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 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 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 multiple ways to specify the faked time: a) By setting the environment variable FAKETIME. 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. e) By using FAKETIME_UPDATE_TIMESTAMP_FILE and date -s "