[v5,03/52] eal: replace strerror with reentrant version

Message ID 20241104111037.3632161-4-huangdengdui@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series replace strerror |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

huangdengdui Nov. 4, 2024, 11:09 a.m. UTC
The function strerror() is insecure in a multi-thread environment.
This patch uses strerror_r() to replace it.

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
---
 lib/eal/common/eal_common_fbarray.c     |   6 +-
 lib/eal/common/eal_common_options.c     |  19 ++--
 lib/eal/common/eal_common_proc.c        |  32 +++++--
 lib/eal/common/eal_common_trace_utils.c |  14 ++-
 lib/eal/freebsd/eal.c                   |  10 +-
 lib/eal/freebsd/eal_interrupts.c        |  26 ++++--
 lib/eal/freebsd/eal_memory.c            |   6 +-
 lib/eal/freebsd/eal_timer.c             |  22 +++--
 lib/eal/include/rte_errno.h             |   3 +
 lib/eal/linux/eal.c                     |  25 +++--
 lib/eal/linux/eal_dev.c                 |   5 +-
 lib/eal/linux/eal_hugepage_info.c       |  17 ++--
 lib/eal/linux/eal_interrupts.c          |  51 +++++++---
 lib/eal/linux/eal_memalloc.c            | 118 ++++++++++++++++++------
 lib/eal/linux/eal_memory.c              | 102 ++++++++++++++------
 lib/eal/linux/eal_timer.c               |   6 +-
 lib/eal/linux/eal_vfio.c                | 102 ++++++++++++++------
 lib/eal/unix/eal_filesystem.c           |  12 ++-
 lib/eal/unix/eal_unix_memory.c          |  19 +++-
 lib/eal/unix/rte_thread.c               |  18 ++--
 20 files changed, 446 insertions(+), 167 deletions(-)
  

Patch

diff --git a/lib/eal/common/eal_common_fbarray.c b/lib/eal/common/eal_common_fbarray.c
index 22b43073c6..f288bd9163 100644
--- a/lib/eal/common/eal_common_fbarray.c
+++ b/lib/eal/common/eal_common_fbarray.c
@@ -985,6 +985,7 @@  rte_fbarray_detach(struct rte_fbarray *arr)
 int
 rte_fbarray_destroy(struct rte_fbarray *arr)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct mem_area *tmp = NULL;
 	size_t mmap_len;
 	int fd, ret;
@@ -1040,8 +1041,9 @@  rte_fbarray_destroy(struct rte_fbarray *arr)
 		/* we're OK to destroy the file */
 		eal_get_fbarray_path(path, sizeof(path), arr->name);
 		if (unlink(path)) {
-			EAL_LOG(DEBUG, "Cannot unlink fbarray: %s",
-				strerror(errno));
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+			EAL_LOG(DEBUG, "Cannot unlink fbarray: %s", errmsg);
 			rte_errno = errno;
 			/*
 			 * we're still holding an exclusive lock, so drop it to
diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c
index f1a5e329a5..f516b72fbf 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -44,6 +44,7 @@ 
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include "eal_trace.h"
 #endif
+#include <rte_errno.h>
 
 #define BITS_PER_HEX 4
 #define LCORE_OPT_LST 1
@@ -401,6 +402,7 @@  eal_plugins_init(void)
 static int
 eal_plugindir_init(const char *path)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	DIR *d = NULL;
 	struct dirent *dent = NULL;
 	char sopath[PATH_MAX];
@@ -410,8 +412,9 @@  eal_plugindir_init(const char *path)
 
 	d = opendir(path);
 	if (d == NULL) {
-		EAL_LOG(ERR, "failed to open directory %s: %s",
-			path, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "failed to open directory %s: %s", path, errmsg);
 		return -1;
 	}
 
@@ -443,6 +446,7 @@  eal_plugindir_init(const char *path)
 static int
 verify_perms(const char *dirpath)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct stat st;
 
 	/* if not root, check down one level first */
@@ -462,8 +466,9 @@  verify_perms(const char *dirpath)
 
 	/* call stat to check for permissions and ensure not world writable */
 	if (stat(dirpath, &st) != 0) {
-		EAL_LOG(ERR, "Error with stat on %s, %s",
-				dirpath, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "Error with stat on %s, %s", dirpath, errmsg);
 		return -1;
 	}
 	if (st.st_mode & S_IWOTH) {
@@ -479,6 +484,7 @@  verify_perms(const char *dirpath)
 static void *
 eal_dlopen(const char *pathname)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	void *retval = NULL;
 	char *realp = realpath(pathname, NULL);
 
@@ -490,8 +496,9 @@  eal_dlopen(const char *pathname)
 		return retval;
 	}
 	if (realp == NULL) {
-		EAL_LOG(ERR, "Error with realpath for %s, %s",
-				pathname, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "Error with realpath for %s, %s", pathname, errmsg);
 		goto out;
 	}
 	if (strnlen(realp, PATH_MAX) == PATH_MAX) {
diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c
index d24093937c..0e857102c6 100644
--- a/lib/eal/common/eal_common_proc.c
+++ b/lib/eal/common/eal_common_proc.c
@@ -268,6 +268,7 @@  read_msg(int fd, struct mp_msg_internal *m, struct sockaddr_un *s)
 	char control[CMSG_SPACE(sizeof(m->msg.fds))];
 	struct cmsghdr *cmsg;
 	int buflen = sizeof(*m) - sizeof(m->msg.fds);
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	memset(&msgh, 0, sizeof(msgh));
 	iov.iov_base = m;
@@ -291,7 +292,9 @@  read_msg(int fd, struct mp_msg_internal *m, struct sockaddr_un *s)
 		if (errno == EINTR)
 			goto retry;
 
-		EAL_LOG(ERR, "recvmsg failed, %s", strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "recvmsg failed, %s", errmsg);
 		return -1;
 	}
 
@@ -561,6 +564,7 @@  async_reply_handle(void *arg)
 static int
 open_socket_fd(void)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct sockaddr_un un;
 
 	peer_name[0] = '\0';
@@ -582,8 +586,9 @@  open_socket_fd(void)
 	unlink(un.sun_path); /* May still exist since last run */
 
 	if (bind(mp_fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
-		EAL_LOG(ERR, "failed to bind %s: %s",
-			un.sun_path, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "failed to bind %s: %s", un.sun_path, errmsg);
 		close(mp_fd);
 		return -1;
 	}
@@ -605,6 +610,7 @@  close_socket_fd(int fd)
 int
 rte_mp_channel_init(void)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	char path[PATH_MAX];
 	int dir_fd;
 	const struct internal_config *internal_conf =
@@ -630,14 +636,16 @@  rte_mp_channel_init(void)
 	/* lock the directory */
 	dir_fd = open(mp_dir_path, O_RDONLY);
 	if (dir_fd < 0) {
-		EAL_LOG(ERR, "failed to open %s: %s",
-			mp_dir_path, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "failed to open %s: %s", mp_dir_path, errmsg);
 		return -1;
 	}
 
 	if (flock(dir_fd, LOCK_EX)) {
-		EAL_LOG(ERR, "failed to lock %s: %s",
-			mp_dir_path, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "failed to lock %s: %s", mp_dir_path, errmsg);
 		close(dir_fd);
 		return -1;
 	}
@@ -649,8 +657,9 @@  rte_mp_channel_init(void)
 
 	if (rte_thread_create_internal_control(&mp_handle_tid, "mp-msg",
 			mp_handle, NULL) < 0) {
-		EAL_LOG(ERR, "failed to create mp thread: %s",
-			strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "failed to create mp thread: %s", errmsg);
 		close(dir_fd);
 		close(rte_atomic_exchange_explicit(&mp_fd, -1, rte_memory_order_relaxed));
 		return -1;
@@ -691,6 +700,7 @@  send_msg(const char *dst_path, struct rte_mp_msg *msg, int type)
 	struct cmsghdr *cmsg;
 	struct sockaddr_un dst;
 	struct mp_msg_internal m;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int fd_size = msg->num_fds * sizeof(int);
 	char control[CMSG_SPACE(fd_size)];
 
@@ -732,8 +742,10 @@  send_msg(const char *dst_path, struct rte_mp_msg *msg, int type)
 			unlink(dst_path);
 			return 0;
 		}
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "failed to send to (%s) due to %s",
-			dst_path, strerror(errno));
+			dst_path, errmsg);
 		return -1;
 	}
 
