diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | configure.ac | 21 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/faketime.c | 26 | ||||
-rw-r--r-- | src/faketime_common.h | 24 | ||||
-rw-r--r-- | test/Makefile.am | 3 | ||||
-rw-r--r-- | test/functests/common.inc | 9 | ||||
-rwxr-xr-x | test/test.sh | 70 | ||||
-rw-r--r-- | test/timetest.c | 2 |
9 files changed, 120 insertions, 39 deletions
@@ -6,4 +6,4 @@ src/libfaketime.dylib.1 src/libfaketime.1.dylib src/core src/faketime - +m4/*.m4* diff --git a/configure.ac b/configure.ac index 9703c5a..aacec52 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,15 @@ +# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info +m4_define([lft_major_version], [0]) +m4_define([lft_minor_version], [9]) +m4_define([lft_micro_version], [8]) +m4_define([libfaketime_version], + [lft_major_version.lft_minor_version.lft_micro_version]) + AC_PREREQ([2.68]) -AC_INIT(libfaketime, 0.9.8) +AC_INIT([libfaketime], [libfaketime_version]) AC_SUBST([LIBTOOL_DEPS]) -AC_CONFIG_MACRO_DIRS([m4]) +#AC_CONFIG_MACRO_DIRS([m4]) +AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_CONDITIONAL(MACOS, test `uname` = "Darwin") @@ -9,17 +17,22 @@ AM_CONDITIONAL(SOLARIS, test `uname` = "SunOS") eval PREFIX=`test "$prefix" = NONE && prefix=$ac_default_prefix; eval echo "${prefix}"` eval LIBPREFIX="$PREFIX/lib" -eval LIBVERSION="$(echo ${VERSION} | cut -d. -f1)" +LIBFAKETIME_MAJOR_VERSION=lft_major_version AC_SUBST(PREFIX) AC_SUBST(LIBPREFIX) AC_SUBST(LIBVERSION) AC_DEFINE_UNQUOTED(PREFIX, "$PREFIX", [The install prefix for the package]) AC_DEFINE_UNQUOTED(LIBPREFIX, "$LIBPREFIX", [The install prefix for libraries]) -AC_DEFINE_UNQUOTED(LIBVERSION, "$LIBVERSION", [The library version number]) +AC_DEFINE(LIBVERSION, ["lft_major_version"], [The library version number]) AC_CONFIG_SRCDIR([src]) AC_CONFIG_HEADERS([config.h]) +# libtool versioning +LIBFAKETIME_VERSION=libfaketime_version +AC_SUBST(LIBFAKETIME_VERSION) + + # Checks for programs. AC_PROG_CC AM_PROG_AR diff --git a/src/Makefile.am b/src/Makefile.am index 2b9878e..7a2eeaf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,7 +13,7 @@ if SOLARIS AM_LDFLAGS += -Wl,--version-script=libfaketime.map endif if !MACOS - AM_CFLAGS += -std=gnu99 -Wall -Wextra -Werror -DFAKE_STAT -DFAKE_PTHREAD -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -Wno-nonnull-compare + AM_CFLAGS += -std=gnu99 -Wall -Wextra -Werror -DFAKE_STAT -DFAKE_PTHREAD -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -Wno-nonnull-compare endif LTCFLAGS="" diff --git a/src/faketime.c b/src/faketime.c index 7898d4e..09766b4 100644 --- a/src/faketime.c +++ b/src/faketime.c @@ -295,19 +295,21 @@ int main (int argc, char **argv) { char *ftpl_path; #ifdef __APPLE__ - ftpl_path = LIBPREFIX "/libfaketime." LIBVERSION ".dylib"; - FILE *check; - check = fopen(ftpl_path, "ro"); - if (check == NULL) - { - ftpl_path = PREFIX "/lib/faketime/libfaketime." LIBVERSION ".dylib"; - } - else - { - fclose(check); + if (!getenv("DYLD_INSERT_LIBRARIES") && !getenv("DYLD_FORCE_FLAT_NAMESPACE")) { + ftpl_path = LIBPREFIX "/libfaketime." LIBVERSION ".dylib"; + FILE *check; + check = fopen(ftpl_path, "ro"); + if (check == NULL) + { + ftpl_path = PREFIX "/lib/faketime/libfaketime." LIBVERSION ".dylib"; + } + else + { + fclose(check); + } + setenv("DYLD_INSERT_LIBRARIES", ftpl_path, true); + setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", true); } - setenv("DYLD_INSERT_LIBRARIES", ftpl_path, true); - setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", true); #else { char *ld_preload_new, *ld_preload = getenv("LD_PRELOAD"); diff --git a/src/faketime_common.h b/src/faketime_common.h index 9fda6a7..c95f69f 100644 --- a/src/faketime_common.h +++ b/src/faketime_common.h @@ -58,4 +58,28 @@ struct ft_shared_s #include <mach/mach_port.h> #endif +#ifdef FAKE_SLEEP +#include <time.h> +#include <poll.h> +#include <sys/types.h> +#include <semaphore.h> +/* + * Fake sleep prototypes! + */ +struct pollfd; + +int nanosleep(const struct timespec *req, struct timespec *rem); +int usleep(useconds_t usec); +unsigned int sleep(unsigned int seconds); +unsigned int alarm(unsigned int seconds); +int ppoll(struct pollfd *fds, nfds_t nfds, +const struct timespec *timeout_ts, const sigset_t *sigmask); +int poll(struct pollfd *fds, nfds_t nfds, int timeout); +int select(int nfds, fd_set *readfds, + fd_set *writefds, + fd_set *errorfds, + struct timeval *timeout); +int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout); +#endif /* FAKE_SLEEP */ + #endif diff --git a/test/Makefile.am b/test/Makefile.am index 4df3a7e..6bcf27c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,4 +1,4 @@ -AM_CFLAGS =-DFAKE_SLEEP +AM_CFLAGS =-DFAKE_SLEEP -DFAKE_INTERNAL_CALLS -I../ -I../src AM_LDFLAGS = @@ -21,4 +21,3 @@ test: timetest functest # run functional tests functest: ./testframe.sh functests - diff --git a/test/functests/common.inc b/test/functests/common.inc index d184ae2..3d9be16 100644 --- a/test/functests/common.inc +++ b/test/functests/common.inc @@ -1,5 +1,8 @@ # libfaketime-specific common support routines for tests +LIB_BUILD_PATH="../src/$(grep 'LT_OBJDIR' ../config.h | cut -d'"' -f2)" +LIBFAKETIME_LA=$(find "$LIB_BUILD_PATH" | grep 'libfaketime\.\(dylib\|so\)$') + # say which *_fakecmd wrapper to use platform() { @@ -19,7 +22,7 @@ platform() mac_fakecmd() { typeset timestring="$1"; shift - typeset fakelib=../src/libfaketime.1.dylib + typeset fakelib="$LIBFAKETIME_LA" export DYLD_INSERT_LIBRARIES=$fakelib export DYLD_FORCE_FLAT_NAMESPACE=1 FAKETIME="$timestring" \ @@ -29,7 +32,7 @@ mac_fakecmd() sunos_fakecmd() { typeset timestring="$1"; shift - typeset fakelib=../src/libfaketime.so.1 + typeset fakelib="$LIBFAKETIME_LA" export LD_PRELOAD=$fakelib FAKETIME="$timestring" \ "$@" @@ -39,7 +42,7 @@ sunos_fakecmd() linuxlike_fakecmd() { typeset timestring="$1"; shift - typeset fakelib=../src/libfaketime.so.1 + typeset fakelib="$LIBFAKETIME_LA" export LD_PRELOAD=$fakelib FAKETIME="$timestring" \ "$@" diff --git a/test/test.sh b/test/test.sh index 630cec6..008cf56 100755 --- a/test/test.sh +++ b/test/test.sh @@ -1,14 +1,38 @@ #!/bin/sh +################################################################## +# NOTICE: # +# When you edit this script, maintain compatibility with BASH 3. # +# This is the version that Apple distributes. # +################################################################## + +LIB_BUILD_PATH="../src/$(grep 'LT_OBJDIR' ../config.h | cut -d'"' -f2)" +LIBFAKETIME_LA=$(find "$LIB_BUILD_PATH" | grep 'libfaketime\.\(dylib\|so\)$') + +set_libfaketime() { + the_path="$LIBFAKETIME_LA" + if [[ "$(uname)" = "Darwin" ]]; then + export DYLD_INSERT_LIBRARIES="$the_path" + export DYLD_FORCE_FLAT_NAMESPACE=1 + else + export LD_PRELOAD="$the_path" + fi +} + +echo $(set_libfaketime) + + if [ -f /etc/faketimerc ] ; then echo "Running the test program with your system-wide default in /etc/faketimerc" - echo "\$ LD_PRELOAD=../src/libfaketime.so.1 ./timetest" - LD_PRELOAD=../src/libfaketime.so.1 ./timetest + echo "\$ $(set_libfaketime) ./timetest" + set_libfaketime + ./timetest echo else echo "Running the test program with no faked time specified" - echo "\$ LD_PRELOAD=../src/libfaketime.so.1 ./timetest" - LD_PRELOAD=../src/libfaketime.so.1 ./timetest + echo "\$ $(set_libfaketime) ./timetest" + set_libfaketime + ./timetest echo fi @@ -16,48 +40,62 @@ echo "========================================================================== echo echo "Running the test program with absolute date 2003-01-01 10:00:05 specified" -echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"2003-01-01 10:00:05\" ./timetest" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="2003-01-01 10:00:05" ./timetest +echo "\$ $(set_libfaketime) FAKETIME=\"2003-01-01 10:00:05\" ./timetest" +set_libfaketime +export FAKETIME="2003-01-01 10:00:05" +./timetest echo echo "=============================================================================" echo echo "Running the test program with START date @2005-03-29 14:14:14 specified" -echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"@2005-03-29 14:14:14\" ./timetest" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="@2005-03-29 14:14:14" ./timetest +echo "\$ $(set_libfaketime) FAKETIME=\"@2005-03-29 14:14:14\" ./timetest" +set_libfaketime +export FAKETIME="@2005-03-29 14:14:14" +./timetest echo echo "=============================================================================" echo echo "Running the test program with 10 days negative offset specified" -echo "LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-10d\" ./timetest" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-10d" ./timetest +echo "$(set_libfaketime) FAKETIME=\"-10d\" ./timetest" +set_libfaketime +export FAKETIME="-10d" +./timetest echo echo "=============================================================================" echo echo "Running the test program with 10 days negative offset specified, and FAKE_STAT disabled" -echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-10d\" NO_FAKE_STAT=1 ./timetest" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-10d" NO_FAKE_STAT=1 ./timetest +echo "\$ $(set_libfaketime) FAKETIME=\"-10d\" NO_FAKE_STAT=1 ./timetest" +set_libfaketime +export FAKETIME="-10d" +export NO_FAKE_STAT=1 +./timetest echo echo "=============================================================================" echo echo "Running the test program with 10 days positive offset specified, and sped up 2 times" -echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"+10d x2\" ./timetest" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="+10d x2" NO_FAKE_STAT=1 ./timetest +echo "\$ $(set_libfaketime) FAKETIME=\"+10d x2\" ./timetest" +set_libfaketime +export FAKETIME="+10d x2" +export NO_FAKE_STAT=1 +./timetest echo echo "=============================================================================" echo echo "Running the 'date' command with 15 days negative offset specified" -echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-15d\" date" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-15d" date +echo "\$ $(set_libfaketime) FAKETIME=\"-15d\" date" +set_libfaketime +export FAKETIME="-15d" +date echo echo "=============================================================================" diff --git a/test/timetest.c b/test/timetest.c index 4e3515c..c0a15c5 100644 --- a/test/timetest.c +++ b/test/timetest.c @@ -18,6 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "config.h" #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> @@ -111,6 +112,7 @@ void* pthread_test(void* args) } #endif +#include "faketime_common.h" int main (int argc, char **argv) { |