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.

45 lines
1.8 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. --- a/qga/commands-posix.c
  12. +++ b/qga/commands-posix.c
  13. @@ -84,6 +84,7 @@ static void ga_wait_child(pid_t pid, int
  14. void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
  15. {
  16. const char *shutdown_flag;
  17. + const char *fallback_cmd = NULL;
  18. Error *local_err = NULL;
  19. pid_t pid;
  20. int status;
  21. @@ -91,10 +92,13 @@ void qmp_guest_shutdown(bool has_mode, c
  22. slog("guest-shutdown called, mode: %s", mode);
  23. if (!has_mode || strcmp(mode, "powerdown") == 0) {
  24. shutdown_flag = "-P";
  25. + fallback_cmd = "/sbin/poweroff";
  26. } else if (strcmp(mode, "halt") == 0) {
  27. shutdown_flag = "-H";
  28. + fallback_cmd = "/sbin/halt";
  29. } else if (strcmp(mode, "reboot") == 0) {
  30. shutdown_flag = "-r";
  31. + fallback_cmd = "/sbin/reboot";
  32. } else {
  33. error_setg(errp,
  34. "mode is invalid (valid values are: halt|powerdown|reboot");
  35. @@ -111,6 +115,7 @@ void qmp_guest_shutdown(bool has_mode, c
  36. execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",
  37. "hypervisor initiated shutdown", (char *)NULL, environ);
  38. + execle(fallback_cmd, fallback_cmd, (char*)NULL, environ);
  39. _exit(EXIT_FAILURE);
  40. } else if (pid < 0) {
  41. error_setg_errno(errp, errno, "failed to create child process");