diff --git a/lib/eal/common/eal_common_trace_utils.c b/lib/eal/common/eal_common_trace_utils.c
index 7282715b11..868b28490c 100644
--- a/lib/eal/common/eal_common_trace_utils.c
+++ b/lib/eal/common/eal_common_trace_utils.c
@@ -241,11 +241,14 @@  eal_trace_mode_args_save(const char *val)
 int
 eal_trace_dir_args_save(char const *val)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	char *dir_path;
 	int rc;
 
 	if (asprintf(&dir_path, "%s/", val) == -1) {
-		trace_err("failed to copy directory: %s", strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		trace_err("failed to copy directory: %s", errmsg);
 		return -ENOMEM;
 	}
 
@@ -304,6 +307,7 @@  static int
 trace_mkdir(void)
 {
 	struct trace *trace = trace_obj_get();
+	char errmsg[RTE_STRERR_BUFSIZE];
 	static bool already_done;
 	char *session;
 	int rc;
@@ -329,7 +333,9 @@  trace_mkdir(void)
 	/* Create the path if it t exist, no "mkdir -p" available here */
 	rc = mkdir(trace->dir, 0700);
 	if (rc < 0 && errno != EEXIST) {
-		trace_err("mkdir %s failed [%s]", trace->dir, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		trace_err("mkdir %s failed [%s]", trace->dir, errmsg);
 		rte_errno = errno;
 		return -rte_errno;
 	}
@@ -344,7 +350,9 @@  trace_mkdir(void)
 
 	rc = mkdir(trace->dir, 0700);
 	if (rc < 0) {
-		trace_err("mkdir %s failed [%s]", trace->dir, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		trace_err("mkdir %s failed [%s]", trace->dir, errmsg);
 		rte_errno = errno;
 		return -rte_errno;
 	}
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 1229230063..0fc318acdb 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -177,6 +177,7 @@  rte_eal_config_create(void)
 static int
 rte_eal_config_attach(void)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	void *rte_mem_cfg_addr;
 	const char *pathname = eal_runtime_config_path();
 	struct rte_config *config = rte_eal_get_configuration();
@@ -202,8 +203,10 @@  rte_eal_config_attach(void)
 	if (rte_mem_cfg_addr == MAP_FAILED) {
 		close(mem_cfg_fd);
 		mem_cfg_fd = -1;
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "Cannot mmap memory for rte_config! error %i (%s)",
-			errno, strerror(errno));
+			errno, errmsg);
 		return -1;
 	}
 
@@ -217,6 +220,7 @@  static int
 rte_eal_config_reattach(void)
 {
 	struct rte_mem_config *mem_config;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	void *rte_mem_cfg_addr;
 	struct rte_config *config = rte_eal_get_configuration();
 	const struct internal_config *internal_conf =
@@ -249,8 +253,10 @@  rte_eal_config_reattach(void)
 			munmap(mem_config, sizeof(struct rte_mem_config));
 			return -1;
 		}
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "Cannot mmap memory for rte_config! error %i (%s)",
-			errno, strerror(errno));
+			errno, errmsg);
 		return -1;
 	}
 
diff --git a/lib/eal/freebsd/eal_interrupts.c b/lib/eal/freebsd/eal_interrupts.c
index 23747babc2..73fb732c01 100644
--- a/lib/eal/freebsd/eal_interrupts.c
+++ b/lib/eal/freebsd/eal_interrupts.c
@@ -85,6 +85,7 @@  rte_intr_callback_register(const struct rte_intr_handle *intr_handle,
 		rte_intr_callback_fn cb, void *cb_arg)
 {
 	struct rte_intr_callback *callback;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct rte_intr_source *src;
 	int ret = 0, add_event = 0;
 
@@ -183,10 +184,13 @@  rte_intr_callback_register(const struct rte_intr_handle *intr_handle,
 			if (errno == ENODEV)
 				EAL_LOG(DEBUG, "Interrupt handle %d not supported",
 					rte_intr_fd_get(src->intr_handle));
-			else
+			else {
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				EAL_LOG(ERR, "Error adding fd %d kevent, %s",
 					rte_intr_fd_get(src->intr_handle),
-					strerror(errno));
+					errmsg);
+			}
 			ret = -errno;
 			goto fail;
 		}
@@ -273,6 +277,7 @@  rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle,
 {
 	int ret;
 	struct rte_intr_source *src;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct rte_intr_callback *cb, *next;
 
 	/* do parameter checking first */
@@ -321,9 +326,10 @@  rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle,
 		 * remove intr file descriptor from wait list.
 		 */
 		if (kevent(kq, &ke, 1, NULL, 0, NULL) < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "Error removing fd %d kevent, %s",
-				rte_intr_fd_get(src->intr_handle),
-				strerror(errno));
+				rte_intr_fd_get(src->intr_handle), errmsg);
 			/* removing non-existent even is an expected condition
 			 * in some circumstances (e.g. oneshot events).
 			 */
@@ -462,6 +468,7 @@  eal_intr_process_interrupts(struct kevent *events, int nfds)
 	struct rte_intr_callback active_cb;
 	union rte_intr_read_buffer buf;
 	struct rte_intr_callback *cb, *next;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct rte_intr_source *src;
 	bool call = false;
 	int n, bytes_read;
@@ -513,10 +520,10 @@  eal_intr_process_interrupts(struct kevent *events, int nfds)
 				if (errno == EINTR || errno == EWOULDBLOCK)
 					continue;
 
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				EAL_LOG(ERR, "Error reading from file "
-					"descriptor %d: %s",
-					event_fd,
-					strerror(errno));
+					"descriptor %d: %s", event_fd, errmsg);
 			} else if (bytes_read == 0)
 				EAL_LOG(ERR, "Read nothing from file "
 					"descriptor %d", event_fd);
@@ -565,9 +572,12 @@  eal_intr_process_interrupts(struct kevent *events, int nfds)
 				 * remove intr file descriptor from wait list.
 				 */
 				if (kevent(kq, &ke, 1, NULL, 0, NULL) < 0) {
+					if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+						snprintf(errmsg, sizeof(errmsg),
+							 "Unknown error %d", errno);
 					EAL_LOG(ERR, "Error removing fd %d kevent, %s",
 						rte_intr_fd_get(src->intr_handle),
-						strerror(errno));
+						errmsg);
 					/* removing non-existent even is an expected
 					 * condition in some circumstances
 					 * (e.g. oneshot events).
diff --git a/lib/eal/freebsd/eal_memory.c b/lib/eal/freebsd/eal_memory.c
index a6f3ba226e..840995799b 100644
--- a/lib/eal/freebsd/eal_memory.c
+++ b/lib/eal/freebsd/eal_memory.c
@@ -53,6 +53,7 @@  rte_mem_virt2iova(const void *virtaddr)
 int
 rte_eal_hugepage_init(void)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct rte_mem_config *mcfg;
 	uint64_t total_mem = 0;
 	void *addr;
@@ -84,8 +85,9 @@  rte_eal_hugepage_init(void)
 		addr = mmap(NULL, mem_sz, PROT_READ | PROT_WRITE,
 				MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 		if (addr == MAP_FAILED) {
-			EAL_LOG(ERR, "%s: mmap() failed: %s", __func__,
-					strerror(errno));
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+			EAL_LOG(ERR, "%s: mmap() failed: %s", __func__, errmsg);
 			return -1;
 		}
 
diff --git a/lib/eal/freebsd/eal_timer.c b/lib/eal/freebsd/eal_timer.c
index 4eba66eadb..ec5f4bf98d 100644
--- a/lib/eal/freebsd/eal_timer.c
+++ b/lib/eal/freebsd/eal_timer.c
@@ -15,6 +15,7 @@ 
 #include <rte_memory.h>
 #include <rte_eal.h>
 #include <rte_debug.h>
+#include <rte_errno.h>
 
 #include "eal_private.h"
 #include "eal_internal_cfg.h"
@@ -28,6 +29,7 @@  enum timer_source eal_timer_source = EAL_TIMER_TSC;
 uint64_t
 get_tsc_freq(uint64_t arch_hz)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	size_t sz;
 	int tmp;
 	uint64_t tsc_hz;
@@ -35,21 +37,27 @@  get_tsc_freq(uint64_t arch_hz)
 	sz = sizeof(tmp);
 	tmp = 0;
 
-	if (sysctlbyname("kern.timecounter.smp_tsc", &tmp, &sz, NULL, 0))
-		EAL_LOG(WARNING, "%s", strerror(errno));
-	else if (tmp != 1)
+	if (sysctlbyname("kern.timecounter.smp_tsc", &tmp, &sz, NULL, 0)) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(WARNING, "%s", errmsg);
+	} else if (tmp != 1)
 		EAL_LOG(WARNING, "TSC is not safe to use in SMP mode");
 
 	tmp = 0;
 
-	if (sysctlbyname("kern.timecounter.invariant_tsc", &tmp, &sz, NULL, 0))
-		EAL_LOG(WARNING, "%s", strerror(errno));
-	else if (tmp != 1)
+	if (sysctlbyname("kern.timecounter.invariant_tsc", &tmp, &sz, NULL, 0)) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(WARNING, "%s", errmsg);
+	} else if (tmp != 1)
 		EAL_LOG(WARNING, "TSC is not invariant");
 
 	sz = sizeof(tsc_hz);
 	if (sysctlbyname("machdep.tsc_freq", &tsc_hz, &sz, NULL, 0)) {
-		EAL_LOG(WARNING, "%s", strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(WARNING, "%s", errmsg);
 		return arch_hz;
 	}
 
diff --git a/lib/eal/include/rte_errno.h b/lib/eal/include/rte_errno.h
index c49818a40e..10a04edbda 100644
--- a/lib/eal/include/rte_errno.h
+++ b/lib/eal/include/rte_errno.h
@@ -19,6 +19,9 @@  extern "C" {
 
 RTE_DECLARE_PER_LCORE(int, _rte_errno); /**< Per core error number. */
 
