[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 5/7] qga/commands-posix: 'guest-shutdown' for Solaris
From: |
marcandre . lureau |
Subject: |
[PULL 5/7] qga/commands-posix: 'guest-shutdown' for Solaris |
Date: |
Wed, 4 May 2022 14:00:59 +0400 |
From: Andrew Deason <adeason@sinenomine.net>
On Solaris, instead of the -P, -H, and -r flags, we need to provide
the target init state to the 'shutdown' command: state 5 is poweroff,
0 is halt, and 6 is reboot. We also need to pass -g0 to avoid the
default 60-second delay, and -y to avoid a confirmation prompt.
Implement this logic under an #ifdef CONFIG_SOLARIS, so the
'guest-shutdown' command works properly on Solaris.
Signed-off-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20220426195526.7699-6-adeason@sinenomine.net>
---
qga/commands-posix.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index ee997a58f21c..7ab8d5eb3c69 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -85,13 +85,23 @@ void qmp_guest_shutdown(bool has_mode, const char *mode,
Error **errp)
pid_t pid;
int status;
+#ifdef CONFIG_SOLARIS
+ const char *powerdown_flag = "-i5";
+ const char *halt_flag = "-i0";
+ const char *reboot_flag = "-i6";
+#else
+ const char *powerdown_flag = "-P";
+ const char *halt_flag = "-H";
+ const char *reboot_flag = "-r";
+#endif
+
slog("guest-shutdown called, mode: %s", mode);
if (!has_mode || strcmp(mode, "powerdown") == 0) {
- shutdown_flag = "-P";
+ shutdown_flag = powerdown_flag;
} else if (strcmp(mode, "halt") == 0) {
- shutdown_flag = "-H";
+ shutdown_flag = halt_flag;
} else if (strcmp(mode, "reboot") == 0) {
- shutdown_flag = "-r";
+ shutdown_flag = reboot_flag;
} else {
error_setg(errp,
"mode is invalid (valid values are: halt|powerdown|reboot");
@@ -106,8 +116,13 @@ void qmp_guest_shutdown(bool has_mode, const char *mode,
Error **errp)
reopen_fd_to_null(1);
reopen_fd_to_null(2);
+#ifdef CONFIG_SOLARIS
+ execl("/sbin/shutdown", "shutdown", shutdown_flag, "-g0", "-y",
+ "hypervisor initiated shutdown", (char *)NULL);
+#else
execl("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",
"hypervisor initiated shutdown", (char *)NULL);
+#endif
_exit(EXIT_FAILURE);
} else if (pid < 0) {
error_setg_errno(errp, errno, "failed to create child process");
--
2.36.0.44.g0f828332d5ac
- [PULL 0/7] QGA patches, marcandre . lureau, 2022/05/04
- [PULL 1/7] qga/commands-posix: Use getifaddrs when available, marcandre . lureau, 2022/05/04
- [PULL 2/7] qga/commands-posix: Fix iface hw address detection, marcandre . lureau, 2022/05/04
- [PULL 4/7] qga/commands-posix: Log all net stats failures, marcandre . lureau, 2022/05/04
- [PULL 3/7] qga/commands-posix: Fix listing ifaces for Solaris, marcandre . lureau, 2022/05/04
- [PULL 5/7] qga/commands-posix: 'guest-shutdown' for Solaris,
marcandre . lureau <=
- [PULL 6/7] qga: Introduce NVMe disk bus type, marcandre . lureau, 2022/05/04
- [PULL 7/7] qga: Introduce disk smart, marcandre . lureau, 2022/05/04
- Re: [PULL 0/7] QGA patches, Richard Henderson, 2022/05/04