From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: ghammer@redhat.com, aliguori@us.ibm.com,
mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH v2 8/8] qemu-ga: add win32 guest-shutdown command
Date: Thu, 2 Feb 2012 13:59:00 -0600 [thread overview]
Message-ID: <1328212740-15799-9-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1328212740-15799-1-git-send-email-mdroth@linux.vnet.ibm.com>
Implement guest-shutdown RPC for Windows. Functionally this should be
equivalent to the posix implementation.
Original patch by Gal Hammer <ghammer@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
qga/commands-win32.c | 41 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 40 insertions(+), 1 deletions(-)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index d96f1ad..4aa0f0d 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -15,9 +15,48 @@
#include "qga-qmp-commands.h"
#include "qerror.h"
+#ifndef SHTDN_REASON_FLAG_PLANNED
+#define SHTDN_REASON_FLAG_PLANNED 0x80000000
+#endif
+
void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
{
- error_set(err, QERR_UNSUPPORTED);
+ HANDLE token;
+ TOKEN_PRIVILEGES priv;
+ UINT shutdown_flag = EWX_FORCE;
+
+ slog("guest-shutdown called, mode: %s", mode);
+
+ if (!has_mode || strcmp(mode, "powerdown") == 0) {
+ shutdown_flag |= EWX_POWEROFF;
+ } else if (strcmp(mode, "halt") == 0) {
+ shutdown_flag |= EWX_SHUTDOWN;
+ } else if (strcmp(mode, "reboot") == 0) {
+ shutdown_flag |= EWX_REBOOT;
+ } else {
+ error_set(err, QERR_INVALID_PARAMETER_VALUE, "mode",
+ "halt|powerdown|reboot");
+ return;
+ }
+
+ /* Request a shutdown privilege, but try to shut down the system
+ anyway. */
+ if (OpenProcessToken(GetCurrentProcess(),
+ TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &token))
+ {
+ LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
+ &priv.Privileges[0].Luid);
+
+ priv.PrivilegeCount = 1;
+ priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
+
+ AdjustTokenPrivileges(token, FALSE, &priv, 0, NULL, 0);
+ }
+
+ if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) {
+ slog("guest-shutdown failed: %d", GetLastError());
+ error_set(err, QERR_UNDEFINED_ERROR);
+ }
}
int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Error **err)
--
1.7.4.1
next prev parent reply other threads:[~2012-02-02 20:01 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-02 19:58 [Qemu-devel] [PATCH v2 0/8] qemu-ga: add support for Windows Michael Roth
2012-02-02 19:58 ` [Qemu-devel] [PATCH v2 1/8] qemu-ga: Add schema documentation for types Michael Roth
2012-02-02 19:58 ` [Qemu-devel] [PATCH v2 2/8] qemu-ga: move channel/transport functionality into wrapper class Michael Roth
2012-02-02 19:58 ` [Qemu-devel] [PATCH v2 3/8] qemu-ga: separate out common commands from posix-specific ones Michael Roth
2012-02-02 19:58 ` [Qemu-devel] [PATCH v2 4/8] qemu-ga: rename guest-agent-commands.c -> commands-posix.c Michael Roth
2012-02-02 19:58 ` [Qemu-devel] [PATCH v2 5/8] qemu-ga: fixes for win32 build of qemu-ga Michael Roth
2012-02-02 19:58 ` [Qemu-devel] [PATCH v2 6/8] qemu-ga: add initial win32 support Michael Roth
2012-02-02 19:58 ` [Qemu-devel] [PATCH v2 7/8] qemu-ga: add Windows service integration Michael Roth
2012-02-02 19:59 ` Michael Roth [this message]
2012-02-03 14:18 ` [Qemu-devel] [PATCH v2 0/8] qemu-ga: add support for Windows Luiz Capitulino
2012-02-03 16:37 ` Michael Roth
2012-02-03 16:45 ` Luiz Capitulino
2012-02-03 17:23 ` Michael Roth
2012-02-03 19:16 ` Luiz Capitulino
2012-02-04 15:34 ` Kevin O'Connor
2012-02-06 15:43 ` Luiz Capitulino
2012-02-07 0:09 ` Kevin O'Connor
2012-02-07 8:44 ` Gleb Natapov
2012-02-08 0:35 ` Kevin O'Connor
2012-02-08 7:18 ` Gleb Natapov
2012-02-08 13:25 ` Kevin O'Connor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1328212740-15799-9-git-send-email-mdroth@linux.vnet.ibm.com \
--to=mdroth@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=ghammer@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).