+/* For the buffer size of strerror_r */
+#define RTE_STRERR_BUFSIZE	256
+
 /**
  * Error number value, stored per-thread, which can be queried after
  * calls to certain functions to determine why those functions failed.
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 54577b7718..1da56b9595 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -90,6 +90,7 @@  eal_clean_runtime_dir(void)
 		"fbarray_*",
 		"mp_socket_*"
 	};
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	/* open directory */
 	dir = opendir(runtime_dir);
@@ -159,8 +160,9 @@  eal_clean_runtime_dir(void)
 	if (dir)
 		closedir(dir);
 
-	EAL_LOG(ERR, "Error while clearing runtime dir: %s",
-		strerror(errno));
+	if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+		snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+	EAL_LOG(ERR, "Error while clearing runtime dir: %s", errmsg);
 
 	return -1;
 }
@@ -266,6 +268,7 @@  rte_eal_config_attach(void)
 	struct rte_mem_config *mem_config;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	const char *pathname = eal_runtime_config_path();
 
@@ -287,8 +290,10 @@  rte_eal_config_attach(void)
 	if (mem_config == MAP_FAILED) {
 		close(mem_cfg_fd);
 		mem_cfg_fd = -1;
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "Cannot mmap memory for rte_config! error %i (%s)",
-			errno, strerror(errno));
+			errno, errmsg);
 		return -1;
 	}
 
@@ -306,6 +311,7 @@  rte_eal_config_reattach(void)
 	void *rte_mem_cfg_addr;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	if (internal_conf->no_shconf)
 		return 0;
@@ -334,8 +340,10 @@  rte_eal_config_reattach(void)
 			munmap(mem_config, sizeof(struct rte_mem_config));
 			return -1;
 		}
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "Cannot mmap memory for rte_config! error %i (%s)",
-			errno, strerror(errno));
+			errno, errmsg);
 		return -1;
 	}
 
@@ -1402,6 +1410,7 @@  rte_eal_vfio_get_vf_token(rte_uuid_t vf_token)
 int
 rte_eal_check_module(const char *module_name)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	char sysfs_mod_name[PATH_MAX];
 	struct stat st;
 	int n;
@@ -1411,8 +1420,10 @@  rte_eal_check_module(const char *module_name)
 
 	/* Check if there is sysfs mounted */
 	if (stat("/sys/module", &st) != 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(DEBUG, "sysfs is not mounted! error %i (%s)",
-			errno, strerror(errno));
+			errno, errmsg);
 		return -1;
 	}
 
@@ -1424,8 +1435,10 @@  rte_eal_check_module(const char *module_name)
 	}
 
 	if (stat(sysfs_mod_name, &st) != 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(DEBUG, "Module %s not found! error %i (%s)",
-		        sysfs_mod_name, errno, strerror(errno));
+			sysfs_mod_name, errno, errmsg);
 		return 0;
 	}
 
diff --git a/lib/eal/linux/eal_dev.c b/lib/eal/linux/eal_dev.c
index e63f24d108..77688b2b19 100644
--- a/lib/eal/linux/eal_dev.c
+++ b/lib/eal/linux/eal_dev.c
@@ -62,6 +62,7 @@  sigbus_action_recover(void)
 static void sigbus_handler(int signum, siginfo_t *info,
 				void *ctx __rte_unused)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int ret;
 
 	EAL_LOG(DEBUG, "Thread catch SIGBUS, fault address:%p",
@@ -71,9 +72,11 @@  static void sigbus_handler(int signum, siginfo_t *info,
 	ret = rte_bus_sigbus_handler(info->si_addr);
 	rte_spinlock_unlock(&failure_handle_lock);
 	if (ret == -1) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		rte_exit(EXIT_FAILURE,
 			 "Failed to handle SIGBUS for hot-unplug, "
-			 "(rte_errno: %s)!", strerror(rte_errno));
+			 "(rte_errno: %s)!", errmsg);
 	} else if (ret == 1) {
 		if (sigbus_action_old.sa_flags == SA_SIGINFO
 		    && sigbus_action_old.sa_sigaction) {
diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c
index d47a19c56a..cb2a24e46d 100644
--- a/lib/eal/linux/eal_hugepage_info.c
+++ b/lib/eal/linux/eal_hugepage_info.c
@@ -23,6 +23,7 @@ 
 #include <rte_log.h>
 #include <rte_common.h>
 #include "rte_string_fns.h"
+#include <rte_errno.h>
 
 #include "eal_private.h"
 #include "eal_internal_cfg.h"
@@ -322,6 +323,7 @@  walk_hugedir(const char *hugedir, walk_hugedir_t *cb, void *user_data)
 	struct dirent *dirent;
 	int dir_fd, fd, lck_result;
 	const char filter[] = "*map_*"; /* matches hugepage files */
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	dir = opendir(hugedir);
 	if (!dir) {
@@ -376,9 +378,9 @@  walk_hugedir(const char *hugedir, walk_hugedir_t *cb, void *user_data)
 error:
 	if (dir)
 		closedir(dir);
-
-	EAL_LOG(ERR, "Error while walking hugepage dir: %s",
-		strerror(errno));
+	if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+		snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+	EAL_LOG(ERR, "Error while walking hugepage dir: %s", errmsg);
 
 	return -1;
 }
@@ -400,12 +402,15 @@  static void
 inspect_hugedir_cb(const struct walk_hugedir_data *whd)
 {
 	uint64_t *total_size = whd->user_data;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct stat st;
 
-	if (fstat(whd->file_fd, &st) < 0)
+	if (fstat(whd->file_fd, &st) < 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(DEBUG, "%s(): stat(\"%s\") failed: %s",
-				__func__, whd->file_name, strerror(errno));
-	else
+				__func__, whd->file_name, errmsg);
+	} else
 		(*total_size) += st.st_size;
 }
 
diff --git a/lib/eal/linux/eal_interrupts.c b/lib/eal/linux/eal_interrupts.c
index 6436f796eb..fc0476d948 100644
--- a/lib/eal/linux/eal_interrupts.c
+++ b/lib/eal/linux/eal_interrupts.c
@@ -455,12 +455,15 @@  uio_intx_intr_enable(const struct rte_intr_handle *intr_handle)
 static int
 uio_intr_disable(const struct rte_intr_handle *intr_handle)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	const int value = 0;
 
 	if (rte_intr_fd_get(intr_handle) < 0 ||
 	    write(rte_intr_fd_get(intr_handle), &value, sizeof(value)) < 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "Error disabling interrupts for fd %d (%s)",
-			rte_intr_fd_get(intr_handle), strerror(errno));
+			rte_intr_fd_get(intr_handle), errmsg);
 		return -1;
 	}
 	return 0;
@@ -469,12 +472,15 @@  uio_intr_disable(const struct rte_intr_handle *intr_handle)
 static int
 uio_intr_enable(const struct rte_intr_handle *intr_handle)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	const int value = 1;
 
 	if (rte_intr_fd_get(intr_handle) < 0 ||
 	    write(rte_intr_fd_get(intr_handle), &value, sizeof(value)) < 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "Error enabling interrupts for fd %d (%s)",
-			rte_intr_fd_get(intr_handle), strerror(errno));
+			rte_intr_fd_get(intr_handle), errmsg);
 		return -1;
 	}
 	return 0;
@@ -903,6 +909,7 @@  eal_intr_process_interrupts(struct epoll_event *events, int nfds)
 	struct rte_intr_callback *cb, *next;
 	union rte_intr_read_buffer buf;
 	struct rte_intr_callback active_cb;
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	for (n = 0; n < nfds; n++) {
 
@@ -972,10 +979,11 @@  eal_intr_process_interrupts(struct epoll_event *events, int nfds)
 				if (errno == EINTR || errno == EWOULDBLOCK)
 					continue;
 
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				EAL_LOG(ERR, "Error reading from file "
 					"descriptor %d: %s",
-					events[n].data.fd,
-					strerror(errno));
+					events[n].data.fd, errmsg);
 				/*
 				 * The device is unplugged or buggy, remove
 				 * it as an interrupt source and return to
@@ -1114,6 +1122,7 @@  eal_intr_thread_main(__rte_unused void *arg)
 		static struct epoll_event pipe_event = {
 			.events = EPOLLIN | EPOLLPRI,
 		};
+		char errmsg[RTE_STRERR_BUFSIZE];
 		struct rte_intr_source *src;
 		unsigned numfds = 0;
 
@@ -1129,8 +1138,10 @@  eal_intr_thread_main(__rte_unused void *arg)
 		 */
 		if (epoll_ctl(pfd, EPOLL_CTL_ADD, intr_pipe.readfd,
 						&pipe_event) < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			rte_panic("Error adding fd to %d epoll_ctl, %s\n",
-					intr_pipe.readfd, strerror(errno));
+					intr_pipe.readfd, errmsg);
 		}
 		numfds++;
 
