From patchwork Mon Feb 26 20:49:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 137293 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AC25343BF6; Mon, 26 Feb 2024 21:52:00 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5FBA342E57; Mon, 26 Feb 2024 21:51:56 +0100 (CET) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mails.dpdk.org (Postfix) with ESMTP id 7409A402CC for ; Mon, 26 Feb 2024 21:51:54 +0100 (CET) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1dc0d11d1b7so27710745ad.2 for ; Mon, 26 Feb 2024 12:51:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1708980713; x=1709585513; 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=YCdLEaG5eE8vaeu+2OxtfS28AWX0rOgbRs8sMhWeP5k=; b=h9LM5TLN95z7fLWk2ztun8qRHLBfHhvhdR2xUv+lxhP0HwDbwWgO1seCdufg8V9CxA BK0qz/l1m110mgsWdo9MgVtU9FsJotp9ENDV1MhvbSoqEyH8oVuPT5MGg4UIGow7EudV ElSFLkxauGzfz9/oY7pTPsVaUkA4bWQeRlS2GBVeve+I+x7A6xN0i7ycHImytrRPO9GT MGx9aE5a33bd2RJe0fkaSEsUg+INLvQknmIt0XJsZ0v43Ma02sSVvEFMCtXJ5POXlMU8 j79r/RuysxX8DxawRkKG4Ra/15DhuXkbn02712il85atapOi41tqlnwO/efDq3czjEL3 eAUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708980713; x=1709585513; 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=YCdLEaG5eE8vaeu+2OxtfS28AWX0rOgbRs8sMhWeP5k=; b=IhD51KrEZwZzsaJjZqzc0wE8caodshzulDEx34RMCrsEacT0hYOsmwhALvtWr2C+vk 4sdoCDux83hLnXLhphrekYnQuP4cblj6j/zyqgh1BwBGsRq/SRNNQY7a6Y8FWmsHJQHe DzeDqDHzjbZ2WYwUcyAyL7iwtRq0HMOFfZDrx4MB0FfNHdTAjXRHcbCewr/MaK0QNlHg y7EoKAqqpvmWZFG0pFCDkBJpA2yQdl2guJ6hfDe3Kc9OURXhbl3W1QjyOMrSGcI6zxDk bq+r6U6C/BlA9TSJ1NIXR6zOxaudSA7PTvNnBcBMLZFw3PfoxcZ3PJ6wwkdaHRswqKDm +xUQ== X-Gm-Message-State: AOJu0YxDgLm3bc4yoyaLCmi9g7MF/iyPDPtPfvnqShIvea0HDdTE1xNu /7xSUGT1uifFXYWlRW0XjpjzIu9zfnn3fzezEXQcRglAxFVBP8erIsYCPJ5np8e0fw4F+RiDcdv u X-Google-Smtp-Source: AGHT+IFOEHcevhcYogYA8TVNDntNikwAKIzvQqR2BnyOny24ydPI1qzWm+2C5gDGxxA9bLGyUyU0xw== X-Received: by 2002:a17:903:2409:b0:1dc:81b8:cc1e with SMTP id e9-20020a170903240900b001dc81b8cc1emr7419844plo.60.1708980713650; Mon, 26 Feb 2024 12:51:53 -0800 (PST) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id 5-20020a170902ee4500b001db3efca159sm109615plo.132.2024.02.26.12.51.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 12:51:53 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Isaac Boukris , Reshma Pattan Subject: [PATCH 1/2] app/dumpcap: handle SIGTERM and SIGHUP Date: Mon, 26 Feb 2024 12:49:48 -0800 Message-ID: <20240226205143.66702-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226205143.66702-1-stephen@networkplumber.org> References: <20240226205143.66702-1-stephen@networkplumber.org> MIME-Version: 1.0 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 If application is killed (SIGTERM), or the console session ends (SIGHUP) or the write to the output file fails (SIGPIPE) then do cleanup before exiting. This also makes DPDK dumpcap behave more like Wireshark dumpcap. Suggested-by: Isaac Boukris Signed-off-by: Stephen Hemminger --- app/dumpcap/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index d57db0589a3f..76c747511444 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -939,6 +939,11 @@ int main(int argc, char **argv) { struct rte_ring *r; struct rte_mempool *mp; + struct sigaction action = { + .sa_flags = SA_RESTART, + .sa_handler = signal_handler, + }; + struct sigaction origaction; dumpcap_out_t out; char *p; @@ -964,8 +969,13 @@ int main(int argc, char **argv) compile_filters(); - signal(SIGINT, signal_handler); - signal(SIGPIPE, SIG_IGN); + 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); enable_primary_monitor(); From patchwork Mon Feb 26 20:49:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 137294 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EA56643BF6; Mon, 26 Feb 2024 21:52:05 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7478242E76; Mon, 26 Feb 2024 21:51:57 +0100 (CET) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id 4B3E142E21 for ; Mon, 26 Feb 2024 21:51:55 +0100 (CET) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1dc99a75be6so12549515ad.3 for ; Mon, 26 Feb 2024 12:51:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1708980714; x=1709585514; 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=ONDJULtuKfy2cHyiXCr/Q6vfY1X6kDA4bHcvcA37dr4=; b=dIEHT7iTRuPjwaJrflUTXd4DUie/qGV2qwN5TOPwfka2c32fEAKPm2uHyCkP3wPa9k jVvZ9I8GRg8Sd3q9rixB3GCeaSpNhfzR2VZwhPrsuAcd9px03uQyKqyY8sLEyqI68vw3 2u18RnLgTAm+sBa9BFuLbQc4BP+ElpVYDRfqSX4vJ1ERf3WI6V8tuTNgLdUKZl2lKw9k qsAYX7aspIiCj68AgER1/eYSgPpiVLF3wP/pCnPRWMW+Iv0uHiwBLEqHucANlptEvNII k88frkaTQvMg3jmbeXSZuh2R/RY6nXdXjHNF30IVRAt0Myhnp8TcCmunASSH9WIPRvYK c4rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708980714; x=1709585514; 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=ONDJULtuKfy2cHyiXCr/Q6vfY1X6kDA4bHcvcA37dr4=; b=ccKOKuQJcTXej03OpkkX3slXxnQZG0CNmLd5NnOFi/6eimX124cf40yD9MVzkPxbpg +qHMcdFVbkx2D8zFfVqzC7sDSQUVYcJRDcqqj5GJOAg9IGb7apHxs4VXorPHTXHm70MV J7+wC3JcVI5dQ/C6e7QGwCIdXdDIS6LjXGi+0EcvR2fx8xlnH4qj73JZ4epUoaCaBMD+ fA1U4wtB7MSibLr1e17QTtTT8ME6UDccy6J8ZWwx4OcbAS6JoAIRM4hZScPI/AU6u0MJ LUzvsV5+l1G2AIqbUXQeKaPsbDVd/snU6nv331KFHLZM7U2uk6nqN2i1HJsX6qEVfom9 3NnQ== X-Gm-Message-State: AOJu0YxEO61X0XuCIQTULmm1vO5udsGCJfaHxuaeDatklGOKSBMHbC78 05UhmH1hql3bEqtoxGvAhkchL3K4IL4svSpc/SSM2zkDVLIyIHbzJpc1IolVARnRuBOicQn23VQ I X-Google-Smtp-Source: AGHT+IEv1UGnXpWA3MNX0r7hQZ/S+A8fXRUpNRHI9ccX2RsvpbVxgr7gH8lU9MPpA8vpdaY+IXB56A== X-Received: by 2002:a17:902:a383:b0:1d9:8f6e:86e8 with SMTP id x3-20020a170902a38300b001d98f6e86e8mr7337685pla.69.1708980714445; Mon, 26 Feb 2024 12:51:54 -0800 (PST) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id 5-20020a170902ee4500b001db3efca159sm109615plo.132.2024.02.26.12.51.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 12:51:54 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH 2/2] app/pdump: handle SIGTERM and SIGHUP Date: Mon, 26 Feb 2024 12:49:49 -0800 Message-ID: <20240226205143.66702-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226205143.66702-1-stephen@networkplumber.org> References: <20240226205143.66702-1-stephen@networkplumber.org> MIME-Version: 1.0 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 Like dumpcap, the pdump process should cleanup if process terminates due to being killed or hangup. 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 a9205e130bb1..3592f8a865ad 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;