Up ../

libclockhack — set the time backward/forward for a process by intercepting the relevant system calls.

A small shared library that intercepts the three system calls that linux processes use to get the current time

time_t time (time_t* t);                                       -- time(2)
int    gettimeofday (struct timeval* tv, struct timezone* tz); -- gettimeofday(2)
int    clock_gettime (clockid_t clk_id, struct timespec* ts);  -- clock_gettime(2)

The offset in seconds from the current time is passed via the environment variable HACK_CLOCK_SHIFT. Note: the apparent time still increases monotonically at a constant offset from the real time.


# date uses clock_gettime(2)
Mon Apr  8 21:02:35 EST 2013

LD_PRELOAD=`pwd`/ HACK_CLOCK_SHIFT=-100000000 /bin/date
Sat Feb  6 11:16:25 EST 2010

Source at Source in files/

This library was knocked up to temporarily keep an application (with a current valid license) going with an older version of the software which had the nasty habit of expiring its idea of the license after one year. (The data collection is what was licensed rather than the application.)

Should be able to fiddle it to work on most unix systems. If RTLD_NEXT isn't supported then accessing the real system calls using the syscall(2) interface is another option.

NetBSD seems to rename gettimeofday to gettimeofday50 and has a slightly different prototype but does work after making this change.

Creative Commons CC0

James Sainsbury