wolfcw / libfaketime

libfaketime modifies the system time for a single application
https://github.com/wolfcw/libfaketime
GNU General Public License v2.0
2.64k stars 321 forks source link

Problems on macOS #413

Closed winfreddy88 closed 1 year ago

winfreddy88 commented 1 year ago

I hit some porblems on macOS.

The first time I ran make in the test directory, all was ok, but strangely on subsequent runs I am getting this:

winfreddy88@Winstons-MacBook-Pro:~/git/libfaketime/test master $ make
./testframe.sh functests
# Begin Test Suites in functests

# Begin functests/test_exclude_mono.sh
# PLATFORM=mac
out=81405.46471 When not faking monotonic time, timestamps should be different ref=81406.508149 - ok
# functests/test_exclude_mono.sh summary: 1 succeeded, 0 failed
# End functests/test_exclude_mono.sh - OK

# Begin functests/test_null.sh
out=0 () ref=1668170648 - ok
# functests/test_null.sh summary: 1 succeeded, 0 failed
# End functests/test_null.sh - OK

# Begin functests/test_true.sh
# functests/test_true.sh summary: 1 succeeded, 0 failed
# End functests/test_true.sh - OK

# Begin functests/test_walkone.sh
# PLATFORM=mac
out=1 (skipping test, install gdate) - ok
out=2 (skipping test, install gdate) - ok
out=4 (skipping test, install gdate) - ok
out=8 (skipping test, install gdate) - ok
out=16 (skipping test, install gdate) - ok
out=32 (skipping test, install gdate) - ok
out=64 (skipping test, install gdate) - ok
out=128 (skipping test, install gdate) - ok
out=256 (skipping test, install gdate) - ok
out=512 (skipping test, install gdate) - ok
out=1024 (skipping test, install gdate) - ok
out=2048 (skipping test, install gdate) - ok
out=4096 (skipping test, install gdate) - ok
out=8192 (skipping test, install gdate) - ok
out=16384 (skipping test, install gdate) - ok
out=32768 (skipping test, install gdate) - ok
out=65536 (skipping test, install gdate) - ok
out=131072 (skipping test, install gdate) - ok
out=262144 (skipping test, install gdate) - ok
out=524288 (skipping test, install gdate) - ok
out=1048576 (skipping test, install gdate) - ok
out=2097152 (skipping test, install gdate) - ok
out=4194304 (skipping test, install gdate) - ok
out=8388608 (skipping test, install gdate) - ok
out=16777216 (skipping test, install gdate) - ok
out=33554432 (skipping test, install gdate) - ok
out=67108864 (skipping test, install gdate) - ok
out=134217728 (skipping test, install gdate) - ok
out=268435456 (skipping test, install gdate) - ok
out=536870912 (skipping test, install gdate) - ok
out=1073741824 (skipping test, install gdate) - ok
# functests/test_walkone.sh summary: 31 succeeded, 0 failed
# End functests/test_walkone.sh - OK

# Test Suites summary: 4 succeeded, 0 failed
# End Test Suites - OK
gcc -shared -o libmallocintercept.so -fpic -std=gnu99 -Wall -DFAKE_STAT -Werror -Wextra  libmallocintercept.c
libmallocintercept.c:77:12: error: variable 'ptr2' set but not used [-Werror,-Wunused-but-set-variable]
  long int ptr2 = (long int) ptr; ptr2 -= (long int) ptr;
           ^
1 error generated.
make: *** [libmallocintercept.so] Error 1

Other than that, I'm not able to get it running: UPDATE: it seems that it doesn't work with /bin/date, but it does work with other tools, such as git, gpg, etc. So maybe /bin/date on macOS has some protections built in.

winfreddy88@Winstons-MacBook-Pro:~/git/libfaketime/test master $ FAKETIME='2018-12-24 08:15:42' DYLD_INSERT_LIBRARIES=/Users/winfreddy88/git/libfaketime/src/libfaketime.1.dylib DYLD_FORCE_FLAT_NAMESPACE=1 date
Fri Nov 11 13:44:24 CET 2022
winfreddy88@Winstons-MacBook-Pro:~/git/libfaketime/test master $ 

The file /Users/winfreddy88/git/libfaketime/src/libfaketime.1.dylib exists and seems to have been built successfully (zero exit code).

wolfcw commented 1 year ago

Please see https://github.com/wolfcw/libfaketime/blob/df8a04559743c9de6fbad0e8279ee69ea09b914c/README.OSX#L141-L153 , as this is the most likely cause.

The error you get is just a warning (treated as error, you may want to remote -Werror from the Makefile). Which macOS and gcc version does this happen on? However, this is not related to the built libfaketime.dylib not working.

winfreddy88 commented 1 year ago

Many thanks, indeed that seems to be the case. Sorry for the noise! And thank you for the great tool, it is immensely helpful. :-)