Skip to contentSkip to conversation

iotests: Fix test 039

PATCH Superseded Max Reitz 5 participants 15 messages Dec 4, 2014 – Dec 5, 2014

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

v2 cover iotests: Fix test 039

Test 039 used to fail because qemu-io -c abort may generate core dumps even with ulimit -c 0 (and the output then contains "(core dumped)"). Fix this by adding a new qemu-io command "sigraise" which invokes raise(). Using this command to raise SIGKILL for example does not result in a core dump, but it still badly crashes qemu-io (as desired).

I am sending this series because we need all tests to work before adding the check-block target to "make check" (which we will hopefully do soon).

v2:
- Rewrote patch 1: Overloading "abort" may be somehow technically justifyable, but there is no point in grasping at straws when it is much easier to just introduce a new command. Therefore, in this version, "abort" is no longer overloaded and instead a new command, "sigraise", is added (I thought long and hard about that name; I thought "raise" to sound too unspecific, so this is what I came up with) [Markus]
- Patch 2: Fixed commit message (s/if it is aborted/when it is killed/) [Markus]
- Patch 3: %s/abort -S 9/sigraise 9/

git-backport-diff against v1:

Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively

001/3:[down] 'qemu-io: Add sigraise command'

       ^^^^ wrong, should be:
      [0081] [FC]

002/3:[----] [--] 'iotests: Filter for "Killed" in qemu-io output' 003/3:[0006] [FC] 'iotests: Fix test 039'

Max Reitz (3):
qemu-io: Add sigraise command
iotests: Filter for "Killed" in qemu-io output
iotests: Fix test 039

 qemu-io-cmds.c                   | 46 ++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/039           | 12 ++++++-----
 tests/qemu-iotests/039.out       |  6 +++---
 tests/qemu-iotests/common.filter |  2 +-
 4 files changed, 57 insertions(+), 9 deletions(-)
Signature · 1 line
1.9.3
author
#1 lore raw

PATCH v2 1/3 qemu-io: Add sigraise command

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.

Thus, -c abort is not always useful to simulate a qemu-io crash; therefore, this patch adds a new sigraise command which allows to raise any Unix signal.

---
 qemu-io-cmds.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
qemu-io-cmds.c +46 -0
index d94fb1e..942b694 100644
@@ -2048,6 +2048,51 @@ static const cmdinfo_t abort_cmd = {
        .oneline        = "simulate a program crash using abort(3)",
 };
 
+static void sigraise_help(void)
+{
+    printf(
+"\n"
+" raises the given Unix signal\n"
+"\n"
+" Example:\n"
+" 'sigraise 9' - raises SIGKILL\n"
+"\n"
+" Invokes raise(signal), where \"signal\" is the mandatory integer argument\n"
+" given to sigraise.\n"
+"\n");
+}
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv);
+
+static const cmdinfo_t sigraise_cmd = {
+    .name       = "sigraise",
+    .cfunc      = sigraise_f,
+    .argmin     = 1,
+    .argmax     = 1,
+    .flags      = CMD_NOFILE_OK,
+    .args       = "signal",
+    .oneline    = "raises a Unix signal",
+    .help       = sigraise_help,
+};
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv)
+{
+    int sig = cvtnum(argv[1]);
+    if (sig < 0) {
+        printf("non-numeric signal number argument -- %s\n", argv[1]);
+        return 0;
+    }
+
+    /* Using raise() to kill this process does not necessarily flush all open
+     * streams. At least stdout and stderr (although the latter should be
+     * non-buffered anyway) should be flushed, though. */
+    fflush(stdout);
+    fflush(stderr);
+
+    raise(sig);
+    return 0;
+}
+
 static void sleep_cb(void *opaque)
 {
     bool *expired = opaque;
@@ -2202,4 +2247,5 @@ static void __attribute((constructor)) init_qemuio_commands(void)
     qemuio_add_command(&wait_break_cmd);
     qemuio_add_command(&abort_cmd);
     qemuio_add_command(&sleep_cmd);
+    qemuio_add_command(&sigraise_cmd);
 }
Signature · 1 line
1.9.3
Reviewed-by on v2 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] qemu-io: Add sigraise command

Quoted 79 lines · Max Reitz

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.

Thus, -c abort is not always useful to simulate a qemu-io crash; therefore, this patch adds a new sigraise command which allows to raise any Unix signal.

---
 qemu-io-cmds.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
qemu-io-cmds.c +46 -0
index d94fb1e..942b694 100644
@@ -2048,6 +2048,51 @@ static const cmdinfo_t abort_cmd = {
        .oneline        = "simulate a program crash using abort(3)",
 };
 
