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 D0E1945562; Wed, 3 Jul 2024 17:47:53 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BB6C242E5D; Wed, 3 Jul 2024 17:47:53 +0200 (CEST) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id 1F3AD42E5D for ; Wed, 3 Jul 2024 17:47:52 +0200 (CEST) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1fa9ecfb321so35726775ad.0 for ; Wed, 03 Jul 2024 08:47:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1720021671; x=1720626471; 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=xdLacqVPFVdyoOQkjEF6f43ctMDzJj8a9cBSxURYhNmBU88EyEBYQqaxW7AK/gZTZt WiQnAvRrH/HilzcrAXxrmzEolAEDvJqU6Os3lDeVFpmXpRUfT7zlEetXFQyLUO96bWBr nOHwVZeVTDc/2ewY1syYbAC/vgkgGvEQ8tqsvy1MYsSPnyiy3DUW6cHjjdnNokLixr1o RmJxQCacFpeeCwY6yVN4rnEGYaHb2k3QlgnJgyVWeiTCbR2ixpfwxMm6Tnvi2wt+nWMs 1bgaEVOB5hY5eyyroX1ceflmQ3/cgeBi/8zDYg90QVP2A91W5RD75WN0E9cUrkW24dMY 7ACg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720021671; x=1720626471; 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=qo99+W89CQUwYcCa0n0CDFKkWKi1PQxb0qjTmGGJUB/RBXOaja1KW/VvnkvsIkjuSl 4arevWwWDwTIUZvHuMIii71K7mPdwybzs/D/upyemdfHaCHhe2LO9BTBzr3b8YKcB6fK SMx3sz00/FM8M57m4kT8oheoaYLQI56bDCM7gYqCosek6z+jKm4EfF6Z7TQltmD0LNec 4s+1U8ndaLarWt0c46sHt0ReuhYqGqw7yF4GDYAl9ddlrhCY96jzcVYJf8jDpz2eHsrO BYOaWSHLHN1m58yj03Y9BzXO3t7u0wRTEcmwPVK4vtvKsbHXIXlLtITrKw6DYPM7naSd 2BJQ== X-Gm-Message-State: AOJu0YwqGmvfK/Q3iDwEtvNqNE0fyp+y/ybt4LjsyE0dEuqouQ17piQC H3lcQR5ZcGG93zRxEz1xd14PHoRV+NWsbEWaaDy9VntyWmUcqO218N73kEQ8vQTy9cy0QqajgrG ZNnc= X-Google-Smtp-Source: AGHT+IHXB9Dgfu9rST1LYdD/SRwDYNe+hgRwlRLNp4iac/AoNw+t9bUBsy+JayPbrJ5CThPCCuus/A== X-Received: by 2002:a17:902:d50c:b0:1fa:b511:5d44 with SMTP id d9443c01a7336-1fadbce6591mr74951525ad.46.1720021671196; Wed, 03 Jul 2024 08:47:51 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb0bd80588sm24653345ad.7.2024.07.03.08.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 08:47:50 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v3 2/3] app/pdump: handle SIGTERM and SIGHUP Date: Wed, 3 Jul 2024 08:45:44 -0700 Message-ID: <20240703154705.19192-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240703154705.19192-1-stephen@networkplumber.org> References: <20240529160933.282846-1-stephen@networkplumber.org> <20240703154705.19192-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