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 AABBAA034E; Wed, 9 Feb 2022 16:54:51 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2FF8541144; Wed, 9 Feb 2022 16:54:51 +0100 (CET) Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by mails.dpdk.org (Postfix) with ESMTP id EDAA141143 for ; Wed, 9 Feb 2022 16:54:49 +0100 (CET) Received: by mail-pl1-f178.google.com with SMTP id w20so2542111plq.12 for ; Wed, 09 Feb 2022 07:54:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WNphjM8lxQWFcsGPP8709O6U4siVeHQEtoD3vDscrsI=; b=K/wOxNbQRxTDox7qkT1ffmcd8yWN9y7ZxNfpI9y+QDoyQ3iW3HbMM6Tu+t3b56jtZJ B471e127bzMvih0I9mW0eCwPkOusivQSAwinc1S479DFEAogK/dp58PEkUgcqcEt+Gym 1o2uanhp2vn0ngTdGu/CxAwkGm4Qso3+tacLdo2ezwz3RdpumwtKkpU1T1Oh3oaRoM4h Q2RgmGksflcZElk0wYTG0pekUVdPCuI0SFh7zqFghMV0RFqyhXnCJmilZvkMIrmLzCXe m5SutLXhko9QX/yGl4KobDFW3Nyp2jz8/RWjVJhfGHPR5JTfoN/cnQT8hVaH+07U9cJg QDVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WNphjM8lxQWFcsGPP8709O6U4siVeHQEtoD3vDscrsI=; b=SWDUUb1+PZPIvfOYHlHMk5EBkzItareHemeSb5aicpFJjsO2rmbaPgiuLEO168QM1n 745Tpw6V2JWRqBEKx4G9OdBSHhTiED5QCrzix2A2roVwjlQBtH70iygJbzQrLLM9UKXd ZW9WAXWJWnc6Jmo1Se1wqgDXZVho6X5L3Z2e8uxHHaGuZF6LhhrxwFEp2nxyn39/Yx2x MjVvjxLAq1jqOX1THvoHRg4e7W+OKrSJUfv/Vdvby92q1/59BtAa8bfyfaGmk+W/qPCw 4+Rkz0WJA4tkh4N27ZSETLYgyoIsZ7H3dhefhbfTvTGDk1LR2oWDNqYcysgBzDnn/rCK qtKw== X-Gm-Message-State: AOAM533N9V6S47a2kngRR5/WOnot2v/e7MCZ5c4cPKP0Ytohq+Y82OF8 sarrE8SEXErZZ0L1S3oX86TRp3oRN9497wfU X-Google-Smtp-Source: ABdhPJxjpK9BmnCIZpeYnYxIVL37bNmqqBIuKqMU7crWU79P1tJtog1XikEnTzgFAXlcWSrkVAIDDg== X-Received: by 2002:a17:90b:4a09:: with SMTP id kk9mr4116415pjb.107.1644422088550; Wed, 09 Feb 2022 07:54:48 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id c17sm21583195pfv.68.2022.02.09.07.54.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 07:54:48 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Stephen Hemminger Subject: [PATCH v2] Subject: eal: remove unnecessary argv[0] handling Date: Wed, 9 Feb 2022 07:54:43 -0800 Message-Id: <20220209155443.230369-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220202194738.404876-1-stephen@networkplumber.org> References: <20220202194738.404876-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 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 --- 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