libtimefake

There are sometimes programs which refuse to work after a certain date, for
example because of bugs in the code. In most cases it is very easy to fix
this: simply write your own version of the time() system call, put it into a
shared library, and make it override the real call. It is explained in more
detail below. This has been tested under FreeBSD, Solaris and Linux.

This is the source code of "libtimefake" (the first include line is not
needed on some platforms):

    #include <sys/types.h>
    #include <time.h>
    #define faketime 870000000
    time_t time(time_t *loc)
    {
        if (loc) *loc = faketime;
        return faketime;
    }

The time value that you want to fake is defined in the third line. It is
measure in seconds since 1-Jan-1970 0:00 UTC. In this example, it is
870000000 which is 27-Jul-1997 10:40 UTC. The "date" command helps
calculating the number (type "man date" at the shell prompt for details).

Save the above source code in a file called libtimefake.c. To build a shared
library from it, use the following command under Solaris (using the
SPARCworks C compiler):

    cc -G -o libtimefake.so libtimefake.c

... and the following command under FreeBSD or Linux (using the GNU C
compiler):

    cc -shared -o libtimefake.so libtimefake.c

Note: If you run your program under the Linux emulation of FreeBSD, you
should compile libtimefake on a Linux box. In that case you should also make
sure to use the appropriate binary format (a.out or elf). Yeah, those Linux
folks have strange problems...

Now you must make your version of the time() call override the standard
time() call which is located in the libc library. To do this, let the
environment variable LD_PRELOAD point to your library. The exact syntax
depends on the command shell that you are using. For csh and compatible
shells, use this command:

    setenv LD_PRELOAD /home/user/lib/libtimefake.so

... and for sh and compatible shells, use these two commands:

    LD_PRELOAD=/home/user/lib/libtimefake.so
    export LD_PRELOAD

Note that you have to specify the full path of your shared library,
including the directory where you put it. In the above examples, the
directory is /home/user/lib -- if you put it in a different directory, you
have to change that accordingly, of course.

Warning: When the above LD_PRELOAD setting is in effect, all commands will
use the faked time() call, which can have undesired and confusing results.
Normally you want it to be in effect only for one specific program. In that
case, it is best to write a small shell script which sets the LD_PRELOAD
variable and then executes that program, so that the faked time() call will
only be used by that program. Let's suppose that the "broken" program is
called "stubborn". Then the shell script would look like this:

    #!/bin/sh
    LD_PRELOAD=/home/user/lib/libtimefake.so
    export LD_PRELOAD
    stubborn "$@"

Don't forget to change the permissions of the script to make it executable
(type "man chmod" for help about that). You might also have to type "rehash"
or "hash -r" (depending on your shell) before the shell finds the script in
your path directories.

Disclaimer: The information on this page is provided as is and without any
warranty. Use it at your own risk. If you are not absolutely sure that you
don't damage anything, don't do it. Also, note that the information on this
page may only be used as a work-around to fix broken programs, if the author
of the program is not able to provide a fix himself within a reasonable
amount of time. You must not use the information provided on this page if it
could violate the license of the respective program. If in doubt, contact
the author of the program first.



Last changed: 6-Dec-1997, 18:39:11 MET
Copyright  Oliver Fromme <oliver.fromme@heim3.tu-clausthal.de>
