diff options
author | Wolfgang Hommel <wolfcw@users.noreply.github.com> | 2019-11-30 09:36:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-30 09:36:36 +0100 |
commit | af2d2e5111e0e23fc80b2a838b692c597fb8d6a7 (patch) | |
tree | a4ba7beab960159a3cda6d0538c057ca1059113f /src | |
parent | 11fbc2ada1dc3d7d90d600071174ae181cedaa27 (diff) | |
parent | f92d919fb0635768bc95b5bc2d45a73411c52deb (diff) | |
download | libfaketime-af2d2e5111e0e23fc80b2a838b692c597fb8d6a7.tar.gz |
Merge pull request #178 from manchicken/automake-branch
Automake branch
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 128 | ||||
-rw-r--r-- | src/Makefile.OSX | 75 | ||||
-rw-r--r-- | src/Makefile.am | 37 | ||||
-rw-r--r-- | src/faketime.c | 37 | ||||
-rw-r--r-- | src/faketime_common.h | 24 | ||||
-rw-r--r-- | src/libfaketime.c | 1 |
6 files changed, 82 insertions, 220 deletions
diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 4f67ca3..0000000 --- a/src/Makefile +++ /dev/null @@ -1,128 +0,0 @@ -# -# Notes: -# -# * Compilation Defines: -# -# FAKE_STAT -# - Enables time faking also for files' timestamps. -# -# NO_ATFILE -# - Disables support for the fstatat() group of functions -# -# PTHREAD_SINGLETHREADED_TIME -# - Define this if you want to single-thread time() ... there ARE -# possible caching side-effects in a multithreaded environment -# without this, but the performance impact may require you to -# try it unsynchronized. -# -# FAKE_INTERNAL_CALLS -# - Also intercept libc internal __functions, e.g. not just time(), -# but also __time(). Enhances compatibility with applications -# that make use of low-level system calls, such as Java Virtual -# Machines. -# -# FAKE_SLEEP -# - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll() -# -# FAKE_TIMERS -# - Also intercept timer_settime() and timer_gettime() -# -# FAKE_PTHREAD -# - Intercept pthread_cond_timedwait -# -# FAKE_SETTIME -# - Intercept clock_settime(), settimeofday(), and adjtime() -# -# FORCE_MONOTONIC_FIX -# - If the test program hangs forever on -# " pthread_cond_timedwait: CLOCK_MONOTONIC test -# (Intentionally sleeping 1 second...) " -# then add -DFORCE_MONOTONIC_FIX to CFLAGS and recompile. -# (This is a platform-specific issue we cannot handle at run-time.) -# -# 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 -# ld automatically choose the correct library version to use for the -# target binary. Use for Linux platforms with Multi-Arch support only! -# -# * Compilation addition: second libMT target added for building the pthread- -# enabled library as a separate library -# -# * Compilation switch change: previous versions compiled using '-nostartfiles' -# This is no longer the case since there is a 'startup' constructor for the library -# which is used to activate the start-at times when specified. This also initializes -# the dynamic disabling of the FAKE_STAT calls. -# -# By default, libfaketime will be compiled for your system's default architecture. -# To build 32-bit libraries and binaries, add -m32 to CFLAGS and LDFLAGS. -# -# Change PREFIX to where you want libfaketime (libraries and wrapper binary) installed. -# LIBDIRNAME is relative to PREFIX. The default is to install into $PREFIX/lib/faketime, -# but you can set LIBDIRNAME to, e.g., /lib64 if you want to install it elsewhere. -# LIBDIRNAME has been introduced to support MultiLib systems. Please do not change the -# default value on MultiArch systems. -# -# For testing in the current directory without installation, try make PREFIX= LIBDIRNAME='.' - -CC ?= gcc -INSTALL ?= install - -PREFIX ?= /usr/local -LIBDIRNAME ?= /lib/faketime -PLATFORM ?=$(shell uname) - -CFLAGS += -std=gnu99 -Wall -Wextra -Werror -Wno-nonnull-compare -DFAKE_PTHREAD -DFAKE_STAT -DFAKE_SLEEP -DFAKE_TIMERS -DFAKE_INTERNAL_CALLS -fPIC -DPREFIX='"'$(PREFIX)'"' -DLIBDIRNAME='"'$(LIBDIRNAME)'"' $(FAKETIME_COMPILE_CFLAGS) -ifeq ($(PLATFORM),SunOS) -CFLAGS += -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -endif - -LIB_LDFLAGS += -shared - -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 -BINS = faketime - -SONAME = 1 -LIBS = libfaketime.so.${SONAME} libfaketimeMT.so.${SONAME} - -all: ${LIBS} ${BINS} - -libfaketimeMT.o: EXTRA_FLAGS := -DPTHREAD_SINGLETHREADED_TIME - -${LIBS_OBJ}: libfaketime.c - ${CC} -o $@ -c ${CFLAGS} ${CPPFLAGS} ${EXTRA_FLAGS} $< - -%.so.${SONAME}: %.o libfaketime.map - ${CC} -o $@ -Wl,-soname,$@ ${LDFLAGS} ${LIB_LDFLAGS} $< ${LDADD} - -${BINS}: faketime.c - ${CC} -o $@ ${CFLAGS} ${CPPFLAGS} ${EXTRA_FLAGS} $< ${LDFLAGS} ${BIN_LDFLAGS} - -clean: - @rm -f ${LIBS_OBJ} ${LIBS} ${BINS} - -distclean: clean - @echo - -install: ${LIBS} ${BINS} - @echo - @echo "Copying the faketime libraries to ${DESTDIR}${PREFIX}${LIBDIRNAME} and the faketime wrapper script to ${DESTDIR}${PREFIX}/bin ..." - $(INSTALL) -dm0755 "${DESTDIR}${PREFIX}${LIBDIRNAME}/" - $(INSTALL) -m0644 ${LIBS} "${DESTDIR}${PREFIX}${LIBDIRNAME}/" - $(INSTALL) -Dm0755 faketime "${DESTDIR}${PREFIX}/bin/faketime" - -uninstall: - for f in ${LIBS}; do rm -f "${DESTDIR}${PREFIX}${LIBDIRNAME}/$$f"; done - rmdir "${DESTDIR}${PREFIX}${LIBDIRNAME}" - rm -f "${DESTDIR}${PREFIX}/bin/faketime" - -.PHONY: all clean distclean install uninstall diff --git a/src/Makefile.OSX b/src/Makefile.OSX deleted file mode 100644 index 587a8b5..0000000 --- a/src/Makefile.OSX +++ /dev/null @@ -1,75 +0,0 @@ -# -# Notes: -# -# * Compilation Defines: -# -# FAKE_STAT -# - Enables time faking also for files' timestamps. -# -# NO_ATFILE -# - Disables support for the fstatat() group of functions -# -# PTHREAD -# - Define this to enable multithreading support. -# -# PTHREAD_SINGLETHREADED_TIME -# - Define this if you want to single-thread time() ... there ARE -# possible caching side-effects in a multithreaded environment -# without this, but the performance impact may require you to -# try it unsynchronized. -# -# FAKE_SLEEP -# - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll() -# -# * Compilation addition: second libMT target added for building the pthread- -# enabled library as a separate library -# -# * Compilation switch change: previous versions compiled using '-nostartfiles' -# This is no longer the case since there is a 'startup' constructor for the library -# which is used to activate the start-at times when specified. This also initializes -# the dynamic disabling of the FAKE_STAT calls. -# -# By default, libfaketime will be compiled for your system's default architecture. -# To build for a different architecture, add -arch flags to CFLAGS and LDFLAGS. -# -# default to clang to support thread local variables -CC ?= clang -INSTALL ?= install - -PREFIX ?= /usr/local - -CFLAGS += -DFAKE_SLEEP -DFAKE_INTERNAL_CALLS -DPREFIX='"'${PREFIX}'"' $(FAKETIME_COMPILE_CFLAGS) -LIB_LDFLAGS += -dynamiclib -current_version 0.9.8 -compatibility_version 0.7 - -SONAME = 1 -LIBS = libfaketime.${SONAME}.dylib -BINS = faketime - -all: ${LIBS} ${BINS} - -libfaketime.${SONAME}.dylib: libfaketime.c - ${CC} -o $@ ${CFLAGS} ${LDFLAGS} ${LIB_LDFLAGS} -install_name ${PREFIX}/lib/faketime/$@ $< - -faketime: faketime.c - ${CC} -o $@ ${CFLAGS} ${LDFLAGS} $< - -clean: - @rm -f ${OBJ} ${LIBS} ${BINS} - -distclean: clean - @echo - -install: ${LIBS} ${BINS} - @echo - @echo "Copying the faketime libraries to ${DESTDIR}${PREFIX}/lib/faketime and the faketime wrapper script to ${DESTDIR}${PREFIX}/bin ..." - $(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/lib/faketime/" - $(INSTALL) -m0644 ${LIBS} "${DESTDIR}${PREFIX}/lib/faketime/" - $(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/bin" - $(INSTALL) -m0755 faketime "${DESTDIR}${PREFIX}/bin/faketime" - -uninstall: - for f in ${LIBS}; do rm -f "${DESTDIR}${PREFIX}/lib/faketime/$$f"; done - rmdir "${DESTDIR}${PREFIX}/lib/faketime" - rm -f "${DESTDIR}${PREFIX}/bin/faketime" - -.PHONY: all clean distclean install uninstall diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..7a2eeaf --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,37 @@ +ACLOCAL_AMFLAGS=-I m4 +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIBOBJDIR = "." +libtool: $(LIBTOOL_DEPS) + $(SHELL) ./config.status libtool + +AM_CFLAGS =-DFAKE_SLEEP -DFAKE_INTERNAL_CALLS + +AM_LDFLAGS = + +if SOLARIS + AM_CFLAGS += -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 + 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 +endif + +LTCFLAGS="" + +lib_LTLIBRARIES = libfaketime.la libfaketimeMT.la +libfaketime_la_SOURCES = libfaketime.c +libfaketimeMT_la_SOURCES = libfaketime.c + +bin_PROGRAMS = faketime +faketime_SOURCES = faketime.c + +if MACOS + libfaketime_la_LDFLAGS = -dynamiclib -current_version 0.9.8 -compatibility_version 0.7 +else + libfaketime_la_LIBADD = -ldl -lm -lrt -lpthread + libfaketime_la_LDFLAGS = -shared -Wl,--version-script=libfaketime.map + libfaketimeMT_la_LIBADD = -ldl -lm -lrt -lpthread + libfaketimeMT_la_CFLAGS = -DPTHREAD_SINGLETHREADED_TIME + libfaketimeMT_la_LDFLAGS = -shared -Wl,--version-script=libfaketime.map -DPTHREAD_SINGLETHREADED_TIME + faketime_LDADD = -ldl -lm -lrt -lpthread +endif diff --git a/src/faketime.c b/src/faketime.c index 452a58f..99d2f9e 100644 --- a/src/faketime.c +++ b/src/faketime.c @@ -47,8 +47,9 @@ #include <semaphore.h> #include "faketime_common.h" +#include "config.h" -const char version[] = "0.9.7"; +const char version[] = VERSION; #ifdef __APPLE__ static const char *date_cmd = "gdate"; @@ -295,19 +296,21 @@ int main (int argc, char **argv) { char *ftpl_path; #ifdef __APPLE__ - ftpl_path = PREFIX "/libfaketime.1.dylib"; - FILE *check; - check = fopen(ftpl_path, "ro"); - if (check == NULL) - { - ftpl_path = PREFIX "/lib/faketime/libfaketime.1.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"); @@ -318,17 +321,17 @@ 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 = LIBPREFIX "/libfaketimeMT.so." LIBVERSION; #else - ftpl_path = PREFIX "/$LIB/faketime/libfaketimeMT.so.1"; + ftpl_path = PREFIX "/$LIB/faketime/libfaketimeMT.so." LIBVERSION; #endif } else { #ifndef MULTI_ARCH - ftpl_path = PREFIX LIBDIRNAME "/libfaketime.so.1"; + ftpl_path = LIBPREFIX "/libfaketime.so." LIBVERSION; #else - ftpl_path = PREFIX "/$LIB/faketime/libfaketime.so.1"; + ftpl_path = PREFIX "/$LIB/faketime/libfaketime.so." LIBVERSION; #endif } len = ((ld_preload)?strlen(ld_preload) + 1: 0) + 1 + strlen(ftpl_path); 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/src/libfaketime.c b/src/libfaketime.c index 745384d..cd65135 100644 --- a/src/libfaketime.c +++ b/src/libfaketime.c @@ -44,6 +44,7 @@ #include <netinet/in.h> #include <limits.h> +#include "config.h" #include "uthash.h" #include "time_ops.h" |