From 3e1f70db42f099696c68ae51eaf54e57bc024f02 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Mon, 20 Feb 2017 19:13:04 +0000 Subject: [PATCH] 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 --- minix/drivers/vmm_guest/vbox/vbox.c | 60 +++++++++++++++-------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/minix/drivers/vmm_guest/vbox/vbox.c b/minix/drivers/vmm_guest/vbox/vbox.c index 346c96eb1..95896f5d2 100644 --- a/minix/drivers/vmm_guest/vbox/vbox.c +++ b/minix/drivers/vmm_guest/vbox/vbox.c @@ -53,6 +53,33 @@ int vbox_request(struct VMMDevRequestHeader *header, phys_bytes addr, 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 * *===========================================================================*/ @@ -111,7 +138,11 @@ static int vbox_init(int UNUSED(type), sef_init_info_t *UNUSED(info)) 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; } @@ -147,33 +178,6 @@ static void vbox_intr(void) 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 * *===========================================================================*/ -- 2.44.0