[v3,1/8] eal: log: close on cleanup
diff mbox series

Message ID 20200428235827.15383-2-stephen@networkplumber.org
State New
Delegated to: David Marchand
Headers show
Series
  • eal: cleanup resources on shutdown
Related show

Checks

Context Check Description
ci/Intel-compilation fail Compilation issues
ci/iol-testing fail Testing issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger April 28, 2020, 11:58 p.m. UTC
When application calls rte_eal_cleanup on shutdown,
the DPDK log should be closed and cleaned up.

Fixes: af75078fece3 ("first public release")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/common/eal_common_log.c | 12 ++++++++++++
 lib/librte_eal/common/eal_private.h    | 13 +++++++++++++
 lib/librte_eal/linux/eal.c             |  1 +
 lib/librte_eal/linux/eal_log.c         | 14 ++++++++++++++
 4 files changed, 40 insertions(+)

Patch
diff mbox series

diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index d7a5f9b6417a..43de798ae96a 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -479,3 +479,15 @@  eal_log_set_default(FILE *default_log)
 		"Debug dataplane logs available - lower performance\n");
 #endif
 }
+
+/*
+ * Called by environment-specific cleanup function.
+ */
+void
+eal_log_cleanup(void)
+{
+	if (default_log_stream) {
+		fclose(default_log_stream);
+		default_log_stream = NULL;
+	}
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index ecf827914fdd..24ddfc6c53f4 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -89,6 +89,12 @@  int rte_eal_memzone_init(void);
  */
 void eal_log_set_default(FILE *default_log);
 
+/**
+ * Common log cleanup function (private to eal).
+ * Closes the default log stream. Called from rte_eal_cleanup().
+ */
+void eal_log_cleanup(void);
+
 /**
  * Fill configuration with number of physical and logical processors
  *
@@ -150,6 +156,13 @@  int rte_eal_timer_init(void);
  */
 int rte_eal_log_init(const char *id, int facility);
 
+/**
+ * Close the default log stream
+ *
+ * This function is private to EAL.
+ */
+void rte_eal_log_cleanup(void);
+
 /**
  * Save the log regexp for later
  */
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index aa72d3650929..73d2c98b012b 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -1337,6 +1337,7 @@  rte_eal_cleanup(void)
 	rte_trace_save();
 	eal_trace_fini();
 	eal_cleanup_config(&internal_config);
+	rte_eal_log_cleanup();
 	return 0;
 }
 
diff --git a/lib/librte_eal/linux/eal_log.c b/lib/librte_eal/linux/eal_log.c
index 43c8460bfb07..258a16ff2498 100644
--- a/lib/librte_eal/linux/eal_log.c
+++ b/lib/librte_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,
 };
 
 /*
@@ -60,3 +68,9 @@  rte_eal_log_init(const char *id, int facility)
 
 	return 0;
 }
+
+void
+rte_eal_log_cleanup(void)
+{
+	eal_log_cleanup();
+}