@@ -1151,9 +1162,10 @@  eal_intr_thread_main(__rte_unused void *arg)
 			 */
 			if (epoll_ctl(pfd, EPOLL_CTL_ADD,
 					rte_intr_fd_get(src->intr_handle), &ev) < 0) {
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				rte_panic("Error adding fd %d epoll_ctl, %s\n",
-					rte_intr_fd_get(src->intr_handle),
-					strerror(errno));
+					  rte_intr_fd_get(src->intr_handle), errmsg);
 			}
 			else
 				numfds++;
@@ -1202,6 +1214,7 @@  rte_eal_intr_init(void)
 static void
 eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	union rte_intr_read_buffer buf;
 	int bytes_read = 0;
 	int nbytes;
@@ -1242,9 +1255,10 @@  eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle)
 			if (errno == EINTR || errno == EWOULDBLOCK ||
 			    errno == EAGAIN)
 				continue;
-			EAL_LOG(ERR,
-				"Error reading from fd %d: %s",
-				fd, strerror(errno));
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+			EAL_LOG(ERR, "Error reading from fd %d: %s",
+				fd, errmsg);
 		} else if (nbytes == 0)
 			EAL_LOG(ERR, "Read nothing from fd %d", fd);
 		return;
@@ -1317,6 +1331,7 @@  eal_epoll_wait(int epfd, struct rte_epoll_event *events,
 	       int maxevents, int timeout, bool interruptible)
 {
 	struct epoll_event evs[maxevents];
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int rc;
 
 	if (!events) {
@@ -1341,9 +1356,10 @@  eal_epoll_wait(int epfd, struct rte_epoll_event *events,
 				else
 					continue;
 			}
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			/* epoll_wait fail */
-			EAL_LOG(ERR, "epoll_wait returns with fail %s",
-				strerror(errno));
+			EAL_LOG(ERR, "epoll_wait returns with fail %s", errmsg);
 			rc = -1;
 			break;
 		} else {
@@ -1390,6 +1406,7 @@  int
 rte_epoll_ctl(int epfd, int op, int fd,
 	      struct rte_epoll_event *event)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct epoll_event ev;
 
 	if (!event) {
@@ -1411,8 +1428,9 @@  rte_epoll_ctl(int epfd, int op, int fd,
 
 	ev.events = event->epdata.event;
 	if (epoll_ctl(epfd, op, fd, &ev) < 0) {
-		EAL_LOG(ERR, "Error op %d fd %d epoll_ctl, %s",
-			op, fd, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "Error op %d fd %d epoll_ctl, %s", op, fd, errmsg);
 		if (op == EPOLL_CTL_ADD)
 			/* rollback status when CTL_ADD fail */
 			rte_atomic_store_explicit(&event->status, RTE_EPOLL_INVALID,
@@ -1513,6 +1531,7 @@  rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle)
 int
 rte_intr_efd_enable(struct rte_intr_handle *intr_handle, uint32_t nb_efd)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	uint32_t i;
 	int fd;
 	uint32_t n = RTE_MIN(nb_efd, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
@@ -1523,9 +1542,11 @@  rte_intr_efd_enable(struct rte_intr_handle *intr_handle, uint32_t nb_efd)
 		for (i = 0; i < n; i++) {
 			fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
 			if (fd < 0) {
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				EAL_LOG(ERR,
 					"can't setup eventfd, error %i (%s)",
-					errno, strerror(errno));
+					errno, errmsg);
 				return -errno;
 			}
 
diff --git a/lib/eal/linux/eal_memalloc.c b/lib/eal/linux/eal_memalloc.c
index e354efc95d..1bad18b4c0 100644
--- a/lib/eal/linux/eal_memalloc.c
+++ b/lib/eal/linux/eal_memalloc.c
@@ -31,6 +31,7 @@ 
 #include <rte_log.h>
 #include <rte_eal.h>
 #include <rte_memory.h>
+#include <rte_errno.h>
 
 #include "eal_filesystem.h"
 #include "eal_internal_cfg.h"
@@ -156,12 +157,16 @@  check_numa(void)
 static void
 prepare_numa(int *oldpolicy, struct bitmask *oldmask, int socket_id)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
+
 	EAL_LOG(DEBUG, "Trying to obtain current memory policy.");
 	if (get_mempolicy(oldpolicy, oldmask->maskp,
 			  oldmask->size + 1, 0, 0) < 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR,
 			"Failed to get current mempolicy: %s. "
-			"Assuming MPOL_DEFAULT.", strerror(errno));
+			"Assuming MPOL_DEFAULT.", errmsg);
 		*oldpolicy = MPOL_DEFAULT;
 	}
 	EAL_LOG(DEBUG,
@@ -173,14 +178,17 @@  prepare_numa(int *oldpolicy, struct bitmask *oldmask, int socket_id)
 static void
 restore_numa(int *oldpolicy, struct bitmask *oldmask)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
+
 	EAL_LOG(DEBUG,
 		"Restoring previous memory policy: %d", *oldpolicy);
 	if (*oldpolicy == MPOL_DEFAULT) {
 		numa_set_localalloc();
 	} else if (set_mempolicy(*oldpolicy, oldmask->maskp,
 				 oldmask->size + 1) < 0) {
-		EAL_LOG(ERR, "Failed to restore mempolicy: %s",
-			strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "Failed to restore mempolicy: %s", errmsg);
 		numa_set_localalloc();
 	}
 	numa_free_cpumask(oldmask);
@@ -212,6 +220,7 @@  pagesz_flags(uint64_t page_sz)
 /* returns 1 on successful lock, 0 on unsuccessful lock, -1 on error */
 static int lock(int fd, int type)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int ret;
 
 	/* flock may be interrupted */
@@ -223,8 +232,10 @@  static int lock(int fd, int type)
 		/* couldn't lock */
 		return 0;
 	} else if (ret) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "%s(): error calling flock(): %s",
-			__func__, strerror(errno));
+			__func__, errmsg);
 		return -1;
 	}
 	/* lock was successful */
@@ -237,6 +248,7 @@  get_seg_memfd(struct hugepage_info *hi __rte_unused,
 		unsigned int seg_idx __rte_unused)
 {
 #ifdef MEMFD_SUPPORTED
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int fd;
 	char segname[250]; /* as per manpage, limit is 249 bytes plus null */
 
@@ -251,8 +263,10 @@  get_seg_memfd(struct hugepage_info *hi __rte_unused,
 			snprintf(segname, sizeof(segname), "seg_%i", list_idx);
 			fd = memfd_create(segname, flags);
 			if (fd < 0) {
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				EAL_LOG(DEBUG, "%s(): memfd create failed: %s",
-					__func__, strerror(errno));
+					__func__, errmsg);
 				return -1;
 			}
 			fd_list[list_idx].memseg_list_fd = fd;
@@ -265,8 +279,10 @@  get_seg_memfd(struct hugepage_info *hi __rte_unused,
 					list_idx, seg_idx);
 			fd = memfd_create(segname, flags);
 			if (fd < 0) {
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				EAL_LOG(DEBUG, "%s(): memfd create failed: %s",
-					__func__, strerror(errno));
+					__func__, errmsg);
 				return -1;
 			}
 			fd_list[list_idx].fds[seg_idx] = fd;
@@ -282,6 +298,7 @@  get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
 		unsigned int list_idx, unsigned int seg_idx,
 		bool *dirty)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int fd;
 	int *out_fd;
 	struct stat st;
@@ -316,8 +333,10 @@  get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
 	 */
 	ret = stat(path, &st);
 	if (ret < 0 && errno != ENOENT) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(DEBUG, "%s(): stat() for '%s' failed: %s",
-			__func__, path, strerror(errno));
+			__func__, path, errmsg);
 		return -1;
 	}
 	if (!internal_conf->hugepage_file.unlink_existing && ret == 0 &&
@@ -342,8 +361,10 @@  get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
 			ret == 0) {
 		/* coverity[toctou] */
 		if (unlink(path) < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(DEBUG, "%s(): could not remove '%s': %s",
-				__func__, path, strerror(errno));
+				__func__, path, errmsg);
 			return -1;
 		}
 	}
@@ -351,14 +372,18 @@  get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
 	/* coverity[toctou] */
 	fd = open(path, O_CREAT | O_RDWR, 0600);
 	if (fd < 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "%s(): open '%s' failed: %s",
-			__func__, path, strerror(errno));
+			__func__, path, errmsg);
 		return -1;
 	}
 	/* take out a read lock */
 	if (lock(fd, LOCK_SH) < 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "%s(): lock '%s' failed: %s",
-			__func__, path, strerror(errno));
+			__func__, path, errmsg);
 		close(fd);
 		return -1;
 	}
