diff mbox series

[38/47] libsemanage: avoid strerror(3)

Message ID 20241111141706.38039-38-cgoettsche@seltendoof.de (mailing list archive)
State New
Delegated to: Petr Lautrbach
Headers show
Series [01/47] libsemanage: white space cleanup | expand

Commit Message

Christian Göttsche Nov. 11, 2024, 2:16 p.m. UTC
From: Christian Göttsche <cgzones@googlemail.com>

Use the %m printf modifier to format errno in a thread safe way.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libsemanage/src/debug.c          | 6 ++++--
 libsemanage/src/semanage_store.c | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libsemanage/src/debug.c b/libsemanage/src/debug.c
index 1e375694..a2708279 100644
--- a/libsemanage/src/debug.c
+++ b/libsemanage/src/debug.c
@@ -79,8 +79,10 @@  void semanage_msg_default_handler(void *varg __attribute__ ((unused)),
 	vfprintf(stream, fmt, ap);
 	va_end(ap);
 
-	if (errsv && errsv != ENOMEM)
-		fprintf(stream, " (%s).", strerror(errsv));
+	if (errsv && errsv != ENOMEM) {
+		errno = errsv;
+		fprintf(stream, " (%m).");
+	}
 
 	fprintf(stream, "\n");
 }
diff --git a/libsemanage/src/semanage_store.c b/libsemanage/src/semanage_store.c
index 98ef2524..68bc8c41 100644
--- a/libsemanage/src/semanage_store.c
+++ b/libsemanage/src/semanage_store.c
@@ -739,8 +739,8 @@  static int semanage_rename(semanage_handle_t * sh, const char *src, const char *
 		return retval;
 
 	/* we can't use rename() due to filesystem limitation, lets try to copy files manually */
-	WARN(sh, "WARNING: rename(%s, %s) failed: %s, fall back to non-atomic semanage_copy_dir_flags()",
-		 src, dst, strerror(errno));
+	WARN(sh, "WARNING: rename(%s, %s) failed: %m, fall back to non-atomic semanage_copy_dir_flags()",
+		 src, dst);
 	if (semanage_copy_dir_flags(src, dst, 1) == -1) {
 		return -1;
 	}