+static void sigraise_help(void)
+{
+    printf(
+"\n"
+" raises the given Unix signal\n"
+"\n"
+" Example:\n"
+" 'sigraise 9' - raises SIGKILL\n"
+"\n"
+" Invokes raise(signal), where \"signal\" is the mandatory integer argument\n"
+" given to sigraise.\n"
+"\n");
+}
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv);
+
+static const cmdinfo_t sigraise_cmd = {
+    .name       = "sigraise",
+    .cfunc      = sigraise_f,
+    .argmin     = 1,
+    .argmax     = 1,
+    .flags      = CMD_NOFILE_OK,
+    .args       = "signal",
+    .oneline    = "raises a Unix signal",
+    .help       = sigraise_help,
+};
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv)
+{
+    int sig = cvtnum(argv[1]);
+    if (sig < 0) {
+        printf("non-numeric signal number argument -- %s\n", argv[1]);
+        return 0;
+    }
+
+    /* Using raise() to kill this process does not necessarily flush all open
+     * streams. At least stdout and stderr (although the latter should be
+     * non-buffered anyway) should be flushed, though. */
+    fflush(stdout);
+    fflush(stderr);
+
+    raise(sig);
+    return 0;
+}
+
 static void sleep_cb(void *opaque)
 {
     bool *expired = opaque;
@@ -2202,4 +2247,5 @@ static void __attribute((constructor)) init_qemuio_commands(void)
     qemuio_add_command(&wait_break_cmd);
     qemuio_add_command(&abort_cmd);
     qemuio_add_command(&sleep_cmd);
+    qemuio_add_command(&sigraise_cmd);
 }
Signature · 1 line
1.9.3
#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] qemu-io: Add sigraise command

In reply to Max Reitz
Quoted 7 lines · Max Reitz

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.

Thus, -c abort is not always useful to simulate a qemu-io crash; therefore, this patch adds a new sigraise command which allows to raise any Unix signal.

Nitpick: signals are ISO C, not just UNIX.

Quoted 12 lines
---
 qemu-io-cmds.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
qemu-io-cmds.c +0 -0
index d94fb1e..942b694 100644
@@ -2048,6 +2048,51 @@ static const cmdinfo_t abort_cmd = {
        .oneline        = "simulate a program crash using abort(3)",

qemu-io-cmds.c static const cmdinfo_t abort_cmd = { · line 2058

Quoted 10 lines
qemu-io-cmds.c +8 -0
 };
 
+static void sigraise_help(void)
+{
+    printf(
+"\n"
+" raises the given Unix signal\n"
+"\n"
+" Example:\n"
+" 'sigraise 9' - raises SIGKILL\n"

Assumes SIGKILL is encoded as 9, which is traditionally the case, but not actually mandated by POSIX.

You could avoid hardcoding 9 with

" 'sigraise %d' - raises SIGKILL\n"

with a SIGKILL as argument for %d.

But then you'd have to face the fact that SIGKILL is POSIX, not ISO C. The ISO C signals are SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM. Of these, SIGINT and SIGTERM don't dump core, in case you care.

Quoted 41 lines
qemu-io-cmds.c +37 -0
+"\n"
+" Invokes raise(signal), where \"signal\" is the mandatory integer argument\n"
+" given to sigraise.\n"
+"\n");
+}
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv);
+
+static const cmdinfo_t sigraise_cmd = {
+    .name       = "sigraise",
+    .cfunc      = sigraise_f,
+    .argmin     = 1,
+    .argmax     = 1,
+    .flags      = CMD_NOFILE_OK,
+    .args       = "signal",
+    .oneline    = "raises a Unix signal",
+    .help       = sigraise_help,
+};
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv)
+{
+    int sig = cvtnum(argv[1]);
+    if (sig < 0) {
+        printf("non-numeric signal number argument -- %s\n", argv[1]);
+        return 0;
+    }
+
+    /* Using raise() to kill this process does not necessarily flush all open
+     * streams. At least stdout and stderr (although the latter should be
+     * non-buffered anyway) should be flushed, though. */
+    fflush(stdout);
+    fflush(stderr);
+
+    raise(sig);
+    return 0;
+}
+
 static void sleep_cb(void *opaque)
 {
     bool *expired = opaque;

qemu-io-cmds.c static void __attribute((constructor)) init_qemuio_commands(void) · line 2251

Quoted 5 lines
qemu-io-cmds.c +1 -0
@@ -2202,4 +2247,5 @@ static void __attribute((constructor)) init_qemuio_commands(void)
     qemuio_add_command(&wait_break_cmd);
     qemuio_add_command(&abort_cmd);
     qemuio_add_command(&sleep_cmd);
+    qemuio_add_command(&sigraise_cmd);
 }

Looks good otherwise.

author
#4 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] qemu-io: Add sigraise command

Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Max Reitz

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.

Thus, -c abort is not always useful to simulate a qemu-io crash; therefore, this patch adds a new sigraise command which allows to raise any Unix signal.

Nitpick: signals are ISO C, not just UNIX.

Yes, but "Unix signal" is what the Wikipedia article is named, so... ;-)

Quoted 13 lines
Quoted 13 lines
---
  qemu-io-cmds.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 46 insertions(+)
qemu-io-cmds.c +0 -0
index d94fb1e..942b694 100644
@@ -2048,6 +2048,51 @@ static const cmdinfo_t abort_cmd = {
         .oneline        = "simulate a program crash using abort(3)",
  };
 
Quoted 10 lines