@@ -372,15 +397,16 @@  resize_hugefile_in_memory(int fd, uint64_t fa_offset,
 {
 	int flags = grow ? 0 : FALLOC_FL_PUNCH_HOLE |
 			FALLOC_FL_KEEP_SIZE;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int ret;
 
 	/* grow or shrink the file */
 	ret = fallocate(fd, flags, fa_offset, page_sz);
 
 	if (ret < 0) {
-		EAL_LOG(DEBUG, "%s(): fallocate() failed: %s",
-				__func__,
-				strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(DEBUG, "%s(): fallocate() failed: %s", __func__, errmsg);
 		return -1;
 	}
 	return 0;
@@ -392,6 +418,7 @@  resize_hugefile_in_filesystem(int fd, uint64_t fa_offset, uint64_t page_sz,
 {
 	const struct internal_config *internal_conf =
 			eal_get_internal_configuration();
+	char errmsg[RTE_STRERR_BUFSIZE];
 	bool again = false;
 
 	do {
@@ -414,8 +441,10 @@  resize_hugefile_in_filesystem(int fd, uint64_t fa_offset, uint64_t page_sz,
 				*dirty = new_size <= cur_size;
 			if (new_size > cur_size &&
 					ftruncate(fd, new_size) < 0) {
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				EAL_LOG(DEBUG, "%s(): ftruncate() failed: %s",
-					__func__, strerror(errno));
+					__func__, errmsg);
 				return -1;
 			}
 		} else {
@@ -449,9 +478,11 @@  resize_hugefile_in_filesystem(int fd, uint64_t fa_offset, uint64_t page_sz,
 					again = true;
 					fallocate_supported = 0;
 				} else {
+					if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+						snprintf(errmsg, sizeof(errmsg),
+							 "Unknown error %d", errno);
 					EAL_LOG(DEBUG, "%s(): fallocate() failed: %s",
-						__func__,
-						strerror(errno));
+						__func__, errmsg);
 					return -1;
 				}
 			} else {
@@ -476,15 +507,20 @@  close_hugefile(int fd, char *path, int list_idx)
 {
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	char errmsg[RTE_STRERR_BUFSIZE];
+
 	/*
 	 * primary process must unlink the file, but only when not in in-memory
 	 * mode (as in that case there is no file to unlink).
 	 */
 	if (!internal_conf->in_memory &&
 			rte_eal_process_type() == RTE_PROC_PRIMARY &&
-			unlink(path))
+			unlink(path)) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "%s(): unlinking '%s' failed: %s",
-			__func__, path, strerror(errno));
+			__func__, path, errmsg);
+	}
 
 	close(fd);
 	fd_list[list_idx].memseg_list_fd = -1;
@@ -519,6 +555,7 @@  alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 #ifdef RTE_EAL_NUMA_AWARE_HUGEPAGES
 	int cur_socket_id = 0;
 #endif
+	char errmsg[RTE_STRERR_BUFSIZE];
 	uint64_t map_offset;
 	rte_iova_t iova;
 	void *va;
@@ -584,15 +621,19 @@  alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 		} else {
 			map_offset = 0;
 			if (ftruncate(fd, alloc_sz) < 0) {
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				EAL_LOG(DEBUG, "%s(): ftruncate() failed: %s",
-					__func__, strerror(errno));
+					__func__, errmsg);
 				goto resized;
 			}
 			if (internal_conf->hugepage_file.unlink_before_mapping &&
 					!internal_conf->in_memory) {
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				if (unlink(path)) {
 					EAL_LOG(DEBUG, "%s(): unlink() failed: %s",
-						__func__, strerror(errno));
+						__func__, errmsg);
 					goto resized;
 				}
 			}
@@ -610,8 +651,9 @@  alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 			map_offset);
 
 	if (va == MAP_FAILED) {
-		EAL_LOG(DEBUG, "%s(): mmap() failed: %s", __func__,
-			strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(DEBUG, "%s(): mmap() failed: %s", __func__, errmsg);
 		/* mmap failed, but the previous region might have been
 		 * unmapped anyway. try to remap it
 		 */
@@ -661,8 +703,9 @@  alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 		ret = get_mempolicy(&cur_socket_id, NULL, 0, addr,
 					MPOL_F_NODE | MPOL_F_ADDR);
 		if (ret < 0) {
-			EAL_LOG(DEBUG, "%s(): get_mempolicy: %s",
-				__func__, strerror(errno));
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+			EAL_LOG(DEBUG, "%s(): get_mempolicy: %s", __func__, errmsg);
 			goto mapped;
 		} else if (cur_socket_id != socket_id) {
 			EAL_LOG(DEBUG,
@@ -821,6 +864,7 @@  alloc_seg_walk(const struct rte_memseg_list *msl, void *arg)
 	unsigned int msl_idx, need, i;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	if (msl->page_sz != wa->page_sz)
 		return 0;
@@ -873,14 +917,18 @@  alloc_seg_walk(const struct rte_memseg_list *msl, void *arg)
 	if (wa->hi->lock_descriptor == -1 && !internal_conf->in_memory) {
 		dir_fd = open(wa->hi->hugedir, O_RDONLY);
 		if (dir_fd < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "%s(): Cannot open '%s': %s",
-				__func__, wa->hi->hugedir, strerror(errno));
+				__func__, wa->hi->hugedir, errmsg);
 			return -1;
 		}
 		/* blocking writelock */
 		if (flock(dir_fd, LOCK_EX)) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "%s(): Cannot lock '%s': %s",
-				__func__, wa->hi->hugedir, strerror(errno));
+				__func__, wa->hi->hugedir, errmsg);
 			close(dir_fd);
 			return -1;
 		}
@@ -951,6 +999,7 @@  free_seg_walk(const struct rte_memseg_list *msl, void *arg)
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	struct rte_memseg_list *found_msl;
 	struct free_walk_param *wa = arg;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	uintptr_t start_addr, end_addr;
 	int msl_idx, seg_idx, ret, dir_fd = -1;
 	const struct internal_config *internal_conf =
@@ -980,14 +1029,18 @@  free_seg_walk(const struct rte_memseg_list *msl, void *arg)
 	if (wa->hi->lock_descriptor == -1 && !internal_conf->in_memory) {
 		dir_fd = open(wa->hi->hugedir, O_RDONLY);
 		if (dir_fd < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "%s(): Cannot open '%s': %s",
-				__func__, wa->hi->hugedir, strerror(errno));
+				__func__, wa->hi->hugedir, errmsg);
 			return -1;
 		}
 		/* blocking writelock */
 		if (flock(dir_fd, LOCK_EX)) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "%s(): Cannot lock '%s': %s",
-				__func__, wa->hi->hugedir, strerror(errno));
+				__func__, wa->hi->hugedir, errmsg);
 			close(dir_fd);
 			return -1;
 		}
@@ -1335,6 +1388,7 @@  sync_existing(struct rte_memseg_list *primary_msl,
 		struct rte_memseg_list *local_msl, struct hugepage_info *hi,
 		unsigned int msl_idx)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int ret, dir_fd;
 
 	/* do not allow any page allocations during the time we're allocating,
@@ -1344,14 +1398,18 @@  sync_existing(struct rte_memseg_list *primary_msl,
 	 */
 	dir_fd = open(hi->hugedir, O_RDONLY);
 	if (dir_fd < 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "%s(): Cannot open '%s': %s", __func__,
-			hi->hugedir, strerror(errno));
+			hi->hugedir, errmsg);
 		return -1;
 	}
 	/* blocking writelock */
 	if (flock(dir_fd, LOCK_EX)) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "%s(): Cannot lock '%s': %s", __func__,
-			hi->hugedir, strerror(errno));
+			hi->hugedir, errmsg);
 		close(dir_fd);
 		return -1;
 	}
diff --git a/lib/eal/linux/eal_memory.c b/lib/eal/linux/eal_memory.c
index 45879ca743..59be005b4b 100644
--- a/lib/eal/linux/eal_memory.c
+++ b/lib/eal/linux/eal_memory.c
@@ -90,6 +90,7 @@  uint64_t eal_get_baseaddr(void)
 phys_addr_t
 rte_mem_virt2phy(const void *virtaddr)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int fd, retval;
 	uint64_t page, physaddr;
 	unsigned long virt_pfn;
@@ -104,16 +105,20 @@  rte_mem_virt2phy(const void *virtaddr)
 
 	fd = open("/proc/self/pagemap", O_RDONLY);
 	if (fd < 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(INFO, "%s(): cannot open /proc/self/pagemap: %s",
-			__func__, strerror(errno));
+			__func__, errmsg);
 		return RTE_BAD_IOVA;
 	}
 
 	virt_pfn = (unsigned long)virtaddr / page_size;
 	offset = sizeof(uint64_t) * virt_pfn;
 	if (lseek(fd, offset, SEEK_SET) == (off_t) -1) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(INFO, "%s(): seek error in /proc/self/pagemap: %s",
-				__func__, strerror(errno));
+				__func__, errmsg);
 		close(fd);
 		return RTE_BAD_IOVA;
 	}
