From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1D256C433EF for ; Wed, 9 Mar 2022 14:17:53 +0000 (UTC) Received: from localhost ([::1]:52048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRx8S-0005PW-Qo for qemu-devel@archiver.kernel.org; Wed, 09 Mar 2022 09:17:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRx76-0004jJ-VW for qemu-devel@nongnu.org; Wed, 09 Mar 2022 09:16:29 -0500 Received: from [2a00:1450:4864:20::436] (port=44798 helo=mail-wr1-x436.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nRx72-0004ZH-H8 for qemu-devel@nongnu.org; Wed, 09 Mar 2022 09:16:28 -0500 Received: by mail-wr1-x436.google.com with SMTP id u1so3249230wrg.11 for ; Wed, 09 Mar 2022 06:16:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eu5q+IF72Dc8i/IzKe8uegFtihYgdmrQT0qWkEpH/b0=; b=VEWhh1vGOU4x6V1UACVsU18z/ifU4DuXU/nlRJEzeSmBrqKIpfGN1bhyTBeBxjVumt /58wayZvjX+rb/drPYb3qH7U3oGtXhttiCbJRRflCup/+eqocQHIhCn4s3ITa7MtQ4QE OcXIjf07GM1C3IPiQJccsFTUMtkh+Dn0049A7C+gKF3Hv4DTvYW5D4J8qWW3VlVPxPBw UogTPRQUnMk78wZwxtDf4ibb4sLUqAsoIL+kgx/4JLh466sIOSPyToK9WOuPZgF5ioC2 eU1vmfP7Wc+XuqAEkUgmHSVi8XOj4eyB+NchEbhTDvYpzP40ggMmcbGwl6UOuGt0eeZh 1SBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eu5q+IF72Dc8i/IzKe8uegFtihYgdmrQT0qWkEpH/b0=; b=Y1gLzKFYpYe8wYX572ALLDOhne2lr2GrmY8dDx9PRt9ylsKhr8XwUYyBgwDsmjTjph fwtlTOgkV1u3yriER6GA68/CpNxk/BF9BiqsMK0a+AFm4WO850Xzh6XTY1TH+2VoA5Tk wCkDv1Yk1rWoQ4FBDHIDdWuULtjs0zjuiw1cHJOPY3FB4Xzlysn60FF8aafd6f9vVoq3 3LSE6DGP9bP5/uFRzLsAWSqShiJJLQdphszqdcOeIo7Bf2bh99B5JEZNjJYganj2Y7CJ hTfDV1sXTxyD1ecxW7Q3PgCidJDDiybqYLlROnhJ/rjKLyPk8Kb/e1a/udCT21mafcG8 zcHg== X-Gm-Message-State: AOAM532Hfdn5y/Ei4XOtNDfK5AwEv0fDp3Lk807iUAfDpMiyDIvjJqnL Km0/kRm7VOmbs3ZBql7jW6oRqlJ9HmtJ/vGvBkk= X-Google-Smtp-Source: ABdhPJyEchgLpyYCOqfPvLs3Xpa+y4DgyGDTsgprDiCKBH94TnawvY+MUtGJfbQdEn50T4VJlkEXir+UmhQwwaHY4ME= X-Received: by 2002:a5d:4cd1:0:b0:1f0:24d5:7c37 with SMTP id c17-20020a5d4cd1000000b001f024d57c37mr16302355wrt.421.1646835383073; Wed, 09 Mar 2022 06:16:23 -0800 (PST) MIME-Version: 1.0 References: <1640199934-455149-1-git-send-email-steven.sistare@oracle.com> <1640199934-455149-13-git-send-email-steven.sistare@oracle.com> In-Reply-To: <1640199934-455149-13-git-send-email-steven.sistare@oracle.com> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Wed, 9 Mar 2022 18:16:10 +0400 Message-ID: Subject: Re: [PATCH V7 12/29] vl: helper to request re-exec To: Steve Sistare Content-Type: multipart/alternative; boundary="00000000000003016e05d9c9bee1" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::436 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=marcandre.lureau@gmail.com; helo=mail-wr1-x436.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Zeng , Juan Quintela , Eric Blake , "Michael S. Tsirkin" , QEMU , "Dr. David Alan Gilbert" , Zheng Chuan , Alex Williamson , Stefan Hajnoczi , Paolo Bonzini , "Daniel P. Berrange" , =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= , =?UTF-8?B?QWxleCBCZW5uw6ll?= , Markus Armbruster Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --00000000000003016e05d9c9bee1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Dec 22, 2021 at 11:52 PM Steve Sistare wrote: > Add a qemu_system_exec_request() hook that causes the main loop to exit a= nd > re-exec qemu using the specified arguments. > > Signed-off-by: Steve Sistare > --- > include/sysemu/runstate.h | 1 + > softmmu/runstate.c | 21 +++++++++++++++++++++ > 2 files changed, 22 insertions(+) > > diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h > index b655c7b..198211b 100644 > --- a/include/sysemu/runstate.h > +++ b/include/sysemu/runstate.h > @@ -57,6 +57,7 @@ void qemu_system_wakeup_enable(WakeupReason reason, boo= l > enabled); > void qemu_register_wakeup_notifier(Notifier *notifier); > void qemu_register_wakeup_support(void); > void qemu_system_shutdown_request(ShutdownCause reason); > +void qemu_system_exec_request(const strList *args); > void qemu_system_powerdown_request(void); > void qemu_register_powerdown_notifier(Notifier *notifier); > void qemu_register_shutdown_notifier(Notifier *notifier); > diff --git a/softmmu/runstate.c b/softmmu/runstate.c > index 3d344c9..309a4bf 100644 > --- a/softmmu/runstate.c > +++ b/softmmu/runstate.c > @@ -38,6 +38,7 @@ > #include "monitor/monitor.h" > #include "net/net.h" > #include "net/vhost_net.h" > +#include "qapi/util.h" > #include "qapi/error.h" > #include "qapi/qapi-commands-run-state.h" > #include "qapi/qapi-events-run-state.h" > @@ -355,6 +356,7 @@ static NotifierList wakeup_notifiers =3D > static NotifierList shutdown_notifiers =3D > NOTIFIER_LIST_INITIALIZER(shutdown_notifiers); > static uint32_t wakeup_reason_mask =3D ~(1 << QEMU_WAKEUP_REASON_NONE); > +static char **exec_argv; > > ShutdownCause qemu_shutdown_requested_get(void) > { > @@ -371,6 +373,11 @@ static int qemu_shutdown_requested(void) > return qatomic_xchg(&shutdown_requested, SHUTDOWN_CAUSE_NONE); > } > > +static int qemu_exec_requested(void) > +{ > + return exec_argv !=3D NULL; > +} > + > static void qemu_kill_report(void) > { > if (!qtest_driver() && shutdown_signal) { > @@ -641,6 +648,13 @@ void qemu_system_shutdown_request(ShutdownCause > reason) > qemu_notify_event(); > } > > +void qemu_system_exec_request(const strList *args) > +{ > + exec_argv =3D strv_from_strList(args); > I would rather make it take a GStrv, since that's what it actually uses. I would also check if argv[0] is set (or document the expected behaviour). > + shutdown_requested =3D 1; > + qemu_notify_event(); > +} > + > static void qemu_system_powerdown(void) > { > qapi_event_send_powerdown(); > @@ -689,6 +703,13 @@ static bool main_loop_should_exit(void) > } > request =3D qemu_shutdown_requested(); > if (request) { > + > + if (qemu_exec_requested()) { > + execvp(exec_argv[0], exec_argv); > + error_report("execvp %s failed: %s", exec_argv[0], > strerror(errno)); > + g_strfreev(exec_argv); > + exec_argv =3D NULL; > + } > qemu_kill_report(); > qemu_system_shutdown(request); > if (shutdown_action =3D=3D SHUTDOWN_ACTION_PAUSE) { > -- > 1.8.3.1 > > > --=20 Marc-Andr=C3=A9 Lureau --00000000000003016e05d9c9bee1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Dec 22, 2021 at 11:52 PM Stev= e Sistare <steven.sistare@o= racle.com> wrote:
Add a qemu_system_exec_request() hook that causes the main loop = to exit and
re-exec qemu using the specified arguments.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
=C2=A0include/sysemu/runstate.h |=C2=A0 1 +
=C2=A0softmmu/runstate.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 | 21 ++++++++++++++++++= +++
=C2=A02 files changed, 22 insertions(+)

diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h
index b655c7b..198211b 100644
--- a/include/sysemu/runstate.h
+++ b/include/sysemu/runstate.h
@@ -57,6 +57,7 @@ void qemu_system_wakeup_enable(WakeupReason reason, bool = enabled);
=C2=A0void qemu_register_wakeup_notifier(Notifier *notifier);
=C2=A0void qemu_register_wakeup_support(void);
=C2=A0void qemu_system_shutdown_request(ShutdownCause reason);
+void qemu_system_exec_request(const strList *args);
=C2=A0void qemu_system_powerdown_request(void);
=C2=A0void qemu_register_powerdown_notifier(Notifier *notifier);
=C2=A0void qemu_register_shutdown_notifier(Notifier *notifier);
diff --git a/softmmu/runstate.c b/softmmu/runstate.c
index 3d344c9..309a4bf 100644
--- a/softmmu/runstate.c
+++ b/softmmu/runstate.c
@@ -38,6 +38,7 @@
=C2=A0#include "monitor/monitor.h"
=C2=A0#include "net/net.h"
=C2=A0#include "net/vhost_net.h"
+#include "qapi/util.h"
=C2=A0#include "qapi/error.h"
=C2=A0#include "qapi/qapi-commands-run-state.h"
=C2=A0#include "qapi/qapi-events-run-state.h"
@@ -355,6 +356,7 @@ static NotifierList wakeup_notifiers =3D
=C2=A0static NotifierList shutdown_notifiers =3D
=C2=A0 =C2=A0 =C2=A0NOTIFIER_LIST_INITIALIZER(shutdown_notifiers);
=C2=A0static uint32_t wakeup_reason_mask =3D ~(1 << QEMU_WAKEUP_REASO= N_NONE);
+static char **exec_argv;

=C2=A0ShutdownCause qemu_shutdown_requested_get(void)
=C2=A0{
@@ -371,6 +373,11 @@ static int qemu_shutdown_requested(void)
=C2=A0 =C2=A0 =C2=A0return qatomic_xchg(&shutdown_requested, SHUTDOWN_C= AUSE_NONE);
=C2=A0}

+static int qemu_exec_requested(void)
+{
+=C2=A0 =C2=A0 return exec_argv !=3D NULL;
+}
+
=C2=A0static void qemu_kill_report(void)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0if (!qtest_driver() && shutdown_signal) {
@@ -641,6 +648,13 @@ void qemu_system_shutdown_request(ShutdownCause reason= )
=C2=A0 =C2=A0 =C2=A0qemu_notify_event();
=C2=A0}

+void qemu_system_exec_request(const strList *args)
+{
+=C2=A0 =C2=A0 exec_argv =3D strv_from_strList(args);
=
I would rather make it take a GStrv, since that's what i= t actually uses.

I would also check if argv[0] is = set (or document the expected behaviour).
=C2=A0
+=C2=A0 =C2=A0 shutdown_requested =3D 1;
+=C2=A0 =C2=A0 qemu_notify_event();
+}
+
=C2=A0static void qemu_system_powerdown(void)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0qapi_event_send_powerdown();
@@ -689,6 +703,13 @@ static bool main_loop_should_exit(void)
=C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0request =3D qemu_shutdown_requested();
=C2=A0 =C2=A0 =C2=A0if (request) {
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (qemu_exec_requested()) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 execvp(exec_argv[0], exec_argv);=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_report("execvp %s fai= led: %s", exec_argv[0], strerror(errno));
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 g_strfreev(exec_argv);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 exec_argv =3D NULL;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_kill_report();
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_system_shutdown(request);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (shutdown_action =3D=3D SHUTDOWN_ACTIO= N_PAUSE) {
--
1.8.3.1




--
Marc-Andr=C3=A9 Lureau
--00000000000003016e05d9c9bee1--