qemu-io-cmds.c static const cmdinfo_t abort_cmd = { · line 2058

Quoted 8 lines
qemu-io-cmds.c +8 -0
+static void sigraise_help(void)
+{
+    printf(
+"\n"
+" raises the given Unix signal\n"
+"\n"
+" Example:\n"
+" 'sigraise 9' - raises SIGKILL\n"

Assumes SIGKILL is encoded as 9, which is traditionally the case, but not actually mandated by POSIX.

Yes, I know. The best would be to parse the signal like kill(1) does, but that would have been extra difficult and probably not worth the effort.

Furthermore, I know there is a song called "kill dash nine", so I guessed it would be enough (at least it'll have to be enough for test 039, thanks to "_supported_os Linux").

Quoted 5 lines

You could avoid hardcoding 9 with

" 'sigraise %d' - raises SIGKILL\n"

with a SIGKILL as argument for %d.

Clever. Will do.

Quoted 3 lines

But then you'd have to face the fact that SIGKILL is POSIX, not ISO C. The ISO C signals are SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM. Of these, SIGINT and SIGTERM don't dump core, in case you care.

Good to know. I guess I'll just go with SIGKILL anyway, it's ubiquitous enough.

Quoted 39 lines
Quoted 39 lines
qemu-io-cmds.c +37 -0
+"\n"
+" Invokes raise(signal), where \"signal\" is the mandatory integer argument\n"
+" given to sigraise.\n"
+"\n");
+}
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv);
+
+static const cmdinfo_t sigraise_cmd = {
+    .name       = "sigraise",
+    .cfunc      = sigraise_f,
+    .argmin     = 1,
+    .argmax     = 1,
+    .flags      = CMD_NOFILE_OK,
+    .args       = "signal",
+    .oneline    = "raises a Unix signal",
+    .help       = sigraise_help,
+};
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv)
+{
+    int sig = cvtnum(argv[1]);
+    if (sig < 0) {
+        printf("non-numeric signal number argument -- %s\n", argv[1]);
+        return 0;
+    }
+
+    /* Using raise() to kill this process does not necessarily flush all open
+     * streams. At least stdout and stderr (although the latter should be
+     * non-buffered anyway) should be flushed, though. */
+    fflush(stdout);
+    fflush(stderr);
+
+    raise(sig);
+    return 0;
+}
+
  static void sleep_cb(void *opaque)
  {
Quoted 8 lines

qemu-io-cmds.c static void __attribute((constructor)) init_qemuio_commands(void) · line 2251

Quoted 7 lines
qemu-io-cmds.c +1 -0
      bool *expired = opaque;
@@ -2202,4 +2247,5 @@ static void __attribute((constructor)) init_qemuio_commands(void)
      qemuio_add_command(&wait_break_cmd);
      qemuio_add_command(&abort_cmd);
      qemuio_add_command(&sleep_cmd);
+    qemuio_add_command(&sigraise_cmd);
  }

Looks good otherwise.

Thanks :-)

Max

#5 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] qemu-io: Add sigraise command

Quoted 7 lines · Max Reitz
Quoted 6 lines · Markus Armbruster
Quoted 4 lines · Max Reitz

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.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Thus, -c abort is not always useful to simulate a qemu-io crash; therefore, this patch adds a new sigraise command which allows to raise any Unix signal.

Nitpick: signals are ISO C, not just UNIX.

Yes, but "Unix signal" is what the Wikipedia article is named, so... ;-)

If it's in Wikipedia, it must be right! Quick, file a bug against the C standard!

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
---
  qemu-io-cmds.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 46 insertions(+)
qemu-io-cmds.c +1 -0
index d94fb1e..942b694 100644
@@ -2048,6 +2048,51 @@ static const cmdinfo_t abort_cmd = {
         .oneline        = "simulate a program crash using abort(3)",
  };
  +static void sigraise_help(void)
+{
Quoted 8 lines

qemu-io-cmds.c static const cmdinfo_t abort_cmd = { · line 2058

Quoted 6 lines
qemu-io-cmds.c +6 -0
+    printf(
+"\n"
+" raises the given Unix signal\n"
+"\n"
+" Example:\n"
+" 'sigraise 9' - raises SIGKILL\n"

Assumes SIGKILL is encoded as 9, which is traditionally the case, but not actually mandated by POSIX.

Quoted 3 lines

Yes, I know. The best would be to parse the signal like kill(1) does, but that would have been extra difficult and probably not worth the effort.

Agree.

Quoted 3 lines

Furthermore, I know there is a song called "kill dash nine", so I guessed it would be enough (at least it'll have to be enough for test 039, thanks to "_supported_os Linux").

Bash can map signal names to numbers and back:

    $ kill -l 9
    KILL
    $ kill -l KILL
    9

Perhaps you can use that to avoid hardcoding.

Quoted 6 lines
Quoted 5 lines

You could avoid hardcoding 9 with

" 'sigraise %d' - raises SIGKILL\n"

with a SIGKILL as argument for %d.

Quoted 8 lines

Clever. Will do.

Quoted 3 lines

But then you'd have to face the fact that SIGKILL is POSIX, not ISO C. The ISO C signals are SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM. Of these, SIGINT and SIGTERM don't dump core, in case you care.

Good to know. I guess I'll just go with SIGKILL anyway, it's ubiquitous enough.

Might break the Windows compile.

Quoted 48 lines
Quoted 39 lines
Quoted 39 lines
qemu-io-cmds.c +37 -0
+"\n"
+" Invokes raise(signal), where \"signal\" is the mandatory integer argument\n"
+" given to sigraise.\n"
+"\n");
+}
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv);
+
+static const cmdinfo_t sigraise_cmd = {
+    .name       = "sigraise",
+    .cfunc      = sigraise_f,
+    .argmin     = 1,
+    .argmax     = 1,
+    .flags      = CMD_NOFILE_OK,
+    .args       = "signal",
+    .oneline    = "raises a Unix signal",
+    .help       = sigraise_help,
+};
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv)
+{
+    int sig = cvtnum(argv[1]);
+    if (sig < 0) {
+        printf("non-numeric signal number argument -- %s\n", argv[1]);
+        return 0;
+    }
+
+    /* Using raise() to kill this process does not necessarily flush all open
+     * streams. At least stdout and stderr (although the latter should be
+     * non-buffered anyway) should be flushed, though. */
+    fflush(stdout);
+    fflush(stderr);
+
+    raise(sig);
+    return 0;
+}
+
  static void sleep_cb(void *opaque)
  {
Quoted 8 lines

qemu-io-cmds.c static void __attribute((constructor)) init_qemuio_commands(void) · line 2251

Quoted 7 lines
qemu-io-cmds.c +1 -0
      bool *expired = opaque;
@@ -2202,4 +2247,5 @@ static void __attribute((constructor)) init_qemuio_commands(void)
      qemuio_add_command(&wait_break_cmd);
      qemuio_add_command(&abort_cmd);
      qemuio_add_command(&sleep_cmd);
+    qemuio_add_command(&sigraise_cmd);
  }