@@ -121,8 +126,10 @@  rte_mem_virt2phy(const void *virtaddr)
 	retval = read(fd, &page, PFN_MASK_SIZE);
 	close(fd);
 	if (retval < 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(INFO, "%s(): cannot read /proc/self/pagemap: %s",
-				__func__, strerror(errno));
+				__func__, errmsg);
 		return RTE_BAD_IOVA;
 	} else if (retval != PFN_MASK_SIZE) {
 		EAL_LOG(INFO, "%s(): read %d bytes from /proc/self/pagemap "
@@ -237,7 +244,11 @@  static int huge_wrap_sigsetjmp(void)
 /* Callback for numa library. */
 void numa_error(char *where)
 {
-	EAL_LOG(ERR, "%s failed: %s", where, strerror(errno));
+	char errmsg[RTE_STRERR_BUFSIZE];
+
+	if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+		snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+	EAL_LOG(ERR, "%s failed: %s", where, errmsg);
 }
 #endif
 
@@ -262,6 +273,7 @@  map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi,
 	struct bitmask *oldmask = NULL;
 	bool have_numa = true;
 	unsigned long maxnode = 0;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 
@@ -276,9 +288,11 @@  map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi,
 		oldmask = numa_allocate_nodemask();
 		if (get_mempolicy(&oldpolicy, oldmask->maskp,
 				  oldmask->size + 1, 0, 0) < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR,
 				"Failed to get current mempolicy: %s. "
-				"Assuming MPOL_DEFAULT.", strerror(errno));
+				"Assuming MPOL_DEFAULT.", errmsg);
 			oldpolicy = MPOL_DEFAULT;
 		}
 		for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
@@ -332,8 +346,9 @@  map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi,
 		/* try to create hugepage file */
 		fd = open(hf->filepath, O_CREAT | O_RDWR, 0600);
 		if (fd < 0) {
-			EAL_LOG(DEBUG, "%s(): open failed: %s", __func__,
-					strerror(errno));
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+			EAL_LOG(DEBUG, "%s(): open failed: %s", __func__, errmsg);
 			goto out;
 		}
 
@@ -345,8 +360,9 @@  map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi,
 		virtaddr = mmap(NULL, hugepage_sz, PROT_READ | PROT_WRITE,
 				MAP_SHARED | MAP_POPULATE, fd, 0);
 		if (virtaddr == MAP_FAILED) {
-			EAL_LOG(DEBUG, "%s(): mmap failed: %s", __func__,
-					strerror(errno));
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+			EAL_LOG(DEBUG, "%s(): mmap failed: %s", __func__, errmsg);
 			close(fd);
 			goto out;
 		}
@@ -378,8 +394,10 @@  map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi,
 
 		/* set shared lock on the file. */
 		if (flock(fd, LOCK_SH) < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(DEBUG, "%s(): Locking file failed:%s ",
-				__func__, strerror(errno));
+				__func__, errmsg);
 			close(fd);
 			goto out;
 		}
@@ -396,8 +414,9 @@  map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi,
 			numa_set_localalloc();
 		} else if (set_mempolicy(oldpolicy, oldmask->maskp,
 					 oldmask->size + 1) < 0) {
-			EAL_LOG(ERR, "Failed to restore mempolicy: %s",
-				strerror(errno));
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+			EAL_LOG(ERR, "Failed to restore mempolicy: %s", errmsg);
 			numa_set_localalloc();
 		}
 	}
@@ -576,6 +595,7 @@  unlink_hugepage_files(struct hugepage_file *hugepg_tbl,
 {
 	unsigned socket, size;
 	int page, nrpages = 0;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 
@@ -589,8 +609,10 @@  unlink_hugepage_files(struct hugepage_file *hugepg_tbl,
 		struct hugepage_file *hp = &hugepg_tbl[page];
 
 		if (hp->orig_va != NULL && unlink(hp->filepath)) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(WARNING, "%s(): Removing %s failed: %s",
-				__func__, hp->filepath, strerror(errno));
+				__func__, hp->filepath, errmsg);
 		}
 	}
 	return 0;
@@ -607,6 +629,7 @@  unmap_unneeded_hugepages(struct hugepage_file *hugepg_tbl,
 {
 	unsigned socket, size;
 	int page, nrpages = 0;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 
@@ -639,8 +662,12 @@  unmap_unneeded_hugepages(struct hugepage_file *hugepg_tbl,
 
 						hp->orig_va = NULL;
 						if (unlink(hp->filepath) == -1) {
+							if (strerror_r(errno, errmsg,
+							    sizeof(errmsg)) != 0)
+								snprintf(errmsg, sizeof(errmsg),
+									 "Unknown error %d", errno);
 							EAL_LOG(ERR, "%s(): Removing %s failed: %s",
-									__func__, hp->filepath, strerror(errno));
+								__func__, hp->filepath, errmsg);
 							return -1;
 						}
 					} else {
@@ -660,6 +687,7 @@  static int
 remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end)
 {
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct rte_memseg_list *msl;
 	struct rte_fbarray *arr;
 	int cur_page, seg_len;
@@ -735,14 +763,18 @@  remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end)
 
 		fd = open(hfile->filepath, O_RDWR);
 		if (fd < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "Could not open '%s': %s",
-					hfile->filepath, strerror(errno));
+					hfile->filepath, errmsg);
 			return -1;
 		}
 		/* set shared lock on the file. */
 		if (flock(fd, LOCK_SH) < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(DEBUG, "Could not lock '%s': %s",
-					hfile->filepath, strerror(errno));
+					hfile->filepath, errmsg);
 			close(fd);
 			return -1;
 		}
@@ -755,8 +787,10 @@  remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end)
 		addr = mmap(addr, page_sz, PROT_READ | PROT_WRITE,
 				MAP_SHARED | MAP_POPULATE | MAP_FIXED, fd, 0);
 		if (addr == MAP_FAILED) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "Couldn't remap '%s': %s",
-					hfile->filepath, strerror(errno));
+					hfile->filepath, errmsg);
 			close(fd);
 			return -1;
 		}
@@ -1129,6 +1163,7 @@  eal_legacy_hugepage_init(void)
 		eal_get_internal_configuration();
 
 	uint64_t memory[RTE_MAX_NUMA_NODES];
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	unsigned hp_offset;
 	int i, j;
@@ -1177,14 +1212,16 @@  eal_legacy_hugepage_init(void)
 		/* create a memfd and store it in the segment fd table */
 		memfd = memfd_create("nohuge", 0);
 		if (memfd < 0) {
-			EAL_LOG(DEBUG, "Cannot create memfd: %s",
-					strerror(errno));
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+			EAL_LOG(DEBUG, "Cannot create memfd: %s", errmsg);
 			EAL_LOG(DEBUG, "Falling back to anonymous map");
 		} else {
 			/* we got an fd - now resize it */
 			if (ftruncate(memfd, internal_conf->memory) < 0) {
-				EAL_LOG(ERR, "Cannot resize memfd: %s",
-						strerror(errno));
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+				EAL_LOG(ERR, "Cannot resize memfd: %s", errmsg);
 				EAL_LOG(ERR, "Falling back to anonymous map");
 				close(memfd);
 			} else {
@@ -1211,8 +1248,9 @@  eal_legacy_hugepage_init(void)
 		addr = mmap(prealloc_addr, mem_sz, PROT_READ | PROT_WRITE,
 				flags | MAP_FIXED, fd, 0);
 		if (addr == MAP_FAILED || addr != prealloc_addr) {
-			EAL_LOG(ERR, "%s: mmap() failed: %s", __func__,
-					strerror(errno));
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+			EAL_LOG(ERR, "%s: mmap() failed: %s", __func__, errmsg);
 			munmap(prealloc_addr, mem_sz);
 			return -1;
 		}
@@ -1520,6 +1558,7 @@  eal_legacy_hugepage_attach(void)
 {
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	struct hugepage_file *hp = NULL;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	unsigned int num_hp = 0;
 	unsigned int i = 0;
 	unsigned int cur_seg;
@@ -1570,23 +1609,29 @@  eal_legacy_hugepage_attach(void)
 
 		fd = open(hf->filepath, O_RDWR);
 		if (fd < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "Could not open %s: %s",
-				hf->filepath, strerror(errno));
+				hf->filepath, errmsg);
 			goto error;
 		}
 
 		map_addr = mmap(map_addr, map_sz, PROT_READ | PROT_WRITE,
 				MAP_SHARED | MAP_FIXED, fd, 0);
 		if (map_addr == MAP_FAILED) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "Could not map %s: %s",
-				hf->filepath, strerror(errno));
+				hf->filepath, errmsg);
 			goto fd_error;
 		}
 
 		/* set shared lock on the file. */
 		if (flock(fd, LOCK_SH) < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(DEBUG, "%s(): Locking file failed: %s",
-				__func__, strerror(errno));
+				__func__, errmsg);
 			goto mmap_error;
 		}
 
@@ -1918,6 +1963,7 @@  memseg_secondary_init(void)
 int
 rte_eal_memseg_init(void)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	/* increase rlimit to maximum */
 	struct rlimit lim;
 
