From patchwork Wed Apr 20 06:49:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619351 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=D1QYEDYz; 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 4KjrtP2VH7z9sG0 for ; Wed, 20 Apr 2022 16:51:25 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtP1Qqrz2yn2 for ; Wed, 20 Apr 2022 16:51:25 +1000 (AEST) 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=D1QYEDYz; 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::632; helo=mail-pl1-x632.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=D1QYEDYz; dkim-atps=neutral Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 4KjrtL61Fhz2yn2 for ; Wed, 20 Apr 2022 16:51:22 +1000 (AEST) Received: by mail-pl1-x632.google.com with SMTP id 12so950638pll.12 for ; Tue, 19 Apr 2022 23:51:22 -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=SM0LwWTdLbU0ls+OYpiOTf1ONeyi95kxZLireRQvXbI=; b=D1QYEDYzaPwIXNSEXvpfhbjPGtcDPAamYb8ZRMJzy51O48Pqk8IKg69hkvy7Ilu1pY 7IkrWxfhsy/87BO+oVsPOU6v52yWM9vct5weRtysjoSWhO44s0U+gG3F3pdZvkvn6IaE KfQgEHT5NYQN4apYMlpDiOncqqfk/vyB4qRaT2uxvv68VBWXW6ny+Yhh3865OXqUwPNg 9OGHfax/D+tnbCvuKvtGDgU53Py3L2JR13ZezW1Ksls3dKHuiLcOy6IQeraSNNjKJJPC +XnJhL0TB4CsO7311FNbTpYhmNLGlxj6creGdSIq1YuDtIX6NMFYXkKDd5Ef+IJFHMr1 ZdDQ== 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=SM0LwWTdLbU0ls+OYpiOTf1ONeyi95kxZLireRQvXbI=; b=aMfg7f49h9YgCjJ4o5xp0L/mmmHIpmRIfw2QMZMl0E83Wx4u5G/ckiotcVGSKSRhFB 3IyirNTL6Peez0zfpZGwr5pORRTY3bzMsYWX3VHu3fmjC8j4/KQXJd07INo2JQqEczCo hfNTc3g3JxbTcnR1JD1sIEiK/rE7QhaGhEYM0bA+TOPZ3KlIKlDyhkEB7T4WP7hrlvMm MmnNRAonTMu1495gN8//HDJZSTACxIkqZ5YMaeikFcdaUmDbXD3rbStepMVdTS35m9KH 1+JsnMlv3g04iAsgTmlE9scropLG3DtH8xb8b3Nemcu7xaVX3+Bke10FFW56tb9RPkDn SC4g== X-Gm-Message-State: AOAM532VH9FuZAmEFPPyfpvc76CHElmIbVBny6TWO1ECuZz3rWAwmIFV 7iVwTzBA7zEANLqKRBXkoLeomwe1CLAMyw== X-Google-Smtp-Source: ABdhPJz5xsEFXBhBW1kWMkPlusfklWGPxiaGyeu3UxjsVkjKeydETx6AFdzqFiGMt5uwnbuciHZ8dg== X-Received: by 2002:a17:90a:2809:b0:1cb:99a8:ffcd with SMTP id e9-20020a17090a280900b001cb99a8ffcdmr2732916pjd.7.1650437481140; Tue, 19 Apr 2022 23:51:21 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:20 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:58 +1000 Message-Id: <20220420065013.222816-25-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 24/39] gdbserver: catch ctrl-C to clean up host state 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. Later patches will add more host state cleanup. Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 4572c689..ef8aa479 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 | SA_NODEFER; + 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