Re: Clarification: LD_PRELOAD issue

From: John R. LoVerso (johnat_private)
Date: Fri May 14 1999 - 08:51:09 PDT

  • Next message: Ken Williams: "Source code IS available (Was: Re: Windump for Windows)"

    This is a multi-part message in MIME format.
    --------------92A923A295EA885F29EA0156
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    
    Here's an example I cooked up a few years ago that accomplishes
    exactly this.  Works on FreeBSD.  ("make tryit")
    
    John
    --------------92A923A295EA885F29EA0156
    Content-Type: application/x-shar;
     name="timeskew.shar"
    Content-Transfer-Encoding: 7bit
    Content-Disposition: inline;
     filename="timeskew.shar"
    
    # This is a shell archive.  Save it in a file, remove anything before
    # this line, and then unpack it by entering "sh file".  Note, it may
    # create directories; files and directories will be owned by you and
    # have default permissions.
    #
    # This archive contains:
    #
    #	Makefile
    #	timeskew.c
    #
    echo x - Makefile
    sed 's/^X//' >Makefile << 'END-of-Makefile'
    XNOPROFILE=1
    XINTERNALLIB=1
    XSHLIB_MAJOR=1
    XSHLIB_MINOR=0
    X
    XLIB=    timeskew
    XSRCS=   timeskew.c
    X
    Xtryit:	lib$(LIB).so.1.0
    X	@echo 'puts [clock format [clock seconds]]' | tclsh
    X	@echo 'puts [clock format [clock seconds]]' | \
    X		env LD_PRELOAD=./libtimeskew.so.1.0 tclsh
    X
    X.include <bsd.lib.mk>
    END-of-Makefile
    echo x - timeskew.c
    sed 's/^X//' >timeskew.c << 'END-of-timeskew.c'
    X/*
    X * Coerces the return value from gettimeofday() to always fall within
    X * the time range starting at BASEDATE and ending at BASEDATE+TIMESPAN
    X *
    X * Todo: pick up BASEDATE and TIMESPAN from env variables
    X */
    X
    X#include <sys/time.h>
    X#include <sys/syscall.h>
    X
    X#ifndef BASEDATE
    X#define BASEDATE 820472400		/* 1 Jan 1996 00:00:00 */
    X
    X#define TIMESPAN ONELEAPYEAR	
    X/* really only want until 29 Dec 1996 (851835600), but this will do */
    X#endif
    X
    X#define ONEDAY (24*60*60)
    X#define ONEMONTH (ONEDAY*31)
    X#define ONEYEAR (ONEDAY*365)
    X#define ONELEAPYEAR (ONEDAY*366)
    X
    X#ifndef TIMESPAN
    X#define TIMESPAN ONEMONTH
    X#endif
    X
    Xint
    Xgettimeofday(struct timeval *tp, struct timezone *tzp) {
    X	int ret;
    X
    X	ret = __syscall(SYS_gettimeofday, 2, tp, tzp);
    X	if (ret == 0 && tp != NULL) {
    X		tp->tv_sec = ((tp->tv_sec - BASEDATE) % TIMESPAN) + BASEDATE;
    X	}
    X	return ret;
    X}
    X
    END-of-timeskew.c
    exit
    
    
    --------------92A923A295EA885F29EA0156--
    



    This archive was generated by hypermail 2b30 : Fri Apr 13 2001 - 14:45:57 PDT