DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	stable@dpdk.org, Reshma Pattan <reshma.pattan@intel.com>
Subject: [PATCH 4/4] app/dumpcap: do not use rte_exit before EAL init
Date: Tue, 17 Nov 2026 08:06:22 -0800	[thread overview]
Message-ID: <20261117160727.388470-5-stephen@networkplumber.org> (raw)
In-Reply-To: <20261117160727.388470-1-stephen@networkplumber.org>

Errors in command line options and in setting up the EAL arguments
were reported with rte_exit() or rte_panic(), which call EAL cleanup
or dump EAL state before EAL has been initialized.

Use a simple helper which prints the message and exits instead.

Fixes: cbb44143be74 ("app/dumpcap: add new packet capture application")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/dumpcap/main.c | 57 +++++++++++++++++++++++++++-------------------
 1 file changed, 33 insertions(+), 24 deletions(-)

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index 1f9f03c7a3..49979fbf37 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -12,6 +12,7 @@
 #include <inttypes.h>
 #include <limits.h>
 #include <signal.h>
+#include <stdarg.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -163,6 +164,22 @@ static const char *version(void)
 	return str;
 }
 
+/*
+ * Exit with error message, for errors before EAL is initialized
+ * where rte_exit() can not be used.
+ */
+static __rte_noreturn __rte_format_printf(1, 2)
+void early_exit(const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+
+	exit(EXIT_FAILURE);
+}
+
 /* Parse numeric argument from command line */
 static unsigned long get_uint(const char *arg, const char *name,
 			     unsigned int limit)
@@ -172,13 +189,11 @@ static unsigned long get_uint(const char *arg, const char *name,
 
 	u = strtoul(arg, &endp, 0);
 	if (*arg == '\0' || *endp != '\0')
-		rte_exit(EXIT_FAILURE,
-			 "Specified %s \"%s\" is not a valid number\n",
-			 name, arg);
+		early_exit("Specified %s \"%s\" is not a valid number\n",
+			   name, arg);
 	if (limit && u > limit)
-		rte_exit(EXIT_FAILURE,
-			 "Specified %s \"%s\" is too large (greater than %u)\n",
-			 name, arg, limit);
+		early_exit("Specified %s \"%s\" is too large (greater than %u)\n",
+			   name, arg, limit);
 
 	return u;
 }
@@ -190,24 +205,21 @@ static void auto_stop(char *opt)
 
 	value = strchr(opt, ':');
 	if (value == NULL)
-		rte_exit(EXIT_FAILURE,
-			 "Missing colon in auto stop parameter\n");
+		early_exit("Missing colon in auto stop parameter\n");
 
 	*value++ = '\0';
 	if (strcmp(opt, "duration") == 0) {
 		double interval = strtod(value, &endp);
 
 		if (*value == '\0' || *endp != '\0' || interval <= 0)
-			rte_exit(EXIT_FAILURE,
-				 "Invalid duration \"%s\"\n", value);
+			early_exit("Invalid duration \"%s\"\n", value);
 		stop.duration = interval;
 	} else if (strcmp(opt, "filesize") == 0) {
 		stop.size = get_uint(value, "filesize", 0) * 1024;
 	} else if (strcmp(opt, "packets") == 0) {
 		stop.packets = get_uint(value, "packets", 0);
 	} else {
-		rte_exit(EXIT_FAILURE,
-			 "Unknown autostop parameter \"%s\"\n", opt);
+		early_exit("Unknown autostop parameter \"%s\"\n", opt);
 	}
 }
 
@@ -217,11 +229,11 @@ static struct interface *add_interface(const char *name)
 	struct interface *intf;
 
 	if (strlen(name) >= RTE_ETH_NAME_MAX_LEN)
-		rte_exit(EXIT_FAILURE, "invalid name for interface: '%s'\n", name);
+		early_exit("invalid name for interface: '%s'\n", name);
 
 	intf = malloc(sizeof(*intf));
 	if (!intf)
-		rte_exit(EXIT_FAILURE, "no memory for interface\n");
+		early_exit("no memory for interface\n");
 
 	memset(intf, 0, sizeof(*intf));
 	rte_strscpy(intf->name, name, sizeof(intf->name));
@@ -381,13 +393,11 @@ static void parse_opts(int argc, char **argv)
 				tmp_dir = optarg;
 			} else if (!strcmp(longopt, "ifdescr")) {
 				if (last_intf == NULL)
-					rte_exit(EXIT_FAILURE,
-						 "--ifdescr must be specified after a -i option\n");
+					early_exit("--ifdescr must be specified after a -i option\n");
 				last_intf->ifdescr = optarg;
 			} else if (!strcmp(longopt, "ifname")) {
 				if (last_intf == NULL)
-					rte_exit(EXIT_FAILURE,
-						 "--ifname must be specified after a -i option\n");
+					early_exit("--ifname must be specified after a -i option\n");
 				last_intf->ifname = optarg;
 			} else {
 				usage();
@@ -399,8 +409,7 @@ static void parse_opts(int argc, char **argv)
 			auto_stop(optarg);
 			break;
 		case 'b':
-			rte_exit(EXIT_FAILURE,
-				 "multiple files not implemented\n");
+			early_exit("multiple files not implemented\n");
 			break;
 		case 'c':
 			stop.packets = get_uint(optarg, "packet_count", 0);
@@ -629,7 +638,7 @@ static void dpdk_init(void)
 	/* DPDK API requires mutable versions of command line arguments. */
 	eal_argv = calloc(eal_argc + 1, sizeof(char *));
 	if (eal_argv == NULL)
-		rte_panic("No memory\n");
+		early_exit("No memory\n");
 
 	eal_argv[0] = strdup(progname);
 	for (i = 1; i < RTE_DIM(args); i++)
@@ -647,7 +656,7 @@ static void dpdk_init(void)
 
 	for (i = 0; i < (unsigned int)eal_argc; i++) {
 		if (eal_argv[i] == NULL)
-			rte_panic("No memory\n");
+			early_exit("No memory\n");
 	}
 
 	/*
@@ -656,10 +665,10 @@ static void dpdk_init(void)
 	 */
 	if (lcore_arg == NULL &&
 	    rte_thread_get_affinity_by_id(rte_thread_self(), &cpuset) != 0)
-		rte_panic("rte_thread_getaffinity failed\n");
+		early_exit("rte_thread_getaffinity failed\n");
 
 	if (rte_eal_init(eal_argc, eal_argv) < 0)
-		rte_exit(EXIT_FAILURE, "EAL init failed: is primary process running?\n");
+		early_exit("EAL init failed: is primary process running?\n");
 
 	/*
 	 * Register pdump callback handler.
-- 
2.53.0


      parent reply	other threads:[~2026-11-17 16:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 16:06 [PATCH 0/4] app/dumpcap: assorted fixes Stephen Hemminger
2026-11-17 16:06 ` [PATCH 1/4] app/dumpcap: fix packet count overshoot Stephen Hemminger
2026-11-17 16:06 ` [PATCH 2/4] app/dumpcap: fix capture duration Stephen Hemminger
2026-11-17 16:06 ` [PATCH 3/4] app/dumpcap: fix pcap timestamps Stephen Hemminger
2026-11-17 16:06 ` Stephen Hemminger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117160727.388470-5-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=reshma.pattan@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox