diff mbox series

[v6,1/5] eal: close log in eal_cleanup

Message ID 20211113172257.6543-2-stephen@networkplumber.org (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers show
Series cleanup more resources on eal_cleanup | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Nov. 13, 2021, 5:22 p.m. UTC
When application calls rte_eal_cleanup on shutdown,
the DPDK log should be closed and cleaned up.

This helps reduce false reports from tools like ASAN
and valgrind that track memory leaks.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eal/common/eal_common_log.c | 13 +++++++++++++
 lib/eal/common/eal_private.h    |  7 +++++++
 lib/eal/linux/eal.c             |  1 +
 lib/eal/linux/eal_log.c         |  8 ++++++++
 4 files changed, 29 insertions(+)
diff mbox series

Patch

diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c
index 1be35f539727..cbd0b851f216 100644
--- a/lib/eal/common/eal_common_log.c
+++ b/lib/eal/common/eal_common_log.c
@@ -18,6 +18,7 @@ 
 #include <rte_per_lcore.h>
 
 #include "eal_log.h"
+#include "eal_private.h"
 
 struct rte_log_dynamic_type {
 	const char *name;
@@ -535,3 +536,15 @@  eal_log_set_default(FILE *default_log)
 		"Debug dataplane logs available - lower performance\n");
 #endif
 }
+
+/*
+ * Called by eal_cleanup
+ */
+void
+rte_eal_log_cleanup(void)
+{
+	if (default_log_stream) {
+		fclose(default_log_stream);
+		default_log_stream = NULL;
+	}
+}
diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h
index 36bcc0b5a492..2fbad534b938 100644
--- a/lib/eal/common/eal_private.h
+++ b/lib/eal/common/eal_private.h
@@ -152,6 +152,13 @@  int rte_eal_tailqs_init(void);
  */
 int rte_eal_intr_init(void);
 
+/**
+ * Close the default log stream
+ *
+ * This function is private to EAL.
+ */
+void rte_eal_log_cleanup(void);
+
 /**
  * Init alarm mechanism. This is to allow a callback be called after
  * specific time.
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 60b49248388e..b67030b2792e 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -1370,6 +1370,7 @@  rte_eal_cleanup(void)
 	rte_trace_save();
 	eal_trace_fini();
 	eal_cleanup_config(internal_conf);
+	rte_eal_log_cleanup();
 	return 0;
 }
 
diff --git a/lib/eal/linux/eal_log.c b/lib/eal/linux/eal_log.c
index c0aa1007c4df..5a795ac9ebe3 100644
--- a/lib/eal/linux/eal_log.c
+++ b/lib/eal/linux/eal_log.c
@@ -37,8 +37,16 @@  console_log_write(__rte_unused void *c, const char *buf, size_t size)
 	return ret;
 }
 
+static int
+console_log_close(__rte_unused void *c)
+{
+	closelog();
+	return 0;
+}
+
 static cookie_io_functions_t console_log_func = {
 	.write = console_log_write,
+	.close = console_log_close,
 };
 
 /*