From patchwork Mon Oct 18 14:02:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 515923 Delivered-To: patch@linaro.org Received: by 2002:ac0:cd8c:0:0:0:0:0 with SMTP id d12csp1815098imp; Mon, 18 Oct 2021 07:06:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNhPRI9ttcnOyUvAS3k3AzgwUzWY8UMZBhfeoPL80IIRm+EfEODWLwhNuKJjPh60pkRvd6 X-Received: by 2002:a67:ee47:: with SMTP id g7mr27141657vsp.46.1634566006249; Mon, 18 Oct 2021 07:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634566006; cv=none; d=google.com; s=arc-20160816; b=n4psIU1nuTNiqaWrXuGXmTXdTsTKHIysw95txlDUpXvj3jh6OCEKLmYsLRaxG9jSR+ kRvNYWGupCvBDewe6+/kLU4H3kmXDRYSJTgU2jc0JoxQhgF3CIE8V+7MlQrJ4hF8u41A H5iNOPUusQWqX8aq0Tno35NNcPnNXwr+l/f5p6ygvVim33Cphl6UKH+SMTGQpNAKgKMX 7Lf5R5vNwq7mNvl///QLc2uz0gJ8KOOsIp6QrufIYLRIVyeesUJn3sSqjDQJmgQWWsIw 85ps0y+BP94dxnuKE6+hgoe6ax4rAgXjzrrKXwvxjyUJYUlNJAu4jTqJBjZlQ8z9f5Ly 8tcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=+dr9HiO6Z+6raCU+RfVpg+exNsSiRLldmzl+NY3BKOw=; b=itnHCp3zd01xRxax6DkNQvvGP2pcUrtqtHHSjFw3l/NV5/VaBeacSk1KVPN9V7dIhg FJUU3i1VViHP0VwV6pL/LpYjpigsm4sb+OhnpgSd4IU1alAfCbbtxrObSZDDBfRXLiZS +fGn7sYAXmFtqFceUlgk0wnI66NVuLM6/hX1DqMzBq6m6qA3SPmrV9EsfpjK0kuBIVri gha4pjroWXbkt+gNQ8BSV+MnOWFJ+LqCD32mRSIgtinnjJbSn5bGbfD4d9z8YHx9tBHc Orw+p3nNXUZtaZZocYRNtTPwCym3yjmvm/zCct8XEkRJcXF7/TBZpWmxERz2ZFmPINuS ppAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=H2HktZmT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w134si11390926vkd.27.2021.10.18.07.06.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Oct 2021 07:06:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=H2HktZmT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcTHp-0005Cl-Ma for patch@linaro.org; Mon, 18 Oct 2021 10:06:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcTDy-0003Gp-OO for qemu-devel@nongnu.org; Mon, 18 Oct 2021 10:02:47 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:36852) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcTDw-0005hC-Sm for qemu-devel@nongnu.org; Mon, 18 Oct 2021 10:02:46 -0400 Received: by mail-wm1-x32d.google.com with SMTP id z77-20020a1c7e50000000b0030db7b70b6bso10487665wmc.1 for ; Mon, 18 Oct 2021 07:02:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+dr9HiO6Z+6raCU+RfVpg+exNsSiRLldmzl+NY3BKOw=; b=H2HktZmTWi7wEQEvdcjPBiDGlTr8Sw7fYYJP7G9fLVTTsBLID2TFFP7deoZ1Vt/574 9uLIFzvmA9erIdrpyAtaT5bibRDK5Ed7IusJVHiWVX4294Z+ySdWbTyKKH5SSobT++zu F3ugDfbMyUXW3srSgt9OR+uyVqwFHHxMW7PyEk7hoU7SgC1zameWSsKICLbBCViZDfQ8 0mIJkIJLXwn0sJvSq3IrdEtdVEb7KPWpitH0YliuVl79JlCDyYqzv/nddrNl7wTUXLRr DcPCs1X3kJvnAh5B63O8S7omkQynORVktaZJdVVx+VRODaUe+b/6rT1S+2DPuvO4RMTq 3hyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+dr9HiO6Z+6raCU+RfVpg+exNsSiRLldmzl+NY3BKOw=; b=1nmH7iTKWSDE54m3W8N/9ENfKK9yDcQxiSuvzw4LXwKJBuQN6+GpF6Tw+uSbJ9B90r D50DgC9b4qUBXj3DCEAZ/2Xk88knglRd7pX8WlBEX18siAPqQO64BLNvUlz34SEQ/n1u E0asGlrVHRve4E7cD4atWFn074AQaH2i6MzFhMUTQ3DYIuLzcvdqIpBXqEYZbAvBjWPr RXwz1YH9vSQzQ6Rgz/YZRMqvJDkShfNqu5wh/0t3TBPkUbOl19Hj3Ij7fAw9kAnYtreR RmKuAU95I/Any9BiaKxIq1VBUoGEwZrtKw34X5FMCGuYRhID7oVyqmFVSA8u8e9U+sYf hexw== X-Gm-Message-State: AOAM5327qM973kCltoEUvvw2bWFhBdPCpJMjKmZmRsAl8Az/7XAX21eU 5VKfLdM0bwTLu0Db4K9f8JWjzA== X-Received: by 2002:a1c:cc09:: with SMTP id h9mr31326162wmb.191.1634565762838; Mon, 18 Oct 2021 07:02:42 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id p19sm17991599wmg.29.2021.10.18.07.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 07:02:41 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D62A11FF96; Mon, 18 Oct 2021 15:02:40 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [RFC PATCH] chardev: don't exit() straight away on C-a x Date: Mon, 18 Oct 2021 15:02:26 +0100 Message-Id: <20211018140226.838137-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Lukas_J=C3=BCnger?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" While there are a number of uses in the code-base of the exit(0) pattern it gets in the way of clean exit which can do all of it's house-keeping. In particular it was reported that you can crash plugins this way because TCG can still be running on other threads when the atexit callback is called. Use qemu_system_shutdown_request() instead. I did a gentle rename of the runstate stub seeing as it now contains two functions. Signed-off-by: Alex Bennée Reported-by: Lukas Jünger --- chardev/char-mux.c | 3 ++- stubs/{runstate-check.c => runstate.c} | 5 +++++ stubs/meson.build | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) rename stubs/{runstate-check.c => runstate.c} (64%) -- 2.30.2 Reviewed-by: Marc-André Lureau Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reported-by: Lukas Jünger <lukas.junger@greensocs.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
diff --git a/chardev/char-mux.c b/chardev/char-mux.c index ada0c6866f..a46897fcd5 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -28,6 +28,7 @@ #include "qemu/option.h" #include "chardev/char.h" #include "sysemu/block-backend.h" +#include "sysemu/runstate.h" #include "chardev-internal.h" /* MUX driver for serial I/O splitting */ @@ -157,7 +158,7 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch) { const char *term = "QEMU: Terminated\n\r"; qemu_chr_write_all(chr, (uint8_t *)term, strlen(term)); - exit(0); + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); break; } case 's': diff --git a/stubs/runstate-check.c b/stubs/runstate.c similarity index 64% rename from stubs/runstate-check.c rename to stubs/runstate.c index 2ccda2b70f..f47dbcd3e0 100644 --- a/stubs/runstate-check.c +++ b/stubs/runstate.c @@ -5,3 +5,8 @@ bool runstate_check(RunState state) { return state == RUN_STATE_PRELAUNCH; } + +void qemu_system_shutdown_request(ShutdownCause reason) +{ + return; +} diff --git a/stubs/meson.build b/stubs/meson.build index f6aa3aa94f..8f6a9f17e5 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -35,7 +35,7 @@ stub_ss.add(files('qtest.c')) stub_ss.add(files('ram-block.c')) stub_ss.add(files('ramfb.c')) stub_ss.add(files('replay.c')) -stub_ss.add(files('runstate-check.c')) +stub_ss.add(files('runstate.c')) stub_ss.add(files('sysbus.c')) stub_ss.add(files('target-get-monitor-def.c')) stub_ss.add(files('target-monitor-defs.c'))