Looks good otherwise.

Quoted 1 line

Thanks :-)

Looking forward to v3 :)

#6 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] qemu-io: Add sigraise command

Am 05.12.2014 um 13:23 hat Markus Armbruster geschrieben:

Quoted 12 lines
Quoted 10 lines · Max Reitz
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Max Reitz

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.

Thus, -c abort is not always useful to simulate a qemu-io crash; therefore, this patch adds a new sigraise command which allows to raise any Unix signal.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Nitpick: signals are ISO C, not just UNIX.

Yes, but "Unix signal" is what the Wikipedia article is named, so... ;-)

If it's in Wikipedia, it must be right! Quick, file a bug against the C standard!

Well, if we're into nitpicking today: As you already said below, only a small subset is in standard C. Therefore, "allows to raise any Unix signal" is more than "allows to raise any C signal".

Quoted 33 lines
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
---
  qemu-io-cmds.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 46 insertions(+)
qemu-io-cmds.c +1 -0
index d94fb1e..942b694 100644
@@ -2048,6 +2048,51 @@ static const cmdinfo_t abort_cmd = {
         .oneline        = "simulate a program crash using abort(3)",
  };
  +static void sigraise_help(void)
+{
Quoted 8 lines

qemu-io-cmds.c static const cmdinfo_t abort_cmd = { · line 2058

Quoted 6 lines
qemu-io-cmds.c +6 -0
+    printf(
+"\n"
+" raises the given Unix signal\n"
+"\n"
+" Example:\n"
+" 'sigraise 9' - raises SIGKILL\n"

Assumes SIGKILL is encoded as 9, which is traditionally the case, but not actually mandated by POSIX.

Quoted 3 lines

Yes, I know. The best would be to parse the signal like kill(1) does, but that would have been extra difficult and probably not worth the effort.

Agree.

Quoted 3 lines

Furthermore, I know there is a song called "kill dash nine", so I guessed it would be enough (at least it'll have to be enough for test 039, thanks to "_supported_os Linux").

Quoted 8 lines

Bash can map signal names to numbers and back:

    $ kill -l 9
    KILL
    $ kill -l KILL
    9

Perhaps you can use that to avoid hardcoding.

Can we please immediately stop overengineering a simple debugging tool that should do nothing but quit qemu without doing a clean shutdown?

If the literal 9 bothers you, kill the example from the help text and be done with it.

Kevin

author
#7 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] qemu-io: Add sigraise command

In reply to Markus Armbruster
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Max Reitz
Quoted 6 lines · Markus Armbruster
Quoted 4 lines · Max Reitz

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.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines

Thus, -c abort is not always useful to simulate a qemu-io crash; therefore, this patch adds a new sigraise command which allows to raise any Unix signal.

Nitpick: signals are ISO C, not just UNIX.

Yes, but "Unix signal" is what the Wikipedia article is named, so... ;-)

If it's in Wikipedia, it must be right! Quick, file a bug against the C standard!

Yes, I know. But caling it "ISO C signals" or just "C signals" sounds strange, since C only defines raise() as far as I remember. Originally, I just called it "signals", of course, but that didn't sound so clear. "Unix signal" is an unambiguous way to name them.

Quoted 30 lines
Quoted 22 lines
Quoted 14 lines
Quoted 14 lines
---
   qemu-io-cmds.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
   1 file changed, 46 insertions(+)
qemu-io-cmds.c +1 -0
index d94fb1e..942b694 100644
@@ -2048,6 +2048,51 @@ static const cmdinfo_t abort_cmd = {
          .oneline        = "simulate a program crash using abort(3)",
   };
   +static void sigraise_help(void)
+{
Quoted 8 lines

qemu-io-cmds.c static const cmdinfo_t abort_cmd = { · line 2058

Quoted 6 lines
qemu-io-cmds.c +6 -0
+    printf(
+"\n"
+" raises the given Unix signal\n"
+"\n"
+" Example:\n"
+" 'sigraise 9' - raises SIGKILL\n"

Assumes SIGKILL is encoded as 9, which is traditionally the case, but not actually mandated by POSIX.

Quoted 3 lines

Yes, I know. The best would be to parse the signal like kill(1) does, but that would have been extra difficult and probably not worth the effort.

Agree.

Quoted 3 lines

Furthermore, I know there is a song called "kill dash nine", so I guessed it would be enough (at least it'll have to be enough for test 039, thanks to "_supported_os Linux").

Quoted 8 lines

Bash can map signal names to numbers and back:

     $ kill -l 9
     KILL
     $ kill -l KILL
     9

Perhaps you can use that to avoid hardcoding.

I hope you're talking about doing this in the patch and not in qemu-io itself. *g*

Well, can do. There is no real reason to as long as the test is only supported under Linux anyway, but there's no reason not to do this in the respin (other than that I'll lose Fam's R-b...) either. Therefore, will do, thanks.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

You could avoid hardcoding 9 with

" 'sigraise %d' - raises SIGKILL\n"

with a SIGKILL as argument for %d.

Quoted 8 lines
Quoted 7 lines

Clever. Will do.

Quoted 3 lines

But then you'd have to face the fact that SIGKILL is POSIX, not ISO C. The ISO C signals are SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM. Of these, SIGINT and SIGTERM don't dump core, in case you care.

Good to know. I guess I'll just go with SIGKILL anyway, it's ubiquitous enough.

Might break the Windows compile.

Right, the simplest way to do it then would be just to use SIGTERM instead of SIGKILL in the example and still use SIGKILL in 039. I'll do that if you don't disagree.

Max

Quoted 49 lines
Quoted 47 lines
Quoted 39 lines
Quoted 39 lines
qemu-io-cmds.c +37 -0
+"\n"
+" Invokes raise(signal), where \"signal\" is the mandatory integer argument\n"
+" given to sigraise.\n"
+"\n");
+}
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv);
+
+static const cmdinfo_t sigraise_cmd = {
+    .name       = "sigraise",
+    .cfunc      = sigraise_f,
+    .argmin     = 1,
+    .argmax     = 1,
+    .flags      = CMD_NOFILE_OK,
+    .args       = "signal",
+    .oneline    = "raises a Unix signal",
+    .help       = sigraise_help,
+};
+
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv)
+{
+    int sig = cvtnum(argv[1]);
+    if (sig < 0) {
+        printf("non-numeric signal number argument -- %s\n", argv[1]);
+        return 0;
+    }
+
+    /* Using raise() to kill this process does not necessarily flush all open
+     * streams. At least stdout and stderr (although the latter should be
+     * non-buffered anyway) should be flushed, though. */
+    fflush(stdout);
+    fflush(stderr);
+
+    raise(sig);
+    return 0;
+}
+
   static void sleep_cb(void *opaque)
   {
Quoted 8 lines

qemu-io-cmds.c static void __attribute((constructor)) init_qemuio_commands(void) · line 2251

Quoted 7 lines
qemu-io-cmds.c +1 -0
       bool *expired = opaque;
@@ -2202,4 +2247,5 @@ static void __attribute((constructor)) init_qemuio_commands(void)
       qemuio_add_command(&wait_break_cmd);
       qemuio_add_command(&abort_cmd);
       qemuio_add_command(&sleep_cmd);
+    qemuio_add_command(&sigraise_cmd);
   }

Looks good otherwise.

Quoted 1 line

Thanks :-)

Looking forward to v3 :)

#8 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] qemu-io: Add sigraise command

Quoted 15 lines · Max Reitz
Quoted 14 lines · Markus Armbruster
Quoted 12 lines · Max Reitz
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Max Reitz

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.

Thus, -c abort is not always useful to simulate a qemu-io crash; therefore, this patch adds a new sigraise command which allows to raise any Unix signal.

Nitpick: signals are ISO C, not just UNIX.

Yes, but "Unix signal" is what the Wikipedia article is named, so... ;-)

