From: "Michael S. Tsirkin" <mst@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: qemu-devel@nongnu.org, "Eric Blake" <eblake@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Markus Armbruster" <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 2/1] libqtest: add more exit status checks
Date: Thu, 24 May 2018 21:15:49 +0300 [thread overview]
Message-ID: <20180524205847-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <02e22133-8358-99c6-784e-52ac39b7b273@redhat.com>
On Thu, May 24, 2018 at 07:58:06PM +0200, Thomas Huth wrote:
> On 24.05.2018 19:33, Michael S. Tsirkin wrote:
> > On Thu, May 24, 2018 at 07:26:16PM +0200, Thomas Huth wrote:
> >> On 24.05.2018 18:11, Michael S. Tsirkin wrote:
> >>> Add more checks on how did QEMU exit.
> >>>
> >>> Legal ways to exit right now:
> >>> - exit(0) or return from main
> >>> - kill(SIGTERM) - sent by testing infrastructure
> >>>
> >>> Anything else is illegal.
> >> [...]
> >>> - if (pid == s->qemu_pid && WIFSIGNALED(wstatus)) {
> >>> + /* waitpid returns child PID on success */
> >>> + assert(pid == s->qemu_pid);
> >>> +
> >>> + /* If exited on signal - check the reason: core dump is never OK */
> >>> + if (WIFSIGNALED(wstatus)) {
> >>> assert(!WCOREDUMP(wstatus));
> >>> }
> >>> + /* If exited normally - check exit status */
> >>> + if (WIFEXITED(wstatus)) {
> >>> + assert(!WEXITSTATUS(wstatus));
> >>> + }
> >>> + /* Valid ways to exit: right now only return from main or exit */
> >>> + assert(WIFEXITED(wstatus));
> >>> }
> >>> }
> >>
> >> It's strange that you always get WIFEXITED(wstatus) == true here, even
> >> if QEMU has been terminated by SIGTERM? I assume that's due to the fact
> >> that QEMU intercepts SIGTERM and terminates via exit() instead?
> >
> > Right now, yes. This can of course change, so it's not
> > a good idea hard-coding this assumption to deep
> > in the code, imho.
> >
> >> So I
> >> think you could simply replace the last three asserts with:
> >>
> >> assert(WIFEXITED(wstatus) && !WEXITSTATUS(wstatus));
> >>
> >> Thomas
> >
> > I could but they would be harder to debug.
> >
> > If I see
> > "assertion failed: !WCOREDUMP(wstatus)"
> > then that is very readable.
> >
> > If I just see
> > "assertion failed: WIFEXITED(wstatus) && !WEXITSTATUS(wstatus)"
> > then I just know something went wrong.
>
> Then simply use:
>
> assert(WIFEXITED(wstatus));
> assert(!WEXITSTATUS(wstatus));
>
> If QEMU exited due to a signal, you'll see the first assert, and if it
> returned a non-zero exit code, you'll see the second assert. That's all
> you really need to know here, I think.
>
> I don't think that you gain anything by checking WCOREDUMP() here.
> And
> according to the man-page of waitpid:
>
> This macro is not specified in POSIX.1-2001 and is not
> available on some UNIX implementations (e.g., AIX, SunOS).
> Only use this enclosed in #ifdef WCOREDUMP ... #endif.
>
> So if you insist on using that macro, you might need to add some #ifdef
> code around it, I think.
>
> Thomas
I think we are better off defining it if it's not defined.
Will post an osdep patch.
--
MST
next prev parent reply other threads:[~2018-05-24 18:15 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-24 14:30 [Qemu-devel] [PATCH] libqtest: fail if child coredumps Michael S. Tsirkin
2018-05-24 14:45 ` Thomas Huth
2018-05-24 15:00 ` Michael S. Tsirkin
2018-05-24 15:04 ` Marc-André Lureau
2018-05-24 15:18 ` Michael S. Tsirkin
2018-05-24 15:46 ` Thomas Huth
2018-05-24 15:51 ` Michael S. Tsirkin
2018-05-24 16:01 ` Thomas Huth
2018-05-24 15:17 ` [Qemu-devel] [PATCH 2/1] libqtest: add more exit status checks Michael S. Tsirkin
2018-05-24 15:24 ` Eric Blake
2018-05-24 15:38 ` [Qemu-devel] [PATCH v2 " Michael S. Tsirkin
2018-05-24 15:52 ` Eric Blake
2018-05-24 16:00 ` Eric Blake
2018-05-24 16:01 ` Michael S. Tsirkin
2018-05-24 18:16 ` Eric Blake
2018-05-24 18:20 ` Michael S. Tsirkin
2018-05-25 5:40 ` Markus Armbruster
2018-05-24 16:00 ` Michael S. Tsirkin
2018-05-24 15:54 ` Thomas Huth
2018-05-24 16:01 ` Michael S. Tsirkin
2018-05-24 16:11 ` [Qemu-devel] [PATCH v3 " Michael S. Tsirkin
2018-05-24 17:26 ` Thomas Huth
2018-05-24 17:33 ` Michael S. Tsirkin
2018-05-24 17:58 ` Thomas Huth
2018-05-24 18:15 ` Michael S. Tsirkin [this message]
2018-05-24 15:02 ` [Qemu-devel] [PATCH] libqtest: fail if child coredumps Peter Maydell
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=20180524205847-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=f4bug@amsat.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@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 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.