@@ -1930,8 +1976,10 @@  rte_eal_memseg_init(void)
 		lim.rlim_cur = lim.rlim_max;
 
 		if (setrlimit(RLIMIT_NOFILE, &lim) < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(DEBUG, "Setting maximum number of open files failed: %s",
-					strerror(errno));
+					errmsg);
 		} else {
 			EAL_LOG(DEBUG, "Setting maximum number of open files to %"
 					PRIu64,
diff --git a/lib/eal/linux/eal_timer.c b/lib/eal/linux/eal_timer.c
index 489732c116..1ea4d82bb2 100644
--- a/lib/eal/linux/eal_timer.c
+++ b/lib/eal/linux/eal_timer.c
@@ -137,6 +137,7 @@  rte_eal_hpet_init(int make_default)
 	int fd, ret;
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	if (internal_conf->no_hpet) {
 		EAL_LOG(NOTICE, "HPET is disabled");
@@ -145,8 +146,9 @@  rte_eal_hpet_init(int make_default)
 
 	fd = open(DEV_HPET, O_RDONLY);
 	if (fd < 0) {
-		EAL_LOG(ERR, "ERROR: Cannot open "DEV_HPET": %s!",
-			strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "ERROR: Cannot open "DEV_HPET": %s!", errmsg);
 		internal_conf->no_hpet = 1;
 		return -1;
 	}
diff --git a/lib/eal/linux/eal_vfio.c b/lib/eal/linux/eal_vfio.c
index 7132e24cba..ed8eba76eb 100644
--- a/lib/eal/linux/eal_vfio.c
+++ b/lib/eal/linux/eal_vfio.c
@@ -351,6 +351,7 @@  vfio_open_group_fd(int iommu_group_num)
 {
 	int vfio_group_fd;
 	char filename[PATH_MAX];
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct rte_mp_msg mp_req, *mp_rep;
 	struct rte_mp_reply mp_reply = {0};
 	struct timespec ts = {.tv_sec = 5, .tv_nsec = 0};
@@ -367,8 +368,9 @@  vfio_open_group_fd(int iommu_group_num)
 		if (vfio_group_fd < 0) {
 			/* if file not found, it's not an error */
 			if (errno != ENOENT) {
-				EAL_LOG(ERR, "Cannot open %s: %s",
-						filename, strerror(errno));
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+				EAL_LOG(ERR, "Cannot open %s: %s", filename, errmsg);
 				return -1;
 			}
 
@@ -379,9 +381,12 @@  vfio_open_group_fd(int iommu_group_num)
 			vfio_group_fd = open(filename, O_RDWR);
 			if (vfio_group_fd < 0) {
 				if (errno != ENOENT) {
+					if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+						snprintf(errmsg, sizeof(errmsg),
+							 "Unknown error %d", errno);
 					EAL_LOG(ERR,
 						"Cannot open %s: %s",
-						filename, strerror(errno));
+						filename, errmsg);
 					return -1;
 				}
 				return -ENOENT;
@@ -745,6 +750,7 @@  rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
 	};
 	struct vfio_config *vfio_cfg;
 	struct user_mem_maps *user_mem_maps;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int vfio_container_fd;
 	int vfio_group_fd;
 	int iommu_group_num;
@@ -790,8 +796,10 @@  rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
 	/* check if the group is viable */
 	ret = ioctl(vfio_group_fd, VFIO_GROUP_GET_STATUS, &group_status);
 	if (ret) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "%s cannot get VFIO group status, "
-			"error %i (%s)", dev_addr, errno, strerror(errno));
+			"error %i (%s)", dev_addr, errno, errmsg);
 		close(vfio_group_fd);
 		rte_vfio_clear_group(vfio_group_fd);
 		return -1;
@@ -817,9 +825,11 @@  rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
 		ret = ioctl(vfio_group_fd, VFIO_GROUP_SET_CONTAINER,
 				&vfio_container_fd);
 		if (ret) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR,
 				"%s cannot add VFIO group to container, error "
-				"%i (%s)", dev_addr, errno, strerror(errno));
+				"%i (%s)", dev_addr, errno, errmsg);
 			close(vfio_group_fd);
 			rte_vfio_clear_group(vfio_group_fd);
 			return -1;
@@ -857,10 +867,12 @@  rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
 			else
 				ret = 0;
 			if (ret) {
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				EAL_LOG(ERR,
 					"%s DMA remapping failed, error "
 					"%i (%s)",
-					dev_addr, errno, strerror(errno));
+					dev_addr, errno, errmsg);
 				close(vfio_group_fd);
 				rte_vfio_clear_group(vfio_group_fd);
 				rte_mcfg_mem_read_unlock();
@@ -976,9 +988,10 @@  rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
 dev_get_info:
 	ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
 	if (ret) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "%s cannot get device info, "
-				"error %i (%s)", dev_addr, errno,
-				strerror(errno));
+				"error %i (%s)", dev_addr, errno, errmsg);
 		close(*vfio_dev_fd);
 		close(vfio_group_fd);
 		rte_vfio_clear_group(vfio_group_fd);
@@ -1205,6 +1218,7 @@  vfio_get_iommu_type(void)
 const struct vfio_iommu_type *
 vfio_set_iommu_type(int vfio_container_fd)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	unsigned idx;
 	for (idx = 0; idx < RTE_DIM(iommu_types); idx++) {
 		const struct vfio_iommu_type *t = &iommu_types[idx];
@@ -1216,10 +1230,11 @@  vfio_set_iommu_type(int vfio_container_fd)
 					t->type_id, t->name);
 			return t;
 		}
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		/* not an error, there may be more supported IOMMU types */
 		EAL_LOG(DEBUG, "Set IOMMU type %d (%s) failed, error "
-				"%i (%s)", t->type_id, t->name, errno,
-				strerror(errno));
+				"%i (%s)", t->type_id, t->name, errno, errmsg);
 	}
 	/* if we didn't find a suitable IOMMU type, fail */
 	return NULL;
@@ -1229,6 +1244,7 @@  int
 rte_vfio_get_device_info(const char *sysfs_base, const char *dev_addr,
 		int *vfio_dev_fd, struct vfio_device_info *device_info)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int ret;
 
 	if (device_info == NULL || *vfio_dev_fd < 0)
@@ -1241,9 +1257,11 @@  rte_vfio_get_device_info(const char *sysfs_base, const char *dev_addr,
 			return -1;
 	} else {
 		ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		if (ret) {
 			EAL_LOG(ERR, "%s cannot get device info, error %i (%s)",
-					dev_addr, errno, strerror(errno));
+					dev_addr, errno, errmsg);
 			return -1;
 		}
 	}
@@ -1254,6 +1272,7 @@  rte_vfio_get_device_info(const char *sysfs_base, const char *dev_addr,
 int
 vfio_has_supported_extensions(int vfio_container_fd)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int ret;
 	unsigned idx, n_extensions = 0;
 	for (idx = 0; idx < RTE_DIM(iommu_types); idx++) {
@@ -1262,8 +1281,10 @@  vfio_has_supported_extensions(int vfio_container_fd)
 		ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION,
 				t->type_id);
 		if (ret < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "Could not get IOMMU type, error "
-					"%i (%s)", errno, strerror(errno));
+				"%i (%s)", errno, errmsg);
 			close(vfio_container_fd);
 			return -1;
 		} else if (ret == 1) {
@@ -1288,6 +1309,7 @@  int
 rte_vfio_get_container_fd(void)
 {
 	int ret, vfio_container_fd;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct rte_mp_msg mp_req, *mp_rep;
 	struct rte_mp_reply mp_reply = {0};
 	struct timespec ts = {.tv_sec = 5, .tv_nsec = 0};
@@ -1300,21 +1322,25 @@  rte_vfio_get_container_fd(void)
 	if (internal_conf->process_type == RTE_PROC_PRIMARY) {
 		vfio_container_fd = open(VFIO_CONTAINER_PATH, O_RDWR);
 		if (vfio_container_fd < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR,
 					"Cannot open VFIO container %s, error "
 					"%i (%s)", VFIO_CONTAINER_PATH,
-					errno, strerror(errno));
+					errno, errmsg);
 			return -1;
 		}
 
 		/* check VFIO API version */
 		ret = ioctl(vfio_container_fd, VFIO_GET_API_VERSION);
 		if (ret != VFIO_API_VERSION) {
-			if (ret < 0)
+			if (ret < 0) {
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				EAL_LOG(ERR,
 					"Could not get VFIO API version, error "
-					"%i (%s)", errno, strerror(errno));
-			else
+					"%i (%s)", errno, errmsg);
+			} else
 				EAL_LOG(ERR, "Unsupported VFIO API version!");
 			close(vfio_container_fd);
 			return -1;
@@ -1422,6 +1448,7 @@  vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,
 {
 	struct vfio_iommu_type1_dma_map dma_map;
 	struct vfio_iommu_type1_dma_unmap dma_unmap;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int ret;
 
 	if (do_map != 0) {
@@ -1443,9 +1470,11 @@  vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,
 				EAL_LOG(DEBUG,
 					"Memory segment is already mapped, skipping");
 			} else {
+				if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+					snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 				EAL_LOG(ERR,
 					"Cannot set up DMA remapping, error "
-					"%i (%s)", errno, strerror(errno));
+					"%i (%s)", errno, errmsg);
 				return -1;
 			}
 		}
@@ -1458,8 +1487,10 @@  vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,
 		ret = ioctl(vfio_container_fd, VFIO_IOMMU_UNMAP_DMA,
 				&dma_unmap);
 		if (ret) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "Cannot clear DMA remapping, error "
