DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] eal: remove unnecessary argv[0] handling
@ 2022-02-02 19:47 Stephen Hemminger
  2022-02-09 14:58 ` Thomas Monjalon
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Stephen Hemminger @ 2022-02-02 19:47 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Stephen Hemminger

The rte_eal_init function looks at argv[0] to determine
the program name to pass to the log init function.
This is both unnecessary and in a corner case a problem.

Parsing argv[0] is unnecessary because the function openlog()
already determines the log identifier from program name if
NULL is passed, see openlog man page:
    The string pointed to by ident is prepended to every message, and is
    typically set to the program name. If ident is NULL, the program name
    is used.  (POSIX.1-2008 does not specify the behavior when ident is
    NULL.)

It is possible to run a program with argc=0 and argv[0]=NULL.
This would cause rte_eal_init() to dereference a null pointer.
Not a really useful feature, but better for DPDK get a SEGV
if it doesn't need to.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 lib/eal/linux/eal.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 60b49248388e..6bc7cdf440b8 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -966,8 +966,6 @@ rte_eal_init(int argc, char **argv)
 	pthread_t thread_id;
 	static uint32_t run_once;
 	uint32_t has_run = 0;
-	const char *p;
-	static char logid[PATH_MAX];
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
 	char thread_name[RTE_MAX_THREAD_NAME_LEN];
 	bool phys_addrs;
@@ -989,8 +987,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	p = strrchr(argv[0], '/');
-	strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid));
 	thread_id = pthread_self();
 
 	eal_reset_internal_config(internal_conf);
@@ -1165,7 +1161,7 @@ rte_eal_init(int argc, char **argv)
 #endif
 	}
 
-	if (eal_log_init(logid, internal_conf->syslog_facility) < 0) {
+	if (eal_log_init(NULL, internal_conf->syslog_facility) < 0) {
 		rte_eal_init_alert("Cannot init logging.");
 		rte_errno = ENOMEM;
 		__atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-02-10  7:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 19:47 [PATCH] eal: remove unnecessary argv[0] handling Stephen Hemminger
2022-02-09 14:58 ` Thomas Monjalon
2022-02-09 15:36   ` Stephen Hemminger
2022-02-09 15:45   ` Stephen Hemminger
2022-02-09 18:51     ` Thomas Monjalon
2022-02-09 19:29       ` Stephen Hemminger
2022-02-10  7:57         ` Thomas Monjalon
2022-02-09 15:54 ` [PATCH v2] Subject: " Stephen Hemminger
2022-02-09 20:41 ` [PATCH v3] eal: simplify " Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).