Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

running a process (oracle db) with modified system time

1 view
Skip to first unread message

Jarek 'bacza' Baczynski

unread,
May 15, 2004, 7:23:39 PM5/15/04
to
hello there,

I'm wondering if there is a way to run a process on solaris in such
a way that it receives the system time modified with a given amount
of secs/mins/hours/...

I don't want to change the time on the server, I just want to run
a specific process in an environment that "emulates" a different time.

is it possible to write some piece of code that catches some syscalls
and returns modified time? if it is, how can I do that?
any hints/links/code examples ;) will be greatly appreciated.

the "process" is in fact an oracle database instance, so the solution
(if any) would have to be a really good one :)
(that is, on proper level of interception to make sure that any syscall
that is supposed to return a current time is intercepted consistently)

regards,
-- jb.

Howard J. Rogers

unread,
May 15, 2004, 7:51:06 PM5/15/04
to
Jarek 'bacza' Baczynski wrote:


You are joking, aren't you?

But assuming you are not, what is the actual business problem you are
trying to solve with this approach?

From where I sit, I could imagine the business problem to be "I want to
fake some audit records in my database. How do I do that?" Or, "I have
embezzled some funds and I want to fiddle the transaction dates so that
no-one will notice until next year".

I doubt that any moderately sensible person here would indulge you by
supplying instructions to do as you ask.

However, if you state what the problem you are trying to solve is, then
all sorts of possibilities may arise. In other words, WHY do you feel
you need to fool Oracle into thinking it is a different date and time
from what your server says? And WHY do you not want to simply change the
server time?

Regards
HJR

Barry Margolin

unread,
May 15, 2004, 9:13:55 PM5/15/04
to
In article <slrn.pl.cadde9...@Jarek.Baczynski>,

You could use LD_PRELOAD to substitute your own function in place of the
gettimeofday() system call.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Richard L. Hamilton

unread,
May 15, 2004, 10:49:19 PM5/15/04
to
In article <barmar-AC84E4....@comcast.dca.giganews.com>,

Barry Margolin <bar...@alum.mit.edu> writes:
> In article <slrn.pl.cadde9...@Jarek.Baczynski>,
> Jarek 'bacza' Baczynski <ja...@nie.lubie.spamu.invalid> wrote:
>
>> hello there,
>>
>> I'm wondering if there is a way to run a process on solaris in such
>> a way that it receives the system time modified with a given amount
>> of secs/mins/hours/...
>>
>> I don't want to change the time on the server, I just want to run
>> a specific process in an environment that "emulates" a different time.
>>
>> is it possible to write some piece of code that catches some syscalls
>> and returns modified time? if it is, how can I do that?
>> any hints/links/code examples ;) will be greatly appreciated.
>>
>> the "process" is in fact an oracle database instance, so the solution
>> (if any) would have to be a really good one :)
>> (that is, on proper level of interception to make sure that any syscall
>> that is supposed to return a current time is intercepted consistently)
>
> You could use LD_PRELOAD to substitute your own function in place of the
> gettimeofday() system call.
>

I have something sitting around that may do that job:


============= time_offset.c ==== cut here ==============================
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <time.h>
#include <sys/time.h>
#include <sys/timex.h>
/*
* Here's an LD_PRELOADable wrapper of a few system calls that can
* trick a program into thinking that the system date is other than it
* actually is, by having it apply some offset in seconds from the actual
* date.
*
* compile as:
* gcc -fPIC -mno-app-regs -G time_offset.c -o time_offset.so
*
* Usage: to trick a command into thinking the system time is other
* than it is, set environment variables as follows:
*
* LD_PRELOAD to the full pathname of time_offset.so
* TIME_OFFSET to the number of seconds to add to the actual time
*
* For example, to get the date as of 24 hours ago,
*
* env LD_PRELOAD=$HOME/lib/time_offset.so TIME_OFFSET=-86400 date
*
* Notes:
*
* * there are various places in this code that assume that time_t is
* a signed fundamental arithmetic type (preferably an integer type,
* like long)
*
* * one might wish a full illusion to also offset the timestamps
* from stat(), fstat(), as well as info returned about SysV
* semaphores, shared memory, and message queues. This could be done,
* but wrapping at least five more functions is a bit more bother than
* I feel like going through just now.
*
*/

static int initialized;
static time_t (*time_real)(time_t *);
static int (*gettimeofday_real)(struct timeval *, void *);
static int (*ntp_gettime_real)(struct ntptimeval *);
static time_t offset;

static void init()
{
register char *e;
auto char *p;
if (initialized) /* fast exit if not needed */
return;
initialized=1;
if ((e=getenv("TIME_OFFSET"))!=NULL) {
offset=strtol(e,&p,0);
if (p==e || *p!='\0')
offset=0;
}
time_real = (time_t (*) (time_t *)) dlsym(RTLD_NEXT, "time");
gettimeofday_real = (int (*) (struct timeval *, void *))
dlsym(RTLD_NEXT, "gettimeofday");
ntp_gettime_real = (int (*) (struct ntptimeval *))
dlsym(RTLD_NEXT, "ntp_gettime");
}

time_t time(time_t *tloc)
{
register time_t rc;
init();
if ((rc = time_real(tloc)) != (time_t) -1 && offset!=0) {
rc+=offset;
if (tloc!=NULL)
*tloc+=offset;
}
return rc;
}

int gettimeofday(struct timeval *tp, void *bogus)
{
register int rc;
init();
if ((rc = gettimeofday_real(tp,bogus)) != -1 && offset!=0 && tp!=NULL)
tp->tv_sec+=offset;
return rc;
}