-					"%i (%s)", errno, strerror(errno));
+					"%i (%s)", errno, errmsg);
 			return -1;
 		} else if (dma_unmap.size != len) {
 			EAL_LOG(ERR, "Unexpected size %"PRIu64
@@ -1493,6 +1524,7 @@  vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,
 		.size = len,
 		.flags = 0
 	};
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int ret;
 
 	if (do_map != 0) {
@@ -1506,9 +1538,11 @@  vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,
 		ret = ioctl(vfio_container_fd,
 				VFIO_IOMMU_SPAPR_REGISTER_MEMORY, &reg);
 		if (ret) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR,
 				"Cannot register vaddr for IOMMU, error "
-				"%i (%s)", errno, strerror(errno));
+				"%i (%s)", errno, errmsg);
 			return -1;
 		}
 
@@ -1522,8 +1556,10 @@  vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,
 
 		ret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map);
 		if (ret) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "Cannot map vaddr for IOMMU, error "
-					"%i (%s)", errno, strerror(errno));
+					"%i (%s)", errno, errmsg);
 			return -1;
 		}
 
@@ -1538,17 +1574,21 @@  vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,
 		ret = ioctl(vfio_container_fd, VFIO_IOMMU_UNMAP_DMA,
 				&dma_unmap);
 		if (ret) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "Cannot unmap vaddr for IOMMU, error "
-					"%i (%s)", errno, strerror(errno));
+					"%i (%s)", errno, errmsg);
 			return -1;
 		}
 
 		ret = ioctl(vfio_container_fd,
 				VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY, &reg);
 		if (ret) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR,
 				"Cannot unregister vaddr for IOMMU, error "
-				"%i (%s)", errno, strerror(errno));
+				"%i (%s)", errno, errmsg);
 			return -1;
 		}
 	}
@@ -1724,6 +1764,7 @@  vfio_spapr_create_dma_window(int vfio_container_fd)
 		.argsz = sizeof(remove), };
 	struct vfio_iommu_spapr_tce_info info = {
 		.argsz = sizeof(info), };
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int ret;
 
 	ret = spapr_dma_win_size();
@@ -1732,8 +1773,10 @@  vfio_spapr_create_dma_window(int vfio_container_fd)
 
 	ret = ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_GET_INFO, &info);
 	if (ret) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "Cannot get IOMMU info, error %i (%s)",
-			errno, strerror(errno));
+			errno, errmsg);
 		return -1;
 	}
 
@@ -1773,8 +1816,10 @@  vfio_spapr_create_dma_window(int vfio_container_fd)
 	}
 #endif /* VFIO_IOMMU_SPAPR_INFO_DDW */
 	if (ret) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "Cannot create new DMA window, error "
-				"%i (%s)", errno, strerror(errno));
+				"%i (%s)", errno, errmsg);
 		EAL_LOG(ERR,
 			"Consider using a larger hugepage size if supported by the system");
 		return -1;
@@ -2027,6 +2072,7 @@  container_dma_unmap(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova,
 int
 rte_vfio_noiommu_is_enabled(void)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int fd;
 	ssize_t cnt;
 	char c;
@@ -2034,8 +2080,10 @@  rte_vfio_noiommu_is_enabled(void)
 	fd = open(VFIO_NOIOMMU_MODE, O_RDONLY);
 	if (fd < 0) {
 		if (errno != ENOENT) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			EAL_LOG(ERR, "Cannot open VFIO noiommu file "
-					"%i (%s)", errno, strerror(errno));
+					"%i (%s)", errno, errmsg);
 			return -1;
 		}
 		/*
@@ -2048,8 +2096,10 @@  rte_vfio_noiommu_is_enabled(void)
 	cnt = read(fd, &c, 1);
 	close(fd);
 	if (cnt != 1) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(ERR, "Unable to read from VFIO noiommu file "
-				"%i (%s)", errno, strerror(errno));
+				"%i (%s)", errno, errmsg);
 		return -1;
 	}
 
diff --git a/lib/eal/unix/eal_filesystem.c b/lib/eal/unix/eal_filesystem.c
index 6cd5f1492c..d87924fe79 100644
--- a/lib/eal/unix/eal_filesystem.c
+++ b/lib/eal/unix/eal_filesystem.c
@@ -13,12 +13,14 @@ 
 #include <unistd.h>
 
 #include <rte_log.h>
+#include <rte_errno.h>
 
 #include "eal_private.h"
 #include "eal_filesystem.h"
 
 int eal_create_runtime_dir(void)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	const char *directory;
 	char run_dir[PATH_MAX];
 	char tmp[PATH_MAX];
@@ -58,15 +60,17 @@  int eal_create_runtime_dir(void)
 	 */
 	ret = mkdir(tmp, 0700);
 	if (ret < 0 && errno != EEXIST) {
-		EAL_LOG(ERR, "Error creating '%s': %s",
-			tmp, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "Error creating '%s': %s", tmp, errmsg);
 		return -1;
 	}
 
 	ret = mkdir(run_dir, 0700);
 	if (ret < 0 && errno != EEXIST) {
-		EAL_LOG(ERR, "Error creating '%s': %s",
-			run_dir, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(ERR, "Error creating '%s': %s", run_dir, errmsg);
 		return -1;
 	}
 
diff --git a/lib/eal/unix/eal_unix_memory.c b/lib/eal/unix/eal_unix_memory.c
index 4fd066a290..6bcbfe3091 100644
--- a/lib/eal/unix/eal_unix_memory.c
+++ b/lib/eal/unix/eal_unix_memory.c
@@ -27,12 +27,15 @@  static void *
 mem_map(void *requested_addr, size_t size, int prot, int flags,
 	int fd, uint64_t offset)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
+
 	void *virt = mmap(requested_addr, size, prot, flags, fd, offset);
 	if (virt == MAP_FAILED) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(DEBUG,
 		    "Cannot mmap(%p, 0x%zx, 0x%x, 0x%x, %d, 0x%"PRIx64"): %s",
-		    requested_addr, size, prot, flags, fd, offset,
-		    strerror(errno));
+		    requested_addr, size, prot, flags, fd, offset, errmsg);
 		rte_errno = errno;
 		return NULL;
 	}
@@ -42,10 +45,14 @@  mem_map(void *requested_addr, size_t size, int prot, int flags,
 static int
 mem_unmap(void *virt, size_t size)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
+
 	int ret = munmap(virt, size);
 	if (ret < 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(DEBUG, "Cannot munmap(%p, 0x%zx): %s",
-			virt, size, strerror(errno));
+			virt, size, errmsg);
 		rte_errno = errno;
 	}
 	return ret;
@@ -80,11 +87,15 @@  eal_mem_free(void *virt, size_t size)
 int
 eal_mem_set_dump(void *virt, size_t size, bool dump)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
+
 	int flags = dump ? EAL_DODUMP : EAL_DONTDUMP;
 	int ret = madvise(virt, size, flags);
 	if (ret) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		EAL_LOG(DEBUG, "madvise(%p, %#zx, %d) failed: %s",
-				virt, size, flags, strerror(errno));
+				virt, size, flags, errmsg);
 		rte_errno = errno;
 	}
 	return ret;
diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c
index 1b4c73f58e..c24fae8ea5 100644
--- a/lib/eal/unix/rte_thread.c
+++ b/lib/eal/unix/rte_thread.c
@@ -293,6 +293,7 @@  rte_thread_set_priority(rte_thread_t thread_id,
 int
 rte_thread_key_create(rte_thread_key *key, void (*destructor)(void *))
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int err;
 
 	*key = malloc(sizeof(**key));
@@ -303,8 +304,9 @@  rte_thread_key_create(rte_thread_key *key, void (*destructor)(void *))
 	}
 	err = pthread_key_create(&((*key)->thread_index), destructor);
 	if (err) {
-		EAL_LOG(DEBUG, "pthread_key_create failed: %s",
-			strerror(err));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(DEBUG, "pthread_key_create failed: %s", errmsg);
 		free(*key);
 		rte_errno = ENOEXEC;
 		return -1;
@@ -315,6 +317,7 @@  rte_thread_key_create(rte_thread_key *key, void (*destructor)(void *))
 int
 rte_thread_key_delete(rte_thread_key key)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int err;
 
 	if (!key) {
@@ -324,8 +327,9 @@  rte_thread_key_delete(rte_thread_key key)
 	}
 	err = pthread_key_delete(key->thread_index);
 	if (err) {
-		EAL_LOG(DEBUG, "pthread_key_delete failed: %s",
-			strerror(err));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(DEBUG, "pthread_key_delete failed: %s", errmsg);
 		free(key);
 		rte_errno = ENOEXEC;
 		return -1;
@@ -337,6 +341,7 @@  rte_thread_key_delete(rte_thread_key key)
 int
 rte_thread_value_set(rte_thread_key key, const void *value)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int err;
 
 	if (!key) {
@@ -346,8 +351,9 @@  rte_thread_value_set(rte_thread_key key, const void *value)
 	}
 	err = pthread_setspecific(key->thread_index, value);
 	if (err) {
-		EAL_LOG(DEBUG, "pthread_setspecific failed: %s",
-			strerror(err));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		EAL_LOG(DEBUG, "pthread_setspecific failed: %s", errmsg);
 		rte_errno = ENOEXEC;
 		return -1;
 	}