From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:33899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDFzW-0001WK-SN for qemu-devel@nongnu.org; Wed, 06 Mar 2013 10:10:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UDFzU-00033N-53 for qemu-devel@nongnu.org; Wed, 06 Mar 2013 10:10:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:6392) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDFzT-00032s-TR for qemu-devel@nongnu.org; Wed, 06 Mar 2013 10:10:48 -0500 Message-ID: <51375B2A.5000200@redhat.com> Date: Wed, 06 Mar 2013 08:05:14 -0700 From: Eric Blake MIME-Version: 1.0 References: <1362577504-7994-1-git-send-email-lilei@linux.vnet.ibm.com> <1362577504-7994-3-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1362577504-7994-3-git-send-email-lilei@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2EVOPSMVTVTCRLENOFNBW" 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: Lei Li Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2EVOPSMVTVTCRLENOFNBW Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 03/06/2013 06:45 AM, Lei Li wrote: > Signed-off-by: Lei Li > --- > qga/commands-win32.c | 35 +++++++++++++++++++++++++++++++++++ > 1 files changed, 35 insertions(+), 0 deletions(-) >=20 > diff --git a/qga/commands-win32.c b/qga/commands-win32.c > index 4febec7..1a90aa7 100644 > --- a/qga/commands-win32.c > +++ b/qga/commands-win32.c > @@ -136,6 +136,41 @@ int64_t qmp_guest_get_time(Error **errp) > return time_ns; > } > =20 > +void qmp_guest_set_time(int64_t time_ns, Error **errp) > +{ > + SYSTEMTIME ts; > + FILETIME tf; > + LONGLONG time; > + > + /* year-2038 will overflow in case time_t is 32bit */ > + if (time_ns / 1000000000 !=3D (time_t)(time_ns / 1000000000)) { > + error_setg(errp, "Time %" PRId64 " is too large", time_ns); > + return; > + } Do you really need this? That is, don't you already know what size time_t is on windows; not to mention that on Windows, you aren't going through time_t, but directly to tf.dwHighDateTime. > + > + acquire_privilege(SE_SYSTEMTIME_NAME, errp); > + if (error_is_set(errp)) { > + error_setg(errp, "Failed to acquire privilege"); > + return; > + } > + > + time =3D time_ns / 100 + _W32_FT_OFFSET; On the other hand, _this_ operation can overflow, so you should be checking that time_ns doesn't result in an unexpected time value. > + > + tf.dwLowDateTime =3D (DWORD) time; > + tf.dwHighDateTime =3D (DWORD) (time >> 32); > + > + if (!FileTimeToSystemTime(&tf, &ts)) { > + error_setg(errp, "Failed to convert system time"); > + return; > + } > + > + if (!SetSystemTime(&ts)) { > + slog("guest-set-time failed: %d", GetLastError()); > + error_setg_errno(errp, errno, "Failed to set time to guest"); > + return; > + } =20 Trailing whitespace. Run your submission through scripts/checkpatch.pl. Should you relinquish the SE_SYSTEMTIME_NAME privilege when exiting this function, instead of leaving it always enabled for the remaining life of the agent service? --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2EVOPSMVTVTCRLENOFNBW Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJRN1sqAAoJEKeha0olJ0Nqoq8H/R5EeQTkY/RsQOFORj4BSwk8 x3xOYgmCVNmSFYZfbhX6MTm53PsQYoObBhMzj9Y9Kk8odyJFb+2ErVqqALmI/GTr eAPGufak1zRvdYTg1k23HW6WF3af5xMY9fQzoxY/Om0wovM7Q1/ANUE1BEjqqh5L wrdUQLJrjXaZHQHnN0hAAJtpdD2SbwyzudC55h5hjdTjgAxWBdOx4YRcSuw0MwP8 KJuRjLPWKb2MksPQrWhOlCVgsI8++wCz0Omtme13sJnlNVqG4JFGoH3/Xo6JJazn 1s/N5ah/MaQuGNUi5qRwiHFuB1CNV5vqN+tcUY5IszotoYSHaipEfFpSClX1Iyo= =vile -----END PGP SIGNATURE----- ------enig2EVOPSMVTVTCRLENOFNBW--