Current time in chroot-ed environment differs from local time

1k views Asked by At

My c program in chrooted environment does not give proper current time, how to deal with it ? Is there something to mount for it ? It is working properly in normal directory. but seems something wrong with chroot.

#include <stdio.h>      /* puts */
#include <time.h>       /* time_t, struct tm, time, localtime, strftime */

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;
  char buffer [80];

  time (&rawtime);
  timeinfo = localtime (&rawtime);

  strftime (buffer,80,"date=%Y-%m-%d time=%H:%M:%S",timeinfo);
  puts (buffer);

  return 0;
}

normal execution:

./bin/binarycode
date=2013-09-23 time=20:09:02

chrooted execution:

/usr/sbin/chroot /var/rooted /bin/binarycode
date=2013-09-24 time=01:50:04 

It seems the time is shown is 5.30 hrs. difference.

I cannot do softlink/hardlink in this scenario. I am running this on redhat.

0

There are 0 answers