You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.9 KiB

  1. From 80ec6872aceb18c68b1cf5b6f8acd6ad667cbd4f Mon Sep 17 00:00:00 2001
  2. From: Yousong Zhou <yszhou4tech@gmail.com>
  3. Date: Thu, 17 Dec 2020 15:55:55 +0800
  4. Subject: [PATCH] qga: invoke separate applets for guest-shutdown modes
  5. /sbin/shutdown is not available on OpenWrt by default
  6. Origin: "main/qemu: fix shutdown from guest agent"
  7. https://gitlab.alpinelinux.org/alpine/aports/commit/76b81b486480fd9c3294cd420bcf2df01c27790d
  8. ---
  9. qga/commands-posix.c | 5 +++++
  10. 1 file changed, 5 insertions(+)
  11. diff --git a/qga/commands-posix.c b/qga/commands-posix.c
  12. index a52af0315f..623d856c64 100644
  13. --- a/qga/commands-posix.c
  14. +++ b/qga/commands-posix.c
  15. @@ -84,6 +84,7 @@ static void ga_wait_child(pid_t pid, int *status, Error **errp)
  16. void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
  17. {
  18. const char *shutdown_flag;
  19. + const char *fallback_cmd = NULL;
  20. Error *local_err = NULL;
  21. pid_t pid;
  22. int status;
  23. @@ -91,10 +92,13 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
  24. slog("guest-shutdown called, mode: %s", mode);
  25. if (!has_mode || strcmp(mode, "powerdown") == 0) {
  26. shutdown_flag = "-P";
  27. + fallback_cmd = "/sbin/poweroff";
  28. } else if (strcmp(mode, "halt") == 0) {
  29. shutdown_flag = "-H";
  30. + fallback_cmd = "/sbin/halt";
  31. } else if (strcmp(mode, "reboot") == 0) {
  32. shutdown_flag = "-r";
  33. + fallback_cmd = "/sbin/reboot";
  34. } else {
  35. error_setg(errp,
  36. "mode is invalid (valid values are: halt|powerdown|reboot");
  37. @@ -111,6 +115,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
  38. execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",
  39. "hypervisor initiated shutdown", (char*)NULL, environ);
  40. + execle(fallback_cmd, fallback_cmd, (char*)NULL, environ);
  41. _exit(EXIT_FAILURE);
  42. } else if (pid < 0) {
  43. error_setg_errno(errp, errno, "failed to create child process");