VBOX: update current time immediately at startup

Performing the update at any later time may cause rc scripts to work
with a wrong date, which may have side effects, such as databse files
getting regenerated on every boot.

Change-Id: Idfdbf67ad285300c982d95769007dc88c522b908
This commit is contained in:
David van Moolenbroek 2017-02-20 19:13:04 +00:00
parent 81fc6023c2
commit 3e1f70db42

View File

@ -53,6 +53,33 @@ int vbox_request(struct VMMDevRequestHeader *header, phys_bytes addr,
return header->result; return header->result;
} }
/*===========================================================================*
* vbox_update_time *
*===========================================================================*/
static void vbox_update_time(void)
{
/* Update the current time if it has drifted too far. */
struct VMMDevReqHostTime *req;
time_t otime, ntime;
req = (struct VMMDevReqHostTime *) vir_ptr;
if (vbox_request(&req->header, phys_ptr, VMMDEV_REQ_HOSTTIME,
sizeof(*req)) == VMMDEV_ERR_OK) {
time(&otime); /* old time */
ntime = req->time / 1000; /* new time */
/* Make time go forward, if the difference exceeds the drift
* threshold. Never make time go backward.
*/
if ((ntime - otime) >= drift)
stime(&ntime);
}
sys_setalarm(ticks, 0);
}
/*===========================================================================* /*===========================================================================*
* vbox_init * * vbox_init *
*===========================================================================*/ *===========================================================================*/
@ -111,7 +138,11 @@ static int vbox_init(int UNUSED(type), sef_init_info_t *UNUSED(info))
ticks = sys_hz() * interval; ticks = sys_hz() * interval;
sys_setalarm(ticks, 0); /*
* Do the first time update immediately. If the time changes
* significantly, there may otherwise be interference with rc scripts.
*/
vbox_update_time();
return OK; return OK;
} }
@ -147,33 +178,6 @@ static void vbox_intr(void)
panic("unable to reenable IRQ: %d", r); panic("unable to reenable IRQ: %d", r);
} }
/*===========================================================================*
* vbox_update_time *
*===========================================================================*/
static void vbox_update_time(void)
{
/* Update the current time if it has drifted too far. */
struct VMMDevReqHostTime *req;
time_t otime, ntime;
req = (struct VMMDevReqHostTime *) vir_ptr;
if (vbox_request(&req->header, phys_ptr, VMMDEV_REQ_HOSTTIME,
sizeof(*req)) == VMMDEV_ERR_OK) {
time(&otime); /* old time */
ntime = req->time / 1000; /* new time */
/* Make time go forward, if the difference exceeds the drift
* threshold. Never make time go backward.
*/
if ((ntime - otime) >= drift)
stime(&ntime);
}
sys_setalarm(ticks, 0);
}
/*===========================================================================* /*===========================================================================*
* vbox_signal * * vbox_signal *
*===========================================================================*/ *===========================================================================*/