From nobody Thu May 2 00:17:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503404507625263.03163099784376; Tue, 22 Aug 2017 05:21:47 -0700 (PDT) Received: from localhost ([::1]:41209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk8Bm-0005K8-CX for importer@patchew.org; Tue, 22 Aug 2017 08:21:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk8Ar-0004lX-Hw for qemu-devel@nongnu.org; Tue, 22 Aug 2017 08:20:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk8Al-0004hZ-NS for qemu-devel@nongnu.org; Tue, 22 Aug 2017 08:20:49 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:34737) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dk8Al-0004h7-8z for qemu-devel@nongnu.org; Tue, 22 Aug 2017 08:20:43 -0400 Received: by mail-wr0-x243.google.com with SMTP id p14so17086151wrg.1 for ; Tue, 22 Aug 2017 05:20:41 -0700 (PDT) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id j137sm3074279wmd.0.2017.08.22.05.20.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2017 05:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=X0X+5i5E/Ty0E4Ch71fpmpkeZHIbTH0KwrbM+v3qteY=; b=0GqQDIYOjBcHmx7fV7f3ma0FU82IK+xLxJl09eGQd6u3z6Bco4MxG5HVBTybozFgmX /CGMA44WU4oFWSu3ajtY/F/hZ/TnNb/0wsbGYOnn37FOEH43nE2tdIZeMFyDoFE8D2tS kwA89yDWsfNwX8Ru8pYv9WClZCeF7FztkPTDjzzMvmQDy0b/SDYbXFaE74sM8B/DDPWh VXVrKqGEYSSukFflVIqw7a9Geo9Qj3gBtfJF9Oa7895tANTOqhrX/Fmf7lxzByhQMeSA YeXZwBVLiJXR38NCvDl/pWSyjG++iO+qF7Tf1ioSK7lkhxTYYEAYe0Z3FJTBqMhT4i29 iLKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=X0X+5i5E/Ty0E4Ch71fpmpkeZHIbTH0KwrbM+v3qteY=; b=PocOsMqGWgqi/yO/wM7rak7oWCs59y+izKcVW7fNfKUwHqoBtF9Ecl1kuSlc+pYBXs 5RNN5ZNpnQBKSnT1NJ7RnN1JxyTBDmJU2G/MdxnK2wJadcJZ4+Z4yNPQmkx5RA1hMJo1 Q+yhqlGQgFYrPrKrR2vXl5kK+yAgPl0j/RAyrlKESAhWN4oHGclAFhtTSoS/733fUk4v pHQwUdcXU5PXU+JFsu1bxP+bWX8KCLfmTuRVOS558fuIx5L/y5KEACwqI/Oee4EhEAvJ Cha85IQtSA1+Pu3uWu+Oj+uIqLvPtqzOjtGIlBOVvl2ejG7l4guq7a8Tn0rG5mCit1eL tBvw== X-Gm-Message-State: AHYfb5ja2Q5TGA+9cOr+GNAC0UM8LRzA+l8KRkyfZcAKfP2kGa1Wf/56 2rZKgxBWChQZCWp3uQiNVQ== X-Received: by 10.28.37.2 with SMTP id l2mr348571wml.112.1503404440468; Tue, 22 Aug 2017 05:20:40 -0700 (PDT) From: Bishara AbuHattoum To: qemu-devel@nongnu.org, Michael Roth Date: Tue, 22 Aug 2017 15:20:35 +0300 Message-Id: <20170822122035.8914-1-bishara@daynix.com> X-Mailer: git-send-email 2.13.5 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH] qga-win: Updating guest_set_time action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Sameeh Jubran Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" At the moment, Windows libraries don't provide a way to access RTC, so, a workaround is to use the Windows w32tm command to resync the time. Related bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=3D1183874 Signed-off-by: Bishara AbuHattoum Reviewed-by: Sameeh Jubran --- configure | 2 +- qga/commands-win32.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/configure b/configure index dd73cce62f..c7d42d8b00 100755 --- a/configure +++ b/configure @@ -824,7 +824,7 @@ if test "$mingw32" =3D "yes" ; then sysconfdir=3D"\${prefix}" local_statedir=3D confsuffix=3D"" - libs_qga=3D"-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -liphlpapi -lnetapi32= $libs_qga" + libs_qga=3D"-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lsensapi -liphlpapi = -lnetapi32 $libs_qga" fi =20 werror=3D"" diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 619dbd2bc2..f93f69baeb 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -29,6 +29,7 @@ #endif #include #include +#include =20 #include "qga/guest-agent-core.h" #include "qga/vss-win32.h" @@ -1277,8 +1278,41 @@ void qmp_guest_set_time(bool has_time, int64_t time_= ns, Error **errp) * RTC yet: * * https://msdn.microsoft.com/en-us/library/aa908981.aspx + * + * Instead, a workaround is to use the Windows win32tm command to + * resync the time using the Windows Time service. */ - error_setg(errp, "Time argument is required on this platform"); + LPVOID msg_buffer; + DWORD ret_flags; + + HRESULT hr =3D system("w32tm /resync /nowait"); + + if (GetLastError() !=3D 0) { + strerror_s((LPTSTR) & msg_buffer, 0, errno); + error_setg(errp, "system(...) failed: %s", (LPCTSTR)msg_buffer= ); + } else if (hr !=3D 0) { + if (hr =3D=3D HRESULT_FROM_WIN32(ERROR_SERVICE_NOT_ACTIVE)) { + error_setg(errp, "Windows Time service not running on the " + "guest"); + } else { + if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, NULL, + (DWORD)hr, MAKELANGID(LANG_NEUTRAL, + SUBLANG_DEFAULT), (LPTSTR) & msg_buffer= , 0, + NULL)) { + error_setg(errp, "w32tm failed with error (0x%lx), cou= ldn'" + "t retrieve error message", hr); + } else { + error_setg(errp, "w32tm failed with error (0x%lx): %s"= , hr, + (LPCTSTR)msg_buffer); + LocalFree(msg_buffer); + } + } + } else if (!IsNetworkAlive(&ret_flags)) { + error_setg(errp, "No network connection on guest, sync not" + " accurate"); + } return; } =20 --=20 2.13.5