From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1CC9E44104; Wed, 29 May 2024 18:10:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 576C5406B7; Wed, 29 May 2024 18:10:00 +0200 (CEST) Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) by mails.dpdk.org (Postfix) with ESMTP id 5EF81406B6 for ; Wed, 29 May 2024 18:09:58 +0200 (CEST) Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5b970a97e8eso1392112eaf.1 for ; Wed, 29 May 2024 09:09:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716998997; x=1717603797; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aUbR1QuF5VEjLqtQHnxRH2cT49VK+//tGuQs4vv7YHI=; b=UPING+cIH6+y4gDacNKfGc+6V5/nF5CY/dEeWzlVVXENXKZgNy6TCiES2cB8B78eOI iC0dGsAR3dsrbic9ExlTkkXUx8kJTM/Tq4ZfFOEovKm/Mcm0hnL6H/4FUNsBFNvbY37W nzpEuHdTuYQM6x7EAIv+8TsUnvZVP4mxSqGgQ3zdvqfMsjspzIXUztax7M6JKSE0UhEM X291PHWGTe044utftPZBS4uUMUqDBH5UWqqXyISQ383zRhYTEFdXKX3Toy7JfNEvyeID 1l3sumCFtDAZuzAsTtEG1hT8hQRpRnB4xBgyqBlQoTfPu7M/61ViZvAKiahgr1QOdead hK8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716998997; x=1717603797; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aUbR1QuF5VEjLqtQHnxRH2cT49VK+//tGuQs4vv7YHI=; b=AamfF6p/kHDxaj6LPzbUhSCoJPbZVr/yBM/M9NCJB/3nP2doj9ZGLYeqhAiiJDXpcn g5K9MoBdFzzCqdTywoP64q2msz0/xjYY9qA4idF95e07aeoC/C86dK4+xX/irEcfEQSs Q4ZhdzbTz5s10GrvuU9S/9ubDoM2fxjebj1w4SpHVQpz/DgI0qhtQ7ulnnXs/AWY6Bxb 7qmOhOQHNHAhlSPdf0X8JarPX2Hnjqeuks2cRJpUpWQ4jSLdSlaLnGT9CIqswJchGrzu dw1/1BNtBd1E0T9MntKm4WbiT8kFFd/5Km1WoQfPBbdq48vkFF/xqLDw+XnAjhEvOEaQ 9O7g== X-Gm-Message-State: AOJu0Ywj56BGc0W6C5sTYdJJyJLBqxOMTrFk6pSPPyHvRYlYX6YNBXra OmuJk+iVbrTGfRwEUKHihx52VElecT0+bOM85YAh9Zbt3zLRL94YYFQ2xlr/VWrdRlasFGsuz3C T X-Google-Smtp-Source: AGHT+IHlGbtePHocxbmKhvYvAbwMovCZE4GuyjRi56mqEg2hh0LZcuvAaZvRMle+l5482vqztlAS1A== X-Received: by 2002:a05:6358:338e:b0:18f:743b:bb7e with SMTP id e5c5f4694b2df-197e51054bdmr2004026755d.15.1716998997156; Wed, 29 May 2024 09:09:57 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6be6cac52b9sm306713a12.70.2024.05.29.09.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 09:09:56 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v2 2/2] app/pdump: handle SIGTERM and SIGHUP Date: Wed, 29 May 2024 09:08:07 -0700 Message-ID: <20240529160933.282846-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240529160933.282846-1-stephen@networkplumber.org> References: <20240226205143.66702-1-stephen@networkplumber.org> <20240529160933.282846-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The pdump application will leak ring and memory pool if killed by SIGTERM. Like dumpcap, the pdump process should cleanup if process terminates due to being killed or hangup. Fixes: caa7028276b8 ("app/pdump: add tool for packet capturing") Signed-off-by: Stephen Hemminger --- app/pdump/main.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/pdump/main.c b/app/pdump/main.c index 3bdbb8dc78..fa85859703 100644 --- a/app/pdump/main.c +++ b/app/pdump/main.c @@ -571,11 +571,9 @@ disable_primary_monitor(void) } static void -signal_handler(int sig_num) +signal_handler(int sig_num __rte_unused) { - if (sig_num == SIGINT) { - quit_signal = 1; - } + quit_signal = 1; } static inline int @@ -975,6 +973,11 @@ enable_primary_monitor(void) int main(int argc, char **argv) { + struct sigaction action = { + .sa_flags = SA_RESTART, + .sa_handler = signal_handler, + }; + struct sigaction origaction; int diag; int ret; int i; @@ -983,8 +986,14 @@ main(int argc, char **argv) char mp_flag[] = "--proc-type=secondary"; char *argp[argc + 2]; - /* catch ctrl-c so we can print on exit */ - signal(SIGINT, signal_handler); + /* catch ctrl-c so we can cleanup on exit */ + sigemptyset(&action.sa_mask); + sigaction(SIGTERM, &action, NULL); + sigaction(SIGINT, &action, NULL); + sigaction(SIGPIPE, &action, NULL); + sigaction(SIGHUP, NULL, &origaction); + if (origaction.sa_handler == SIG_DFL) + sigaction(SIGHUP, &action, NULL); argp[0] = argv[0]; argp[1] = n_flag; -- 2.43.0