qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/2] qga: add windows implementation for guest-s


From: Lei Li
Subject: Re: [Qemu-devel] [PATCH 2/2] qga: add windows implementation for guest-set-time
Date: Thu, 14 Mar 2013 14:29:12 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

On 03/14/2013 04:25 AM, mdroth wrote:
On Wed, Mar 13, 2013 at 06:10:31PM +0800, address@hidden wrote:
From: Lei Li <address@hidden>

Signed-off-by: Lei Li <address@hidden>
---
  qga/commands-win32.c |   34 ++++++++++++++++++++++++++++++++++
  1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 0a2bb34..a0c8d43 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -140,6 +140,40 @@ int64_t qmp_guest_get_time(Error **errp)
     return time_ns;
  }

+void qmp_guest_set_time(int64_t time_ns, Error **errp)
+{
+    SYSTEMTIME ts;
+    FILETIME tf;
+    LONGLONG time;
+
+    if (time_ns < 0 || time_ns / 100 > INT64_MAX - W32_FT_OFFSET) {
+        error_setg(errp, "Time %" PRId64 "is invalid", time_ns);
+        return;
+    }
+
+    time = time_ns / 100 + W32_FT_OFFSET;
+
+    tf.dwLowDateTime = (DWORD) time;
+    tf.dwHighDateTime = (DWORD) (time >> 32);
+
+    if (!FileTimeToSystemTime(&tf, &ts)) {
+        error_setg(errp, "Failed to convert system time");
+        return;
+    }
+
+    acquire_privilege(SE_SYSTEMTIME_NAME, errp);
+    if (error_is_set(errp)) {
+        error_setg(errp, "Failed to acquire privilege");
+        return;
+    }
+
+    if (!SetSystemTime(&ts)) {
+        slog("guest-set-time failed: %d", GetLastError());
+        error_setg_errno(errp, errno, "Failed to set time to guest");
I think we want to pass back GetLastError(), SetSystemTime doesn't set errno
(and if it did something in the slog() callchain probably would've
clobbered it)

OK.

Looks good otherwise.

+        return;
+    }
+}
+
  int64_t qmp_guest_file_open(const char *path, bool has_mode, const char 
*mode, Error **err)
  {
      error_set(err, QERR_UNSUPPORTED);
--
1.7.7.6



--
Lei




reply via email to

[Prev in Thread] Current Thread [Next in Thread]