619821
From 9bf536ecc296516cb5d82d5e9630663aaac56629 Mon Sep 17 00:00:00 2001
619821
From: Max Reitz <mreitz@redhat.com>
619821
Date: Mon, 13 Mar 2017 17:46:24 +0100
619821
Subject: [PATCH 13/24] qemu-io: Add sigraise command
619821
619821
RH-Author: Max Reitz <mreitz@redhat.com>
619821
Message-id: <20170313174629.28735-2-mreitz@redhat.com>
619821
Patchwork-id: 74275
619821
O-Subject: [RHEL-7.4 qemu-kvm PATCH 4/9] qemu-io: Add sigraise command
619821
Bugzilla: 1427176
619821
RH-Acked-by: Fam Zheng <famz@redhat.com>
619821
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
619821
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
619821
619821
abort() has the sometimes undesirable side-effect of generating a core
619821
dump. If that is not needed, SIGKILL has the same effect of abruptly
619821
crash qemu; without a core dump.
619821
619821
Thus, -c abort is not always useful to simulate a qemu-io crash;
619821
therefore, this patch adds a new sigraise command which allows raising
619821
a signal.
619821
619821
Signed-off-by: Max Reitz <mreitz@redhat.com>
619821
Reviewed-by: Fam Zheng <famz@redhat.com>
619821
Message-id: 1418032092-16813-2-git-send-email-mreitz@redhat.com
619821
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
619821
(cherry picked from commit 0e82dc7bbd96f9b0fb76e5fe263ba04b15e68127)
619821
Signed-off-by: Max Reitz <mreitz@redhat.com>
619821
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
619821
---
619821
 qemu-io-cmds.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
619821
 1 file changed, 46 insertions(+)
619821
619821
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
619821
index b41d6ee..010f05f 100644
619821
--- a/qemu-io-cmds.c
619821
+++ b/qemu-io-cmds.c
619821
@@ -2050,6 +2050,51 @@ static const cmdinfo_t abort_cmd = {
619821
        .oneline        = "simulate a program crash using abort(3)",
619821
 };
619821
 
619821
+static void sigraise_help(void)
619821
+{
619821
+    printf(
619821
+"\n"
619821
+" raises the given signal\n"
619821
+"\n"
619821
+" Example:\n"
619821
+" 'sigraise %i' - raises SIGTERM\n"
619821
+"\n"
619821
+" Invokes raise(signal), where \"signal\" is the mandatory integer argument\n"
619821
+" given to sigraise.\n"
619821
+"\n", SIGTERM);
619821
+}
619821
+
619821
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv);
619821
+
619821
+static const cmdinfo_t sigraise_cmd = {
619821
+    .name       = "sigraise",
619821
+    .cfunc      = sigraise_f,
619821
+    .argmin     = 1,
619821
+    .argmax     = 1,
619821
+    .flags      = CMD_NOFILE_OK,
619821
+    .args       = "signal",
619821
+    .oneline    = "raises a signal",
619821
+    .help       = sigraise_help,
619821
+};
619821
+
619821
+static int sigraise_f(BlockDriverState *bs, int argc, char **argv)
619821
+{
619821
+    int sig = cvtnum(argv[1]);
619821
+    if (sig < 0) {
619821
+        printf("non-numeric signal number argument -- %s\n", argv[1]);
619821
+        return 0;
619821
+    }
619821
+
619821
+    /* Using raise() to kill this process does not necessarily flush all open
619821
+     * streams. At least stdout and stderr (although the latter should be
619821
+     * non-buffered anyway) should be flushed, though. */
619821
+    fflush(stdout);
619821
+    fflush(stderr);
619821
+
619821
+    raise(sig);
619821
+    return 0;
619821
+}
619821
+
619821
 static void sleep_cb(void *opaque)
619821
 {
619821
     bool *expired = opaque;
619821
@@ -2203,4 +2248,5 @@ static void __attribute((constructor)) init_qemuio_commands(void)
619821
     qemuio_add_command(&wait_break_cmd);
619821
     qemuio_add_command(&abort_cmd);
619821
     qemuio_add_command(&sleep_cmd);
619821
+    qemuio_add_command(&sigraise_cmd);
619821
 }
619821
-- 
619821
1.8.3.1
619821