int ntp_gettime(struct ntptimeval *tptr)
{
register int rc;
init();
if ((rc = ntp_gettime_real(tptr)) != -1 && offset!=0)
tptr->time.tv_sec+=offset;
return rc;
}

============= time_offset.c ==== cut here ==============================


--
mailto:rlh...@smart.net http://www.smart.net/~rlhamil

Igor Laletin

unread,
May 16, 2004, 8:36:11 PM5/16/04
to
Jarek 'bacza' Baczynski <ja...@nie.lubie.spamu.invalid> wrote in message news:<slrn.pl.cadde9...@Jarek.Baczynski>...

> hello there,
>
> I'm wondering if there is a way to run a process on solaris in such
> a way that it receives the system time modified with a given amount
> of secs/mins/hours/...
>
> I don't want to change the time on the server, I just want to run
> a specific process in an environment that "emulates" a different time.

The easiest way is to set TZ env variable before you start up the
instance and the listener. You can even have different times in
different sessions if you start several listeners with different TZ's
and connect via Net.



> is it possible to write some piece of code that catches some syscalls
> and returns modified time? if it is, how can I do that?
> any hints/links/code examples ;) will be greatly appreciated.

You need it only if you want to change time on a fly. Such tools exist
and were very popular during Y2K testing. The one I used was 'Time
Machine', worked all right as far as I remember. There are limititions
of course, e.g. possible to overload shared library but not static
one.

Cheers,
Igor

> regards,
> -- jb.

Message has been deleted

Barry Margolin

unread,
May 17, 2004, 12:21:00 AM5/17/04
to
In article <f9226414.0405...@posting.google.com>,
ilal...@usa.net (Igor Laletin) wrote:

> Jarek 'bacza' Baczynski <ja...@nie.lubie.spamu.invalid> wrote in message
> news:<slrn.pl.cadde9...@Jarek.Baczynski>...
> > hello there,
> >
> > I'm wondering if there is a way to run a process on solaris in such
> > a way that it receives the system time modified with a given amount
> > of secs/mins/hours/...
> >
> > I don't want to change the time on the server, I just want to run
> > a specific process in an environment that "emulates" a different time.
>
> The easiest way is to set TZ env variable before you start up the
> instance and the listener. You can even have different times in
> different sessions if you start several listeners with different TZ's
> and connect via Net.

That would change the way the time is displayed to humans, but won't
have any effect on the times used internally within the program. Those
times are simply the interval since the epoch.

Frank van Bortel

unread,
May 17, 2004, 3:54:01 PM5/17/04
to
Howard J. Rogers wrote:

> Jarek 'bacza' Baczynski wrote:
>
>> hello there,
>>
>> I'm wondering if there is a way to run a process on solaris in such
>> a way that it receives the system time modified with a given amount
>> of secs/mins/hours/...
>>
>> I don't want to change the time on the server, I just want to run
>> a specific process in an environment that "emulates" a different time.
>>
>> is it possible to write some piece of code that catches some syscalls
>> and returns modified time? if it is, how can I do that?
>> any hints/links/code examples ;) will be greatly appreciated.
>>
>> the "process" is in fact an oracle database instance, so the solution
>> (if any) would have to be a really good one :)
>> (that is, on proper level of interception to make sure that any syscall
>> that is supposed to return a current time is intercepted consistently)
>>
>> regards,
>> -- jb.
>
>
>
> You are joking, aren't you?
>
> But assuming you are not, what is the actual business problem you are
> trying to solve with this approach?
>

Year2000? Year 2100?

To the OP: there *is* a parameter, fixed_date. Use with care!
FIXED_DATE enables you to set a constant date that SYSDATE
will always return instead of the current date.
This parameter is useful primarily for testing.
The value can be in the format shown above or in the
default Oracle date format, without a time.

> From where I sit, I could imagine the business problem to be "I want to
> fake some audit records in my database. How do I do that?" Or, "I have
> embezzled some funds and I want to fiddle the transaction dates so that
> no-one will notice until next year".
>
> I doubt that any moderately sensible person here would indulge you by
> supplying instructions to do as you ask.
>
> However, if you state what the problem you are trying to solve is, then
> all sorts of possibilities may arise. In other words, WHY do you feel
> you need to fool Oracle into thinking it is a different date and time
> from what your server says? And WHY do you not want to simply change the
> server time?
>
> Regards
> HJR


--

Regards,
Frank van Bortel

Igor Laletin

unread,
May 17, 2004, 8:23:02 PM5/17/04
to
Barry Margolin <bar...@alum.mit.edu> wrote in message news:<barmar-A8D1F0....@comcast.dca.giganews.com>...

> In article <f9226414.0405...@posting.google.com>,
> ilal...@usa.net (Igor Laletin) wrote:
>
> > Jarek 'bacza' Baczynski <ja...@nie.lubie.spamu.invalid> wrote in message
> > news:<slrn.pl.cadde9...@Jarek.Baczynski>...
[...]

> > > is it possible to write some piece of code that catches some syscalls
> > > and returns modified time? if it is, how can I do that?

> > You need it only if you want to change time on a fly.

... and if you need to go more that +- 1 day.

> > The easiest way is to set TZ env variable before you start up the
> > instance and the listener. You can even have different times in
> > different sessions if you start several listeners with different TZ's
> > and connect via Net.
>
> That would change the way the time is displayed to humans, but won't
> have any effect on the times used internally within the program. Those
> times are simply the interval since the epoch.

We are not talking just any program which may or may not use TZ.
Oracle server process calls gettimeofday (on HP-UX anyway) to get UTC
time. After that it _uses_ TZ to shift it to a proper time zone. The
adjusted time is used by the client. You can select it, insert into a
table etc. Easy to check before starting to argue.

Cheers,
Igor

0 new messages