entd: fix problem problem with multi-second timeouts on ARM

BUG=chromium-os:160007
TEST=ran with pkcs11 failing on x86 and verified multiple-minute timeouts work correctly

Change-Id: If4a6cc8cdf8dc132d5520d183983d40144a93a56
Reviewed-on: http://gerrit.chromium.org/gerrit/2100
Tested-by: Ken Mixter <kmixter@chromium.org>
Reviewed-by: Sam Leffler <sleffler@chromium.org>
diff --git a/entd.cc b/entd.cc
index 6750ffd..84aff20 100644
--- a/entd.cc
+++ b/entd.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -32,6 +32,11 @@
 
 void dispatch_OnTimeout(int fd, short flags, void* arg);
 
+inline struct timeval CreateTimeoutInMs(uint64_t milliseconds) {
+  struct timeval tv = { milliseconds / 1000, milliseconds % 1000 * 1000 };
+  return tv;
+}
+
 // Class to represent a pending timeout event.
 class Timeout {
  public:
@@ -55,7 +60,7 @@
     handle_ = (((0xFFFF & reinterpret_cast<size_t>(this)) << 16) |
                ++Timeout::sequence);
 
-    struct timeval tv = { 0, interval * 1000 };
+    struct timeval tv = CreateTimeoutInMs(interval);
     event_ = new struct event;
     event_set(event_, 0, 0, &dispatch_OnTimeout, this);
     event_add(event_, &tv);
@@ -122,7 +127,7 @@
 
   // Calling Start on a running timeout will simply reset the timer
   void Start() {
-    struct timeval tv = { 0, interval_ };
+    struct timeval tv = CreateTimeoutInMs(interval_);
     event_add(event_, &tv);
   }
 
@@ -727,7 +732,7 @@
 
 void Entd::ScheduleShutdown(uint32_t code, uint32_t interval) {
   exit_code_ = code;
-  struct timeval tv = { 0, interval * 1000 };
+  struct timeval tv = CreateTimeoutInMs(interval);
   event_loopexit(&tv);
 }