From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Stephen Hemminger <sthemmin@microsoft.com>
Subject: [PATCH v2] Subject: eal: remove unnecessary argv[0] handling
Date: Wed, 9 Feb 2022 07:54:43 -0800 [thread overview]
Message-ID: <20220209155443.230369-1-stephen@networkplumber.org> (raw)
In-Reply-To: <20220202194738.404876-1-stephen@networkplumber.org>
The rte_eal_init function only evalutes 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.
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.
Parsing argv[0] is unnecessary because the function openlog()
already determines the log identifier from program name if
NULL is passed.
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.)
Since eal_log_init() is internal just drop the unused argument.
Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
lib/eal/common/eal_log.h | 2 +-
lib/eal/linux/eal.c | 6 +-----
lib/eal/linux/eal_log.c | 4 ++--
lib/eal/windows/eal.c | 2 +-
lib/eal/windows/eal_log.c | 2 +-
5 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/lib/eal/common/eal_log.h b/lib/eal/common/eal_log.h
index c784fa604389..d0282b3258da 100644
--- a/lib/eal/common/eal_log.h
+++ b/lib/eal/common/eal_log.h
@@ -11,7 +11,7 @@
/*
* Initialize the default log stream.
*/
-int eal_log_init(const char *id, int facility);
+int eal_log_init(int facility);
/*
* Determine where log data is written when no call to rte_openlog_stream.
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 9c8395ab14d0..a6e8c5793334 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(internal_conf->syslog_facility) < 0) {
rte_eal_init_alert("Cannot init logging.");
rte_errno = ENOMEM;
__atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
diff --git a/lib/eal/linux/eal_log.c b/lib/eal/linux/eal_log.c
index c0aa1007c4df..e5cc10737b37 100644
--- a/lib/eal/linux/eal_log.c
+++ b/lib/eal/linux/eal_log.c
@@ -46,7 +46,7 @@ static cookie_io_functions_t console_log_func = {
* once memzones are available.
*/
int
-eal_log_init(const char *id, int facility)
+eal_log_init(int facility)
{
FILE *log_stream;
@@ -54,7 +54,7 @@ eal_log_init(const char *id, int facility)
if (log_stream == NULL)
return -1;
- openlog(id, LOG_NDELAY | LOG_PID, facility);
+ openlog(NULL, LOG_NDELAY | LOG_PID, facility);
eal_log_set_default(log_stream);
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index ca3c41aaa7f1..3133a934dd3c 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -280,7 +280,7 @@ rte_eal_init(int argc, char **argv)
enum rte_iova_mode iova_mode;
int ret;
- eal_log_init(NULL, 0);
+ eal_log_init(0);
eal_log_level_parse(argc, argv);
diff --git a/lib/eal/windows/eal_log.c b/lib/eal/windows/eal_log.c
index d4ea47f1c824..df995c337998 100644
--- a/lib/eal/windows/eal_log.c
+++ b/lib/eal/windows/eal_log.c
@@ -8,7 +8,7 @@
/* set the log to default function, called during eal init process. */
int
-eal_log_init(__rte_unused const char *id, __rte_unused int facility)
+eal_log_init(__rte_unused int facility)
{
rte_openlog_stream(stderr);
--
2.34.1
next prev parent reply other threads:[~2022-02-09 15:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-02 19:47 [PATCH] " 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 ` Stephen Hemminger [this message]
2022-02-09 20:41 ` [PATCH v3] eal: simplify " Stephen Hemminger
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=20220209155443.230369-1-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=sthemmin@microsoft.com \
/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;
as well as URLs for NNTP newsgroup(s).