Quoted 8 lines
Quoted 2 lines

If it's in Wikipedia, it must be right! Quick, file a bug against the C standard!

Yes, I know. But caling it "ISO C signals" or just "C signals" sounds strange, since C only defines raise() as far as I remember. Originally, I just called it "signals", of course, but that didn't sound so clear. "Unix signal" is an unambiguous way to name them.

I'd write "allows to raise a signal", since I trust folks that have a need for this feature to know what signal means in this context. But if you'd rather write "raise a Unix signal", then that's clearly covered by your artistic license.

Quoted 37 lines
Quoted 37 lines
Quoted 22 lines
Quoted 14 lines
Quoted 14 lines
---
   qemu-io-cmds.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
   1 file changed, 46 insertions(+)
qemu-io-cmds.c +1 -0
index d94fb1e..942b694 100644
@@ -2048,6 +2048,51 @@ static const cmdinfo_t abort_cmd = {
          .oneline        = "simulate a program crash using abort(3)",
   };
   +static void sigraise_help(void)
+{
Quoted 8 lines

qemu-io-cmds.c static const cmdinfo_t abort_cmd = { · line 2058

Quoted 6 lines
qemu-io-cmds.c +6 -0
+    printf(
+"\n"
+" raises the given Unix signal\n"
+"\n"
+" Example:\n"
+" 'sigraise 9' - raises SIGKILL\n"

Assumes SIGKILL is encoded as 9, which is traditionally the case, but not actually mandated by POSIX.

Quoted 3 lines

Yes, I know. The best would be to parse the signal like kill(1) does, but that would have been extra difficult and probably not worth the effort.

Agree.

Quoted 3 lines

Furthermore, I know there is a song called "kill dash nine", so I guessed it would be enough (at least it'll have to be enough for test 039, thanks to "_supported_os Linux").

Bash can map signal names to numbers and back:

     $ kill -l 9
     KILL
     $ kill -l KILL
     9
Quoted 4 lines
Quoted 1 line

Perhaps you can use that to avoid hardcoding.

I hope you're talking about doing this in the patch and not in qemu-io itself. *g*

Dear god, no! %-)

Quoted 15 lines

Well, can do. There is no real reason to as long as the test is only supported under Linux anyway, but there's no reason not to do this in the respin (other than that I'll lose Fam's R-b...) either. Therefore, will do, thanks.

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

You could avoid hardcoding 9 with

" 'sigraise %d' - raises SIGKILL\n"

with a SIGKILL as argument for %d.

Clever. Will do.

Quoted 3 lines

But then you'd have to face the fact that SIGKILL is POSIX, not ISO C. The ISO C signals are SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM. Of these, SIGINT and SIGTERM don't dump core, in case you care.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Good to know. I guess I'll just go with SIGKILL anyway, it's ubiquitous enough.

Might break the Windows compile.

Right, the simplest way to do it then would be just to use SIGTERM instead of SIGKILL in the example and still use SIGKILL in 039. I'll do that if you don't disagree.

Sounds sensible to me.

#9 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] qemu-io: Add sigraise command

Quoted 8 lines · Markus Armbruster
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Thus, -c abort is not always useful to simulate a qemu-io crash; therefore, this patch adds a new sigraise command which allows to raise any Unix signal.

I'd write "allows to raise a signal", since I trust folks that have a need for this feature to know what signal means in this context. But if you'd rather write "raise a Unix signal", then that's clearly covered by your artistic license.

Actually, I'd write "allows raising a signal"; since "allows to" is an awkward construction not usually heard in native English.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#10 lore raw

PATCH v2 2/3 iotests: Filter for "Killed" in qemu-io output

In reply to Max Reitz

_filter_qemu_io already filters out the process ID when qemu-io is aborted; the same should be done when it is killed.

---
 tests/qemu-iotests/common.filter | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/common.filter +1 -1
index dfb9726..6c14590 100644
@@ -150,7 +150,7 @@ _filter_win32()
 _filter_qemu_io()
 {
     _filter_win32 | sed -e "s/[0-9]* ops\; [0-9/:. sec]* ([0-9/.inf]* [EPTGMKiBbytes]*\/sec and [0-9/.inf]* ops\/sec)/X ops\; XX:XX:XX.X (XXX YYY\/sec and XXX ops\/sec)/" \
-        -e "s/: line [0-9][0-9]*:  *[0-9][0-9]*\( Aborted\)/:\1/" \
+        -e "s/: line [0-9][0-9]*:  *[0-9][0-9]*\( Aborted\| Killed\)/:\1/" \
         -e "s/qemu-io> //g"
 }
 
Signature · 1 line
1.9.3
Reviewed-by on v2 2/3
#11 lore raw

Re: [Qemu-devel] [PATCH v2 2/3] iotests: Filter for "Killed" in qemu-io output

Quoted 25 lines · Max Reitz

_filter_qemu_io already filters out the process ID when qemu-io is aborted; the same should be done when it is killed.

---
 tests/qemu-iotests/common.filter | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/common.filter +1 -1
index dfb9726..6c14590 100644
@@ -150,7 +150,7 @@ _filter_win32()
 _filter_qemu_io()
 {
     _filter_win32 | sed -e "s/[0-9]* ops\; [0-9/:. sec]* ([0-9/.inf]* [EPTGMKiBbytes]*\/sec and [0-9/.inf]* ops\/sec)/X ops\; XX:XX:XX.X (XXX YYY\/sec and XXX ops\/sec)/" \
-        -e "s/: line [0-9][0-9]*:  *[0-9][0-9]*\( Aborted\)/:\1/" \
+        -e "s/: line [0-9][0-9]*:  *[0-9][0-9]*\( Aborted\| Killed\)/:\1/" \
         -e "s/qemu-io> //g"
 }
 
Signature · 1 line
1.9.3
author
#12 lore raw

PATCH v2 3/3 iotests: Fix test 039

In reply to Max Reitz

Test 039 used qemu-io -c abort for simulating a qemu crash; however, abort() generally results in a core dump and ulimit -c 0 is no reliable way of preventing that. Use "abort -S 9" instead to have it crash without a core dump.

---
 tests/qemu-iotests/039     | 12 +++++++-----
 tests/qemu-iotests/039.out |  6 +++---
 2 files changed, 10 insertions(+), 8 deletions(-)
tests/qemu-iotests/039 +7 -5
index 84c9167..51cb8f7 100755
@@ -47,9 +47,11 @@ _supported_os Linux
 _default_cache_mode "writethrough"
 _supported_cache_modes "writethrough"
 
-_no_dump_exec()
+_subshell_exec()
 {
-    (ulimit -c 0; exec "$@")
+    # Executing crashing commands in a subshell prevents information like the
+    # "Killed" line from being lost
+    (exec "$@")
 }
 
 size=128M
@@ -72,7 +74,7 @@ echo "== Creating a dirty image file =="
 IMGOPTS="compat=1.1,lazy_refcounts=on"
 _make_test_img $size
 
-_no_dump_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" 2>&1 | _filter_qemu_io
+_subshell_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "sigraise 9" "$TEST_IMG" 2>&1 | _filter_qemu_io
 
 # The dirty bit must be set
 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
@@ -105,7 +107,7 @@ echo "== Opening a dirty image read/write should repair it =="
 IMGOPTS="compat=1.1,lazy_refcounts=on"
 _make_test_img $size
 
-_no_dump_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" 2>&1 | _filter_qemu_io
+_subshell_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "sigraise 9" "$TEST_IMG" 2>&1 | _filter_qemu_io
 
 # The dirty bit must be set
 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
@@ -121,7 +123,7 @@ echo "== Creating an image file with lazy_refcounts=off =="
 IMGOPTS="compat=1.1,lazy_refcounts=off"
 _make_test_img $size
 
-_no_dump_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" 2>&1 | _filter_qemu_io
+_subshell_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "sigraise 9" "$TEST_IMG" 2>&1 | _filter_qemu_io
 
 # The dirty bit must not be set since lazy_refcounts=off
 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
tests/qemu-iotests/039.out +3 -3
index 0adf153..35a04bd 100644
@@ -11,7 +11,7 @@ No errors were found on the image.
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./039: Aborted                 ( ulimit -c 0; exec "$@" )
+./039: Killed                  ( exec "$@" )
 incompatible_features     0x1
 ERROR cluster 5 refcount=0 reference=1
 ERROR OFLAG_COPIED data cluster: l2_entry=8000000000050000 refcount=0
@@ -46,7 +46,7 @@ read 512/512 bytes at offset 0
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./039: Aborted                 ( ulimit -c 0; exec "$@" )
+./039: Killed                  ( exec "$@" )
 incompatible_features     0x1
 ERROR cluster 5 refcount=0 reference=1
 Rebuilding refcount structure
@@ -60,7 +60,7 @@ incompatible_features     0x0
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./039: Aborted                 ( ulimit -c 0; exec "$@" )
+./039: Killed                  ( exec "$@" )
 incompatible_features     0x0
 No errors were found on the image.
 
Signature · 1 line
1.9.3
Reviewed-by on v2 3/3
#13 lore raw
Quoted 4 lines · Max Reitz

Test 039 used qemu-io -c abort for simulating a qemu crash; however, abort() generally results in a core dump and ulimit -c 0 is no reliable way of preventing that. Use "abort -S 9" instead to have it crash without a core dump.

This needs to be fixed to "sigraise 9". Otherwise looks good. With the commit message fixed,

Quoted 87 lines
---
 tests/qemu-iotests/039     | 12 +++++++-----
 tests/qemu-iotests/039.out |  6 +++---
 2 files changed, 10 insertions(+), 8 deletions(-)
tests/qemu-iotests/039 +7 -5
index 84c9167..51cb8f7 100755
@@ -47,9 +47,11 @@ _supported_os Linux
 _default_cache_mode "writethrough"
 _supported_cache_modes "writethrough"
 
-_no_dump_exec()
+_subshell_exec()
 {
-    (ulimit -c 0; exec "$@")
+    # Executing crashing commands in a subshell prevents information like the
+    # "Killed" line from being lost
+    (exec "$@")
 }
 
 size=128M
@@ -72,7 +74,7 @@ echo "== Creating a dirty image file =="
 IMGOPTS="compat=1.1,lazy_refcounts=on"
 _make_test_img $size
 
-_no_dump_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" 2>&1 | _filter_qemu_io
+_subshell_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "sigraise 9" "$TEST_IMG" 2>&1 | _filter_qemu_io
 
 # The dirty bit must be set
 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
@@ -105,7 +107,7 @@ echo "== Opening a dirty image read/write should repair it =="
 IMGOPTS="compat=1.1,lazy_refcounts=on"
 _make_test_img $size
 
-_no_dump_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" 2>&1 | _filter_qemu_io
+_subshell_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "sigraise 9" "$TEST_IMG" 2>&1 | _filter_qemu_io
 
 # The dirty bit must be set
 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
@@ -121,7 +123,7 @@ echo "== Creating an image file with lazy_refcounts=off =="
 IMGOPTS="compat=1.1,lazy_refcounts=off"
 _make_test_img $size
 
-_no_dump_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" 2>&1 | _filter_qemu_io
+_subshell_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "sigraise 9" "$TEST_IMG" 2>&1 | _filter_qemu_io
 
 # The dirty bit must not be set since lazy_refcounts=off
 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
tests/qemu-iotests/039.out +3 -3
index 0adf153..35a04bd 100644
@@ -11,7 +11,7 @@ No errors were found on the image.
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./039: Aborted                 ( ulimit -c 0; exec "$@" )
+./039: Killed                  ( exec "$@" )
 incompatible_features     0x1
 ERROR cluster 5 refcount=0 reference=1
 ERROR OFLAG_COPIED data cluster: l2_entry=8000000000050000 refcount=0
@@ -46,7 +46,7 @@ read 512/512 bytes at offset 0
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./039: Aborted                 ( ulimit -c 0; exec "$@" )
+./039: Killed                  ( exec "$@" )
 incompatible_features     0x1
 ERROR cluster 5 refcount=0 reference=1
 Rebuilding refcount structure
@@ -60,7 +60,7 @@ incompatible_features     0x0
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
 wrote 512/512 bytes at offset 0
 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./039: Aborted                 ( ulimit -c 0; exec "$@" )
+./039: Killed                  ( exec "$@" )
 incompatible_features     0x0
 No errors were found on the image.
 
Signature · 1 line
1.9.3
author
#14 lore raw
Quoted 6 lines · Fam Zheng
Quoted 4 lines · Max Reitz

Test 039 used qemu-io -c abort for simulating a qemu crash; however, abort() generally results in a core dump and ulimit -c 0 is no reliable way of preventing that. Use "abort -S 9" instead to have it crash without a core dump.

This needs to be fixed to "sigraise 9".

Ah, right. Sorry. Will fix (after having waited for Markus's opinion on this v2).

Quoted 4 lines

Otherwise looks good. With the commit
message fixed,

Thanks!

Max

Quoted 86 lines
Quoted 86 lines
---
  tests/qemu-iotests/039     | 12 +++++++-----
  tests/qemu-iotests/039.out |  6 +++---
  2 files changed, 10 insertions(+), 8 deletions(-)
tests/qemu-iotests/039 +7 -5
index 84c9167..51cb8f7 100755
@@ -47,9 +47,11 @@ _supported_os Linux
  _default_cache_mode "writethrough"
  _supported_cache_modes "writethrough"
 
-_no_dump_exec()
+_subshell_exec()
  {
-    (ulimit -c 0; exec "$@")
+    # Executing crashing commands in a subshell prevents information like the
+    # "Killed" line from being lost
+    (exec "$@")
  }
 
  size=128M
@@ -72,7 +74,7 @@ echo "== Creating a dirty image file =="
  IMGOPTS="compat=1.1,lazy_refcounts=on"
  _make_test_img $size
 
-_no_dump_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" 2>&1 | _filter_qemu_io
+_subshell_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "sigraise 9" "$TEST_IMG" 2>&1 | _filter_qemu_io
 
  # The dirty bit must be set
  $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
@@ -105,7 +107,7 @@ echo "== Opening a dirty image read/write should repair it =="
  IMGOPTS="compat=1.1,lazy_refcounts=on"
  _make_test_img $size
 
-_no_dump_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" 2>&1 | _filter_qemu_io
+_subshell_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "sigraise 9" "$TEST_IMG" 2>&1 | _filter_qemu_io
 
  # The dirty bit must be set
  $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
@@ -121,7 +123,7 @@ echo "== Creating an image file with lazy_refcounts=off =="
  IMGOPTS="compat=1.1,lazy_refcounts=off"
  _make_test_img $size
 
-_no_dump_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "abort" "$TEST_IMG" 2>&1 | _filter_qemu_io
+_subshell_exec $QEMU_IO -c "write -P 0x5a 0 512" -c "sigraise 9" "$TEST_IMG" 2>&1 | _filter_qemu_io
 
  # The dirty bit must not be set since lazy_refcounts=off
  $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
tests/qemu-iotests/039.out +3 -3
index 0adf153..35a04bd 100644
@@ -11,7 +11,7 @@ No errors were found on the image.
  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
  wrote 512/512 bytes at offset 0
  512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./039: Aborted                 ( ulimit -c 0; exec "$@" )
+./039: Killed                  ( exec "$@" )
  incompatible_features     0x1
  ERROR cluster 5 refcount=0 reference=1
  ERROR OFLAG_COPIED data cluster: l2_entry=8000000000050000 refcount=0
@@ -46,7 +46,7 @@ read 512/512 bytes at offset 0
  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
  wrote 512/512 bytes at offset 0
  512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./039: Aborted                 ( ulimit -c 0; exec "$@" )
+./039: Killed                  ( exec "$@" )
  incompatible_features     0x1
  ERROR cluster 5 refcount=0 reference=1
  Rebuilding refcount structure
@@ -60,7 +60,7 @@ incompatible_features     0x0
  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
  wrote 512/512 bytes at offset 0
  512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-./039: Aborted                 ( ulimit -c 0; exec "$@" )
+./039: Killed                  ( exec "$@" )
  incompatible_features     0x0
  No errors were found on the image.
 
Signature · 1 line
1.9.3