From: Thomas Huth <thuth@redhat.com>
To: Dominik Csapak <d.csapak@proxmox.com>, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/1] vl.c: call optional script when exiting
Date: Thu, 4 Oct 2018 10:11:58 +0200 [thread overview]
Message-ID: <27e32199-a81f-f693-351e-6c5dda5bf308@redhat.com> (raw)
In-Reply-To: <20181003091344.24496-2-d.csapak@proxmox.com>
On 2018-10-03 11:13, Dominik Csapak wrote:
> some users might want to call a script when qemu exits, without listening
> to a qmp monitor for events when running with --daemonize
>
> this can be used for things like external cleanups
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> qemu-options.hx | 18 ++++++++++++++++++
> vl.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 63 insertions(+)
[...]
> @@ -4577,5 +4586,41 @@ int main(int argc, char **argv, char **envp)
> migration_object_finalize();
> /* TODO: unref root container, check all devices are ok */
>
> + if (exit_script) {
> + int pid, status;
> + char *args[5];
> +
> + /* try to launch network script */
> + pid = fork();
> + if (pid < 0) {
> + error_report("could not launch exit script '%s'", exit_script);
> + exit(1);
> + }
> + if (pid == 0) {
> + int open_max = sysconf(_SC_OPEN_MAX), i;
> +
> + for (i = 3; i < open_max; i++) {
> + close(i);
> + }
> + args[0] = (char *)exit_script;
> + args[1] = g_strdup_printf("%d", shutdown_reason);
> + args[2] = g_strdup_printf("%d", shutdown_was_reset);
> + args[3] = qemu_get_vm_name();
> + args[4] = NULL;
> + execv(exit_script, args);
> + _exit(1);
> + } else {
> + while (waitpid(pid, &status, 0) != pid) {
> + /* loop */
> + }
> +
> + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
> + error_report("exit script '%s' failed with status %d",
> + exit_script, status);
> + exit(1);
> + }
> + }
> + }
Our main() function is already huge, so please put this into a separate
function instead (or even better, refactor the launch_script function as
you've mentioned it in the cover letter).
Thanks,
Thomas
next prev parent reply other threads:[~2018-10-04 8:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-03 9:13 [Qemu-devel] [PATCH 0/1] add exit-script option to qemu Dominik Csapak
2018-10-03 9:13 ` [Qemu-devel] [PATCH 1/1] vl.c: call optional script when exiting Dominik Csapak
2018-10-03 10:15 ` Philippe Mathieu-Daudé
2018-10-04 8:11 ` Thomas Huth [this message]
2018-10-03 10:15 ` [Qemu-devel] [PATCH 0/1] add exit-script option to qemu Philippe Mathieu-Daudé
2018-10-04 13:51 ` Daniel P. Berrangé
2018-10-05 6:56 ` Dominik Csapak
2018-10-05 8:38 ` Daniel P. Berrangé
2018-10-05 12:57 ` Dominik Csapak
2018-10-05 13:02 ` Daniel P. Berrangé
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=27e32199-a81f-f693-351e-6c5dda5bf308@redhat.com \
--to=thuth@redhat.com \
--cc=d.csapak@proxmox.com \
--cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.