From patchwork Thu Sep 17 18:04:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1366325 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=JjJarYef; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BslH93M6dz9sPB for ; Fri, 18 Sep 2020 04:04:53 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AEB6A823DB; Thu, 17 Sep 2020 20:04:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="JjJarYef"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 56B82823ED; Thu, 17 Sep 2020 20:04:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C481D823D9 for ; Thu, 17 Sep 2020 20:04:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1600365879; bh=KFBuxXBdEKwsMoBJgaMyu2ZBf2+TjBXvr7PXRaPhdRs=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=JjJarYefInLyv4D0TvTkMPdGHO8KghQkUz6qd5joecoB9VIKHACir9wJpRi0HS1hJ beYCmbrR//xegpdN2oK43SX3ZAX0VZWgOfJPWnFSXCczLpXzgwRoBDC5+buqUvCkDL QwCKiUbqik7qBL75IYT4M2RgEWKKFaD3cG79Aa6s= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from LT02.fritz.box ([178.202.41.107]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1M2O6e-1kLjA12vc6-003sFS; Thu, 17 Sep 2020 20:04:39 +0200 From: Heinrich Schuchardt To: Simon Glass Cc: Rasmus Villemoes , Bin Meng , Andy Shevchenko , Walter Lozano , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/1] sandbox: support CTRL-C processing in U-Boot Date: Thu, 17 Sep 2020 20:04:22 +0200 Message-Id: <20200917180422.53595-1-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-Provags-ID: V03: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njsR4/oKX2dGH3turjYT7OXSAXm ZAIZgJ369Oj7fq10XHfhxog7NxcVN42E2PRvZWzLi1IarKHGP5Kf8bLYeSI/CMsSJ6QwKy06B p6GOwrRGjkIy1I/j3SkKfnj75IgwV9PukkBf5zUQd7nJe3EhwGsmG6K5iARsVIpWlmM3I6e6t BgDRZEl9D84XI0UeUeEK4dCj8nb+JDYZB/ap12QoCt+XKHeoBMG5t+ZR3eEPzHZcCGvlRN5xF 2fvHGaQbUVvAjEiOThBUovKJbqjvu4zr+xHfjHhvwDii5At/fHZIxc1PvAlEeNvPTAIKti5XJ YtQCrPGKZZl+my6RaxOCpXtPJVDMt84ZatWSo7ddDpKCerFYNNp7yaGQJbVIaMlV3tGHlZnsG kWfM925nRkk2mABNIH5ML6Hwy6QG9n612WF3CIkj+d+fOClMuwWtHxtj48YhKdijdEHpVGBBC AW38/4+3q+CMm//XGlLvOGVqI82LVV20jIqqRRg== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Currently if SIGINT is received, it terminates U-Boot. This does not allow testing the handling of CTRL-C in U-Boot and in UEFI applications. It is especially annoying when working with the 'mm' command. Let the serial console driver provide character 0x03 if SIGINT occurs. We can still exit U-Boot using the reset or poweroff command. Adjust the sandbox test_ctrl_c() Python test accordingly. Signed-off-by: Heinrich Schuchardt --- arch/sandbox/cpu/os.c | 15 ++++++++++++--- drivers/serial/sandbox.c | 11 ++++++++--- include/os.h | 14 ++++++++++++++ test/py/tests/test_sandbox_exit.py | 10 +++++++++- 4 files changed, 43 insertions(+), 7 deletions(-) -- 2.28.0 diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index e7ec892bdf..b5cfa38a32 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -161,6 +161,7 @@ err: static struct termios orig_term; static bool term_setup; static bool term_nonblock; +static bool pending_ctrlc; void os_fd_restore(void) { @@ -176,11 +177,19 @@ void os_fd_restore(void) } } +void os_clear_ctrlc(void) +{ + pending_ctrlc = false; +} + +bool os_get_ctrlc(void) +{ + return pending_ctrlc; +} + static void os_sigint_handler(int sig) { - os_fd_restore(); - signal(SIGINT, SIG_DFL); - raise(SIGINT); + pending_ctrlc = true; } /* Put tty into raw mode so and work */ diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c index f09d291e04..e510d51e27 100644 --- a/drivers/serial/sandbox.c +++ b/drivers/serial/sandbox.c @@ -72,9 +72,6 @@ static int sandbox_serial_probe(struct udevice *dev) os_tty_raw(0, state->term_raw == STATE_TERM_RAW_WITH_SIGS); priv->start_of_line = 0; - if (state->term_raw != STATE_TERM_RAW) - disable_ctrlc(1); - return 0; } @@ -118,6 +115,9 @@ static int sandbox_serial_pending(struct udevice *dev, bool input) increment_buffer_index(serial_buf_write); ssize_t count; + if (os_get_ctrlc()) + return true; + if (!input) return 0; @@ -139,6 +139,11 @@ static int sandbox_serial_getc(struct udevice *dev) { int result; + if (os_get_ctrlc()) { + os_clear_ctrlc(); + return 0x03; + } + if (!sandbox_serial_pending(dev, true)) return -EAGAIN; /* buffer empty */ diff --git a/include/os.h b/include/os.h index 1874ae674f..0cbf737d57 100644 --- a/include/os.h +++ b/include/os.h @@ -355,4 +355,18 @@ int os_read_file(const char *name, void **bufp, int *sizep); */ void *os_find_text_base(void); +/** + * os_get_ctrlc() - check if a CTRL+C has occurred + * + * Return: true if CTRL+C has occurred + */ +bool os_get_ctrlc(void); + +/** + * os_clear_ctrlc() - clear CTRL+C + * + * Mark a previous CTRL+C event as handled. + */ +void os_clear_ctrlc(void); + #endif diff --git a/test/py/tests/test_sandbox_exit.py b/test/py/tests/test_sandbox_exit.py index a301f4b559..4bc703ea56 100644 --- a/test/py/tests/test_sandbox_exit.py +++ b/test/py/tests/test_sandbox_exit.py @@ -15,7 +15,15 @@ def test_reset(u_boot_console): @pytest.mark.boardspec('sandbox') def test_ctrl_c(u_boot_console): - """Test that sending SIGINT to sandbox causes it to exit.""" + """Test that SIGINT is handled as CTRL-C.""" u_boot_console.kill(signal.SIGINT) + u_boot_console.wait_for('') + u_boot_console.run_command('echo') + + u_boot_console.run_command('\x03', wait_for_echo=False, wait_for_prompt=False) + u_boot_console.wait_for('') + u_boot_console.run_command('echo') + + u_boot_console.kill(signal.SIGKILL) assert(u_boot_console.validate_exited())