diff options
-rw-r--r-- | README.OSX | 98 | ||||
-rwxr-xr-x | src/faketime | 20 | ||||
-rw-r--r-- | src/faketime.c | 33 |
3 files changed, 136 insertions, 15 deletions
diff --git a/README.OSX b/README.OSX new file mode 100644 index 0000000..b2bb0e6 --- /dev/null +++ b/README.OSX @@ -0,0 +1,98 @@ +README file for libfaketime on Mac OS X +======================================= + +Support for Mac OS X is still preliminary. Development and tests are +done under 10.7 Lion only currently. + +Compiling and using libfaketime on OS X is slightly different than +on Linux. Please make sure to read the README file for general +setup and usage, and refer to this file only about OS X specifics. + + +1) Compiling libfaketime on OS X +-------------------------------- + +Use the OSX-specific Makefiles that are provided, e.g.: + +cd src/ +make -f Makefile.MacOS + +The resulting library will be named libfaketime.dylib.1 + + +2) Using libfaketime from the command line on OS X +-------------------------------------------------- + +You will need to set three environment variables. In a Terminal.app +or iTerm session, the following commands can be used: + +export DYLD_FORCE_FLAT_NAMESPACE=1 +export DYLD_INSERT_LIBRARIES=/path/to/libfaketime.dylib.1 +export FAKETIME="your favorite faketime-spec here" + +Please refer to the general README file concerning the format +of the FAKETIME environment variable value and other environment +variables that are related to it. + +The "faketime" wrapper shell script has been adapted to OS X; +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. + + +3) Integrating libfaketime with applications +-------------------------------------------- + +Given the limited number of system calls libfaketime intercepts, +it does not work too well with GUI applications on OS X. Crashes +after a random time are common issues, some applications will +not or at least not always see the faked time, and so on. + +A safe way to try out whether a specific application works fine +with libfaketime is to start it from the command line. Perform +the steps outlined above and run the application by issuing the +following command: + +/Applications/ApplicationName.app/Contents/MacOS/ApplicationName + +(Make sure to replace "ApplicationName" twice in that command with +the name of your actual application.) + +If it works fine, you can configure the application to permanently +run with libfaketime by editing its Info.plist file. Add the +LSEnvironment key unless it is already there and add a dictionary +with the three keys like this: + + <key>LSEnvironment</key> + <dict> + <key>DYLD_FORCE_FLAT_NAMESPACE</key> + <string>1</string> + <key>DYLD_INSERT_LIBRARIES</key> + <string>/path/to/libfaketime.dylib.1</string> + <key>FAKETIME</key> + <string>value of FAKETIME here</string> + </dict> + +(If the application is installed in /Applications instead of in +$HOME/Applications, you eventually will need root privileges. If +the application's Info.plist is not in XML, but in binary format, +use appropriate editing or conversion tools.) + +Afterwards, you will probably need to run + +/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/ApplicationName.app + +to make sure the change to Info.plist does not go unnoticed. + +Please note that modifications to Info.plist will be lost when the +application is updated, so this process needs to be repeated after +such updates. + + +4) Notes for developers of OS X applications +-------------------------------------------- + +The environment variable FAKETIME can be changed at application run-time +and always takes precedence over other user-controlled settings. It can +be re-set to 0 (zero) to work around potential incompatibilities. + diff --git a/src/faketime b/src/faketime index 7cc4334..8faf0fb 100755 --- a/src/faketime +++ b/src/faketime @@ -12,11 +12,16 @@ # Acknowledgment: Parts of the functionality of this wrapper have been # inspired by Matthias Urlichs' datefudge 1.14. -# Configuration: Path where the libfaketime libraries can be found. +# Configuration: Path where the libfaketime libraries can be found on Linux/UNIX. FTPL_PATH=/usr/lib/faketime +# For Mac OS X users: Full path and name to libfaketime.dylib.1 +MAC_FTPL_PATH=./libfaketime.dylib.1 + offset="$1" +DATE_CMD=date + USEMT=0 USEDIRECT=0 @@ -60,8 +65,15 @@ fi shift -# Setting LD_PRELOAD ... +# Check whether we are on Mac OS X (Darwin) +UNAME=$(uname) +if [ "$UNAME" = "Darwin" ] ; then + export DYLD_FORCE_FLAT_NAMESPACE=1 + export DYLD_INSERT_LIBRARIES=$MAC_FTPL_PATH + DATE_CMD=gdate +fi +# Setting LD_PRELOAD ... if [ "$USEMT" -eq 0 ] ; then export LD_PRELOAD="${LD_PRELOAD}${LD_PRELOAD:+:}$FTPL_PATH/libfaketime.so.1" fi @@ -74,13 +86,13 @@ fi # Setting FAKETIME ... if [ "$USEDIRECT" -eq 0 ] ; then - seconds=$(date -d "$offset" '+%s') + seconds=$($DATE_CMD -d "$offset" '+%s') if [ $? -ne 0 ] ; then echo "Error: Timestamp to fake not recognized, please re-try with a different timestamp." exit 1 fi - offset=$(expr $seconds - $(date '+%s')) + offset=$(expr $seconds - $($DATE_CMD '+%s')) if [ $? -ne 0 ] ; then echo "Error: Cannot calculate the faketime offset in seconds, please re-try with a different timestamp." exit 1 diff --git a/src/faketime.c b/src/faketime.c index 618896e..3b6e69a 100644 --- a/src/faketime.c +++ b/src/faketime.c @@ -1,6 +1,4 @@ /* - * Copyright (C) 2003,2004,2005,2006,2007,2008 Wolfgang Hommel - * * This file is part of the FakeTime Preload Library, version 0.8. * * The FakeTime Preload Library is free software; you can redistribute it @@ -630,9 +628,12 @@ time_t fake_time(time_t *time_tptr) { static time_t last_data_fetch = 0; /* not fetched previously at first call */ static int cache_expired = 1; /* considered expired at first call */ static int cache_duration = 10; /* cache fake time input for 10 seconds */ -#ifdef __APPLE__ - static int malloc_arena = 0; -#endif +/* + * This no longer appears to be necessary in Mac OS X 10.7 Lion + */ +//#ifdef __APPLE__ +// static int malloc_arena = 0; +//#endif #ifdef PTHREAD_SINGLETHREADED_TIME static pthread_mutex_t time_mutex=PTHREAD_MUTEX_INITIALIZER; @@ -702,12 +703,15 @@ static pthread_mutex_t time_mutex=PTHREAD_MUTEX_INITIALIZER; } /* cache had expired */ -#ifdef __APPLE__ - SINGLE_IF(malloc_arena==0) - malloc_arena = 1; - return *time_tptr; - END_SINGLE_IF -#endif +/* + * This no longer appears to be necessary in Mac OS X 10.7 Lion + */ +//#ifdef __APPLE__ +// SINGLE_IF(malloc_arena==0) +// malloc_arena = 1; +// return *time_tptr; +// END_SINGLE_IF +//#endif /* check whether the user gave us an absolute time to fake */ switch (user_faked_time[0]) { @@ -807,6 +811,10 @@ int fake_clock_gettime(clockid_t clk_id, struct timespec *tp) { } #endif +/* + * This causes serious issues in Mac OS X 10.7 Lion and is disabled there + */ +#ifndef __APPLE__ /* Added in v0.7 as suggested by Jamie Cameron, Google */ #ifdef FAKE_INTERNAL_CALLS int __gettimeofday(struct timeval *tv, void *tz) { @@ -827,4 +835,7 @@ time_t __time(time_t *time_tptr) { return time(time_tptr); } #endif +#endif + +/* eof */ |