[dpdk-stable] patch 'eal: support strlcpy function' has been queued to LTS release 17.11.5
Yongseok Koh
yskoh at mellanox.com
Fri Nov 30 00:11:17 CET 2018
Hi,
FYI, your patch has been queued to LTS release 17.11.5
Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 12/01/18. So please
shout if anyone has objections.
Also note that after the patch there's a diff of the upstream commit vs the patch applied
to the branch. If the code is different (ie: not only metadata diffs), due for example to
a change in context or macro names, please double check it.
Thanks.
Yongseok
---
>From 7f0e34f991b28cb6d4e37bbc2fd3350a9f6464a4 Mon Sep 17 00:00:00 2001
From: Bruce Richardson <bruce.richardson at intel.com>
Date: Mon, 12 Mar 2018 11:32:59 +0000
Subject: [PATCH] eal: support strlcpy function
[ backported from upstream commit 5364de644a4ba99497edbed05bff942b2b461413 ]
The strncpy function is error prone for doing "safe" string copies, so
we generally try to use "snprintf" instead in the code. The function
"strlcpy" is a better alternative, since it better conveys the
intention of the programmer, and doesn't suffer from the non-null
terminating behaviour of it's n'ed brethern.
The downside of this function is that it is not available by default
on linux, though standard in the BSD's. It is available on most
distros by installing "libbsd" package.
This patch therefore provides the following in rte_string_fns.h to ensure
that strlcpy is available there:
* for BSD, include string.h as normal
* if RTE_USE_LIBBSD is set, include <bsd/string.h>
* if not set, fallback to snprintf for strlcpy
Using make build system, the RTE_USE_LIBBSD is a hard-coded value to "n",
but when using meson, it's automatically set based on what is available
on the platform.
Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
Reviewed-by: Stephen Hemminger <stephen at networkplumber.org>
---
config/common_base | 1 +
devtools/cocci/strlcpy.cocci | 8 +++++++
lib/librte_eal/common/include/rte_string_fns.h | 31 ++++++++++++++++++++++++++
mk/rte.app.mk | 3 +++
4 files changed, 43 insertions(+)
create mode 100644 devtools/cocci/strlcpy.cocci
diff --git a/config/common_base b/config/common_base
index 18ff43c4f..7b4792293 100644
--- a/config/common_base
+++ b/config/common_base
@@ -105,6 +105,7 @@ CONFIG_RTE_EAL_IGB_UIO=n
CONFIG_RTE_EAL_VFIO=n
CONFIG_RTE_MALLOC_DEBUG=n
CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=n
+CONFIG_RTE_USE_LIBBSD=n
#
# Recognize/ignore the AVX/AVX512 CPU flags for performance/power testing.
diff --git a/devtools/cocci/strlcpy.cocci b/devtools/cocci/strlcpy.cocci
new file mode 100644
index 000000000..335e27128
--- /dev/null
+++ b/devtools/cocci/strlcpy.cocci
@@ -0,0 +1,8 @@
+ at use_strlcpy@
+identifier src, dst;
+expression size;
+@@
+(
+- snprintf(dst, size, "%s", src)
++ strlcpy(dst, src, size)
+)
diff --git a/lib/librte_eal/common/include/rte_string_fns.h b/lib/librte_eal/common/include/rte_string_fns.h
index cfca2f8df..7c0ab15a3 100644
--- a/lib/librte_eal/common/include/rte_string_fns.h
+++ b/lib/librte_eal/common/include/rte_string_fns.h
@@ -44,6 +44,8 @@
extern "C" {
#endif
+#include <stdio.h>
+
/**
* Takes string "string" parameter and splits it at character "delim"
* up to maxtokens-1 times - to give "maxtokens" resulting tokens. Like
@@ -74,6 +76,35 @@ int
rte_strsplit(char *string, int stringlen,
char **tokens, int maxtokens, char delim);
+/**
+ * @internal
+ * DPDK-specific version of strlcpy for systems without
+ * libc or libbsd copies of the function
+ */
+static inline size_t
+rte_strlcpy(char *dst, const char *src, size_t size)
+{
+ return snprintf(dst, size, "%s", src);
+}
+
+/* pull in a strlcpy function */
+#ifdef RTE_EXEC_ENV_BSDAPP
+#include <string.h>
+#ifndef __BSD_VISIBLE /* non-standard functions are hidden */
+#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
+#endif
+
+
+#else /* non-BSD platforms */
+#ifdef RTE_USE_LIBBSD
+#include <bsd/string.h>
+
+#else /* no BSD header files, create own */
+#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
+
+#endif /* RTE_USE_LIBBSD */
+#endif /* BSDAPP */
+
#ifdef __cplusplus
}
#endif
diff --git a/mk/rte.app.mk b/mk/rte.app.mk
index 6a6a7452e..98ab58de0 100644
--- a/mk/rte.app.mk
+++ b/mk/rte.app.mk
@@ -218,6 +218,9 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) += -lrt
ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP)$(CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES),yy)
_LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) += -lnuma
endif
+ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP)$(CONFIG_RTE_USE_LIBBSD),yy)
+_LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) += -lbsd
+endif
_LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED) += -lm
_LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED) += -lrt
_LDLIBS-$(CONFIG_RTE_LIBRTE_MEMBER) += -lm
--
2.11.0
---
Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- - 2018-11-29 15:01:48.885144145 -0800
+++ 0083-eal-support-strlcpy-function.patch 2018-11-29 15:01:45.230957000 -0800
@@ -1,8 +1,10 @@
-From 5364de644a4ba99497edbed05bff942b2b461413 Mon Sep 17 00:00:00 2001
+From 7f0e34f991b28cb6d4e37bbc2fd3350a9f6464a4 Mon Sep 17 00:00:00 2001
From: Bruce Richardson <bruce.richardson at intel.com>
Date: Mon, 12 Mar 2018 11:32:59 +0000
Subject: [PATCH] eal: support strlcpy function
+[ backported from upstream commit 5364de644a4ba99497edbed05bff942b2b461413 ]
+
The strncpy function is error prone for doing "safe" string copies, so
we generally try to use "snprintf" instead in the code. The function
"strlcpy" is a better alternative, since it better conveys the
@@ -27,43 +29,24 @@
Reviewed-by: Stephen Hemminger <stephen at networkplumber.org>
---
config/common_base | 1 +
- config/meson.build | 7 ++++++
devtools/cocci/strlcpy.cocci | 8 +++++++
lib/librte_eal/common/include/rte_string_fns.h | 31 ++++++++++++++++++++++++++
mk/rte.app.mk | 3 +++
- 5 files changed, 50 insertions(+)
+ 4 files changed, 43 insertions(+)
create mode 100644 devtools/cocci/strlcpy.cocci
diff --git a/config/common_base b/config/common_base
-index 348228b29..c09c7cf88 100644
+index 18ff43c4f..7b4792293 100644
--- a/config/common_base
+++ b/config/common_base
-@@ -76,6 +76,7 @@ CONFIG_RTE_EAL_VFIO=n
- CONFIG_RTE_MAX_VFIO_GROUPS=64
+@@ -105,6 +105,7 @@ CONFIG_RTE_EAL_IGB_UIO=n
+ CONFIG_RTE_EAL_VFIO=n
CONFIG_RTE_MALLOC_DEBUG=n
CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=n
+CONFIG_RTE_USE_LIBBSD=n
#
# Recognize/ignore the AVX/AVX512 CPU flags for performance/power testing.
-diff --git a/config/meson.build b/config/meson.build
-index f8c67578d..77af5d897 100644
---- a/config/meson.build
-+++ b/config/meson.build
-@@ -38,6 +38,13 @@ if numa_dep.found() and cc.has_header('numaif.h')
- dpdk_extra_ldflags += '-lnuma'
- endif
-
-+# check for strlcpy
-+if host_machine.system() == 'linux' and cc.find_library('bsd', required: false).found()
-+ dpdk_conf.set('RTE_USE_LIBBSD', 1)
-+ add_project_link_arguments('-lbsd', language: 'c')
-+ dpdk_extra_ldflags += '-lbsd'
-+endif
-+
- # add -include rte_config to cflags
- add_project_arguments('-include', 'rte_config.h', language: 'c')
-
diff --git a/devtools/cocci/strlcpy.cocci b/devtools/cocci/strlcpy.cocci
new file mode 100644
index 000000000..335e27128
@@ -79,10 +62,10 @@
++ strlcpy(dst, src, size)
+)
diff --git a/lib/librte_eal/common/include/rte_string_fns.h b/lib/librte_eal/common/include/rte_string_fns.h
-index e97047a47..fcbb42e00 100644
+index cfca2f8df..7c0ab15a3 100644
--- a/lib/librte_eal/common/include/rte_string_fns.h
+++ b/lib/librte_eal/common/include/rte_string_fns.h
-@@ -15,6 +15,8 @@
+@@ -44,6 +44,8 @@
extern "C" {
#endif
@@ -91,7 +74,7 @@
/**
* Takes string "string" parameter and splits it at character "delim"
* up to maxtokens-1 times - to give "maxtokens" resulting tokens. Like
-@@ -45,6 +47,35 @@ int
+@@ -74,6 +76,35 @@ int
rte_strsplit(char *string, int stringlen,
char **tokens, int maxtokens, char delim);
@@ -128,10 +111,10 @@
}
#endif
diff --git a/mk/rte.app.mk b/mk/rte.app.mk
-index a9b4b0502..228dc19a7 100644
+index 6a6a7452e..98ab58de0 100644
--- a/mk/rte.app.mk
+++ b/mk/rte.app.mk
-@@ -255,6 +255,9 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) += -lrt
+@@ -218,6 +218,9 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) += -lrt
ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP)$(CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES),yy)
_LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) += -lnuma
endif
More information about the stable
mailing list