Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: running a process (oracle db) with modified system time

Re: running a process (oracle db) with modified system time

From: Richard L. Hamilton <Richard.L.Hamilton_at_mindwarp.smart.net>
Date: Sun, 16 May 2004 02:49:19 -0000
Message-ID: <10adllfri46qac@corp.supernews.com>


In article <barmar-AC84E4.21135515052004_at_comcast.dca.giganews.com>,

        Barry Margolin <barmar_at_alum.mit.edu> writes:

> In article <slrn.pl.cadde9.3vvpmv9.jarek_at_Jarek.Baczynski>,
>  Jarek 'bacza' Baczynski <jarek_at_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:

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

-- 
mailto:rlhamil@smart.net  http://www.smart.net/~rlhamil
Received on Sat May 15 2004 - 21:49:19 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US