[10555] in bugtraq

home help back first fref pref prev next nref lref last post

Re: Clarification: LD_PRELOAD issue

daemon@ATHENA.MIT.EDU (John R. LoVerso)
Fri May 14 13:59:29 1999

Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="------------92A923A295EA885F29EA0156"
Message-Id: <373C466D.AB391B14@loverso.southborough.ma.us>
Date: 	Fri, 14 May 1999 11:51:09 -0400
Reply-To: "John R. LoVerso" <john@LOVERSO.SOUTHBOROUGH.MA.US>
From: "John R. LoVerso" <john@LOVERSO.SOUTHBOROUGH.MA.US>
To: BUGTRAQ@NETSPACE.ORG

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--

home help back first fref pref prev next nref lref last post