From: Max Reitz <mreitz@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Fam Zheng" <famz@redhat.com>,
"Michael Müller" <mimu@linux.vnet.ibm.com>,
"Mao Chuan Li" <maochuan@linux.vnet.ibm.com>,
qemu-devel@nongnu.org, "Stefan Hajnoczi" <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/3] qemu-io: Let -c abort raise any signal
Date: Tue, 25 Nov 2014 14:31:40 +0100 [thread overview]
Message-ID: <547484BC.4080500@redhat.com> (raw)
In-Reply-To: <87tx1nfmea.fsf@blackfin.pond.sub.org>
On 2014-11-25 at 14:19, Markus Armbruster wrote:
> Max Reitz <mreitz@redhat.com> writes:
>
>> abort() has the sometimes undesirable side-effect of generating a core
>> dump. If that is not needed, SIGKILL has the same effect of abruptly
>> crash qemu; without a core dump.
>>
>> Therefore, this patch allows to use the qemu-io abort command to raise
>> any signal.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>> qemu-io-cmds.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
>> 1 file changed, 56 insertions(+), 3 deletions(-)
>>
>> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
>> index d94fb1e..5d39cf4 100644
>> --- a/qemu-io-cmds.c
>> +++ b/qemu-io-cmds.c
>> @@ -2036,18 +2036,71 @@ static const cmdinfo_t wait_break_cmd = {
>> .oneline = "waits for the suspension of a request",
>> };
>>
>> -static int abort_f(BlockDriverState *bs, int argc, char **argv)
>> +
>> +static void abort_help(void)
>> {
>> - abort();
>> + printf(
>> +"\n"
>> +" simulates a program crash\n"
>> +"\n"
>> +" Invokes abort(), or raise(signal) if a signal number is specified.\n"
>> +" -S, -- number of the signal to raise()\n"
>> +"\n");
>> }
>>
>> +static int abort_f(BlockDriverState *bs, int argc, char **argv);
>> +
>> static const cmdinfo_t abort_cmd = {
>> .name = "abort",
>> .cfunc = abort_f,
>> + .argmin = 0,
>> + .argmax = 2,
>> .flags = CMD_NOFILE_OK,
>> - .oneline = "simulate a program crash using abort(3)",
>> + .args = "[-S signal]",
>> + .oneline = "simulate a program crash",
>> + .help = abort_help,
>> };
> This overloads the abort command with a kill command.
abort() does a bit more than raise(SIGABRT), but all that it does more
is basically "Make sure that raise(SIGABRT) actually works". So abort()
basically is already a "kill me" command (kill -SIGABRT). I think
overloading it is fine, but I wouldn't have that much of a problem to
introduce another command, but it was just simpler this way.
> Do we really need a way to send arbitrary signals?
Why not? I'm implementing the functionality here for a single signal,
it's not that hard to do it for arbitrary signals, so I did it.
> If yes, shouldn't we
> call it "kill" rather than "abort"?
I'd call it "raise" (for obious reasons), but will not rename "abort". I
can create a separate "raise" or "kill" command, though, obviously. But
as "abort" is basically a "raise 6" (or "abort -S 6" with this version
of the series), I think it's completely fine to overload "abort".
> I suspect fooling around with signals isn't necessary, and a simple
> exit(1) would do.
No, because that would execute the atexit() functions. I don't know
whether such are used in qemu, but if we want to simulate a crash,
exit() is not the right function to do that.
>>
>> +static int abort_f(BlockDriverState *bs, int argc, char **argv)
>> +{
>> + int c;
>> + int sig = -1;
>> +
>> + while ((c = getopt(argc, argv, "S:")) != EOF) {
>> + switch (c) {
>> + case 'S':
>> + sig = cvtnum(optarg);
>> + if (sig < 0) {
>> + printf("non-numeric signal number argument -- %s\n", optarg);
>> + return 0;
>> + }
>> + break;
>> +
>> + default:
>> + return qemuio_command_usage(&abort_cmd);
>> + }
>> + }
>> +
>> + if (optind != argc) {
>> + return qemuio_command_usage(&abort_cmd);
>> + }
>> +
>> + if (sig < 0) {
>> + abort();
>> + } else {
>> + /* While abort() does flush all open streams, using raise() to kill this
>> + * process does not necessarily. At least stdout and stderr (although
>> + * the latter should be non-buffered anyway) should be flushed, though.
>> + */
>> + fflush(stdout);
>> + fflush(stderr);
> Without -S, we flush all streams. With -S, we flush only stdout and
> stderr. The inconsistency is ugly. Could be avoided with fcloseall(),
> except it's a GNU extension. Or drop the non-signal path entirely, and
> raise(SIGABRT) instead of abort().
Except abort() does a bit more.
Because I think not flushing any stream except for stdout and stderr is
closer to a real crash, I think making sig = 6 the default and thus
dropping the non-signal path is the better option.
Max
next prev parent reply other threads:[~2014-11-25 13:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-25 10:09 [Qemu-devel] [PATCH 0/3] iotests: Fix test 039 Max Reitz
2014-11-25 10:09 ` [Qemu-devel] [PATCH 1/3] qemu-io: Let -c abort raise any signal Max Reitz
2014-11-25 13:19 ` Markus Armbruster
2014-11-25 13:31 ` Max Reitz [this message]
2014-11-25 10:09 ` [Qemu-devel] [PATCH 2/3] iotests: Filter for "Killed" in qemu-io output Max Reitz
2014-11-25 13:05 ` Markus Armbruster
2014-11-25 13:06 ` Max Reitz
2014-11-25 10:09 ` [Qemu-devel] [PATCH 3/3] iotests: Fix test 039 Max Reitz
2014-11-25 12:21 ` [Qemu-devel] [PATCH 0/3] " Markus Armbruster
2014-11-25 12:29 ` Max Reitz
2014-11-25 13:20 ` Markus Armbruster
2014-11-25 13:22 ` Max Reitz
2014-11-25 13:48 ` Markus Armbruster
2014-11-25 13:50 ` Max Reitz
2014-11-25 14:04 ` Markus Armbruster
2014-11-25 16:53 ` Michael Mueller
2014-11-25 16:48 ` Michael Mueller
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=547484BC.4080500@redhat.com \
--to=mreitz@redhat.com \
--cc=armbru@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=maochuan@linux.vnet.ibm.com \
--cc=mimu@linux.vnet.ibm.com \
--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 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.