yeahuh / rpms / qemu-kvm

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