From patchwork Mon Dec 8 09:48:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 418648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B2B361400E2 for ; Mon, 8 Dec 2014 20:49:04 +1100 (AEDT) Received: from localhost ([::1]:60918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XxuwA-00069Y-UI for incoming@patchwork.ozlabs.org; Mon, 08 Dec 2014 04:49:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xxuva-0005GS-HC for qemu-devel@nongnu.org; Mon, 08 Dec 2014 04:48:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XxuvU-0007Ag-84 for qemu-devel@nongnu.org; Mon, 08 Dec 2014 04:48:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33412) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XxuvT-0007Ab-Vz for qemu-devel@nongnu.org; Mon, 08 Dec 2014 04:48:20 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sB89mH9I013014 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 8 Dec 2014 04:48:17 -0500 Received: from localhost (dhcp-192-247.str.redhat.com [10.33.192.247]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sB89mFLS030117 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Mon, 8 Dec 2014 04:48:16 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Mon, 8 Dec 2014 10:48:10 +0100 Message-Id: <1418032092-16813-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1418032092-16813-1-git-send-email-mreitz@redhat.com> References: <1418032092-16813-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Michael=20M=C3=BCller?= , Markus Armbruster , Max Reitz , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v3 1/3] qemu-io: Add sigraise command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 raising a signal. Signed-off-by: Max Reitz Reviewed-by: Fam Zheng --- qemu-io-cmds.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index d94fb1e..e708552 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -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 signal\n" +"\n" +" Example:\n" +" 'sigraise %i' - raises SIGTERM\n" +"\n" +" Invokes raise(signal), where \"signal\" is the mandatory integer argument\n" +" given to sigraise.\n" +"\n", SIGTERM); +} + +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 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); }