From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:53101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UG1fU-0002NG-U9 for qemu-devel@nongnu.org; Thu, 14 Mar 2013 02:29:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UG1fT-0000YX-NE for qemu-devel@nongnu.org; Thu, 14 Mar 2013 02:29:36 -0400 Received: from e28smtp06.in.ibm.com ([122.248.162.6]:45830) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UG1fT-0000Y4-46 for qemu-devel@nongnu.org; Thu, 14 Mar 2013 02:29:35 -0400 Received: from /spool/local by e28smtp06.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 14 Mar 2013 11:55:44 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 7F1D63940023 for ; Thu, 14 Mar 2013 11:59:27 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2E6TMYI25952306 for ; Thu, 14 Mar 2013 11:59:23 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2E6TPJO021998 for ; Thu, 14 Mar 2013 06:29:25 GMT Message-ID: <51416E38.7080906@linux.vnet.ibm.com> Date: Thu, 14 Mar 2013 14:29:12 +0800 From: Lei Li MIME-Version: 1.0 References: <1363169431-1561-1-git-send-email-lilei@linux.vnet.ibm.com> <1363169431-1561-3-git-send-email-lilei@linux.vnet.ibm.com> <20130313202540.GG4005@vm> In-Reply-To: <20130313202540.GG4005@vm> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/2] qga: add windows implementation for guest-set-time List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mdroth Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org On 03/14/2013 04:25 AM, mdroth wrote: > On Wed, Mar 13, 2013 at 06:10:31PM +0800, lilei@linux.vnet.ibm.com wrote: >> From: Lei Li >> >> Signed-off-by: Lei Li >> --- >> 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