From: Konstantin Kostiuk <kkostiuk@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PULL 3/9] qga/commands-posix: qmp_guest_shutdown: use ga_run_command helper
Date: Wed, 1 May 2024 10:43:34 +0300 [thread overview]
Message-ID: <20240501074340.19641-4-kkostiuk@redhat.com> (raw)
In-Reply-To: <20240501074340.19641-1-kkostiuk@redhat.com>
From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Also remove the G_GNUC_UNUSED attribute added in the previous commit from
the helper.
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Link: https://lore.kernel.org/r/20240320161648.158226-4-andrey.drobyshev@virtuozzo.com
Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
---
qga/commands-posix.c | 39 ++++++---------------------------------
1 file changed, 6 insertions(+), 33 deletions(-)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 9b1bdf194c..cb9eed9a0b 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -108,7 +108,6 @@ static ssize_t ga_pipe_read_str(int fd[2], char **str)
* sending string to stdin and taking error message from
* stdout/err.
*/
-G_GNUC_UNUSED
static int ga_run_command(const char *argv[], const char *in_str,
const char *action, Error **errp)
{
@@ -230,8 +229,6 @@ void qmp_guest_shutdown(const char *mode, Error **errp)
{
const char *shutdown_flag;
Error *local_err = NULL;
- pid_t pid;
- int status;
#ifdef CONFIG_SOLARIS
const char *powerdown_flag = "-i5";
@@ -260,46 +257,22 @@ void qmp_guest_shutdown(const char *mode, Error **errp)
return;
}
- pid = fork();
- if (pid == 0) {
- /* child, start the shutdown */
- setsid();
- reopen_fd_to_null(0);
- reopen_fd_to_null(1);
- reopen_fd_to_null(2);
-
+ const char *argv[] = {"/sbin/shutdown",
#ifdef CONFIG_SOLARIS
- execl("/sbin/shutdown", "shutdown", shutdown_flag, "-g0", "-y",
- "hypervisor initiated shutdown", (char *)NULL);
+ shutdown_flag, "-g0", "-y",
#elif defined(CONFIG_BSD)
- execl("/sbin/shutdown", "shutdown", shutdown_flag, "+0",
- "hypervisor initiated shutdown", (char *)NULL);
+ shutdown_flag, "+0",
#else
- execl("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",
- "hypervisor initiated shutdown", (char *)NULL);
+ "-h", shutdown_flag, "+0",
#endif
- _exit(EXIT_FAILURE);
- } else if (pid < 0) {
- error_setg_errno(errp, errno, "failed to create child process");
- return;
- }
+ "hypervisor initiated shutdown", (char *) NULL};
- ga_wait_child(pid, &status, &local_err);
+ ga_run_command(argv, NULL, "shutdown", &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
- if (!WIFEXITED(status)) {
- error_setg(errp, "child process has terminated abnormally");
- return;
- }
-
- if (WEXITSTATUS(status)) {
- error_setg(errp, "child process has failed to shutdown");
- return;
- }
-
/* succeeded */
}
--
2.44.0
next prev parent reply other threads:[~2024-05-01 7:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-01 7:43 [PULL 0/9] QGA misc changes for 2024-05-01 Konstantin Kostiuk
2024-05-01 7:43 ` [PULL 1/9] qga: guest-get-fsinfo: add optional 'total-bytes-privileged' field Konstantin Kostiuk
2024-05-01 7:43 ` [PULL 2/9] qga: introduce ga_run_command() helper for guest cmd execution Konstantin Kostiuk
2024-05-01 7:43 ` Konstantin Kostiuk [this message]
2024-05-01 7:43 ` [PULL 4/9] qga/commands-posix: qmp_guest_set_time: use ga_run_command helper Konstantin Kostiuk
2024-05-01 7:43 ` [PULL 5/9] qga/commands-posix: execute_fsfreeze_hook: " Konstantin Kostiuk
2024-05-01 7:43 ` [PULL 6/9] qga/commands-posix: don't do fork()/exec() when suspending via sysfs Konstantin Kostiuk
2024-05-01 7:43 ` [PULL 7/9] qga/commands-posix: qmp_guest_set_user_password: use ga_run_command helper Konstantin Kostiuk
2024-05-03 6:45 ` Thomas Huth
2024-05-01 7:43 ` [PULL 8/9] qga: Refactor common SSH functions Konstantin Kostiuk
2024-05-01 7:43 ` [PULL 9/9] qga: Implement SSH commands for Windows Konstantin Kostiuk
2024-05-01 22:15 ` [PULL 0/9] QGA misc changes for 2024-05-01 Richard Henderson
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=20240501074340.19641-4-kkostiuk@redhat.com \
--to=kkostiuk@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).