From patchwork Tue Mar 29 15:49:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610705 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=H6auZwy2; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4KSYtd4RXyz9sFk for ; Wed, 30 Mar 2022 02:50:33 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtd3NSXz2xvv for ; Wed, 30 Mar 2022 02:50:33 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=H6auZwy2; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::535; helo=mail-pg1-x535.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=H6auZwy2; dkim-atps=neutral Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KSYtb1gRYz2yJ5 for ; Wed, 30 Mar 2022 02:50:31 +1100 (AEDT) Received: by mail-pg1-x535.google.com with SMTP id l129so6659406pga.3 for ; Tue, 29 Mar 2022 08:50:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UAO+OTcidRidhDB4oXSvLRYcPMOZGfrqd/q2NuiEqZE=; b=H6auZwy2yRds4I4jSbcAZ9z9CEG35GxeS+bGnisWpP41pof+hUmJaeMzv/y6+LwZ32 okItn534IyJwVl2Ke8wyIrcFwSYGGLlC9WE+Gh9CJBeNz+rpry6D2/EFLzNHznX2j3iO nH9fdBYAirJ+2a2OX8D3fa5JsTueLKKViO8g0XcFDQHO+2UeOU5DUbo5L3UNJ+rV32jv fVYAEjSemd8/syrPhZJXTFUyucAYQ8dbtgg7141+aU3p7FahTZn6CAo/8152Vw0HVhSL 6IBH0v5aHdWC/MXbzFvZYmR/CCCHaKtog+kBW+8vDDWot+jrE7j71qFURWjvdHq+AbHB xaUg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=UAO+OTcidRidhDB4oXSvLRYcPMOZGfrqd/q2NuiEqZE=; b=HISnfStwc7j/F+r5i68aK2o1t2NCuc2NBuIKaw8OD1+iokJ6hGuKFHtkdBVgccWG2r WbHqEvBeQiRevvdS3lCm1hUOWIgv5Udn4ylPlopWBHAVrARo2gK97UED8xk1LapqOdHi VWvaocNbaPyhYyIbLSaNkjT3GfkQxwrxW1ZFNY6dVWexPC7548iZEvBlR6YyztvN7tnu FcN5ONbIVaKusThwIjcYWN0hiegygBZJqMsLpG/Fi/EtAVnzrlPPHEd7P6q2f1sKdUnB zOfjyquFGvzV6fzk/KtUK2dO2y5sFoMEp+XrHpAJSsvpFes/KjZe4vmBDUeyP/UhlxtD 8m/Q== X-Gm-Message-State: AOAM531OYeHmHH6wEzS+z/LQeoxiupMZHWuBYccvX3qCiltqfOafqBKe cU9ChcMIuhz7XBQOd9nx1L+d/8uZDNs= X-Google-Smtp-Source: ABdhPJxe5+0SL43YVxqmI/ol4HfcJIPOOZFYNG0v0SO1NyhnunBzu+OXXWmYyQ203BetHTC9JpzG2A== X-Received: by 2002:a63:1a04:0:b0:381:edc8:66b1 with SMTP id a4-20020a631a04000000b00381edc866b1mr2430663pga.131.1648569028841; Tue, 29 Mar 2022 08:50:28 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:28 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:16 +1000 Message-Id: <20220329154931.493851-24-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 23/38] gdbserver: catch ctrl-C X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" This allows gdbserver to clean up the host state gracefully after a SIGINT. It will become more important with later patches. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 29ba52a..b09cf5f 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -640,12 +641,28 @@ static command_cb callbacks[LAST_CMD + 1] = { detach, NULL}; -int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_t port) +static volatile bool gdbserver_running = true; + +static void SIGINT_handler(int sig) +{ + gdbserver_running = false; +} + +static int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_t port) { int sock, i; + struct sigaction sa; struct sockaddr_in name; fd_set active_fd_set, read_fd_set; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = SIGINT_handler; + sa.sa_flags = SA_RESETHAND; + if (sigaction(SIGINT, &sa, NULL) == -1) { + perror("sigaction"); + return -1; + } + parser_init(callbacks); thread_target = thread; adu_target = adu; @@ -674,7 +691,7 @@ int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_ FD_ZERO(&active_fd_set); FD_SET(sock, &active_fd_set); - while (1) { + while (gdbserver_running) { read_fd_set = active_fd_set; timeout.tv_sec = 0; timeout.tv_usec = poll_interval; @@ -725,6 +742,8 @@ int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_ poll(); } + printf("gdbserver: got ctrl-C, cleaning up (second ctrl-C to kill immediately).\n"); + return 1; } @@ -776,6 +795,7 @@ static int gdbserver(uint16_t port) } gdbserver_start(thread, adu, port); + return 0; } #else