From f47cfaf0a90218fc3fe692b9309bbba9622f189d Mon Sep 17 00:00:00 2001
From: Sebastian Reimers <hallo@studio-link.de>
Date: Fri, 29 Sep 2023 15:30:47 +0200
Subject: [PATCH] trace: remove global default trace json

Trace initialization should be handled by application (moving this to baresip)
---
 .gitignore      |  1 -
 src/main/init.c |  8 --------
 test/trace.c    | 15 +++++++++++++++
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/.gitignore b/.gitignore
index 773dcf20a..5510c59c4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,7 +9,6 @@ libre.*dylib
 libre.pc
 libre.so*
 *.gcov
-re_trace.json
 
 # Windows build folder
 Win32/*
diff --git a/src/main/init.c b/src/main/init.c
index b84012979..0d99f80e5 100644
--- a/src/main/init.c
+++ b/src/main/init.c
@@ -168,10 +168,6 @@ int libre_init(void)
 		return err;
 	}
 
-#ifdef RE_TRACE_ENABLED
-	re_trace_init("re_trace.json");
-#endif
-
 	err = re_thread_init();
 
 	return err;
@@ -183,10 +179,6 @@ int libre_init(void)
  */
 void libre_close(void)
 {
-
-#ifdef RE_TRACE_ENABLED
-	re_trace_close();
-#endif
 	(void)fd_setsize(0);
 	net_sock_close();
 	re_thread_close();
diff --git a/test/trace.c b/test/trace.c
index f92bac75a..be85c828e 100644
--- a/test/trace.c
+++ b/test/trace.c
@@ -28,6 +28,9 @@ int test_trace(void)
 	if (test_mode == TEST_THREAD)
 		return ESKIPPED;
 
+	err = re_trace_init("test_trace.json");
+	TEST_ERR(err);
+
 	RE_TRACE_PROCESS_NAME("retest");
 	RE_TRACE_THREAD_NAME("test_trace");
 	RE_TRACE_BEGIN("test", "Test Loop Start");
@@ -51,6 +54,18 @@ int test_trace(void)
 
 	RE_TRACE_END("test", "Test Loop End");
 
+	err = re_trace_close();
+	TEST_ERR(err);
+
+	/* Test TRACE after close - should do nothing */
+	RE_TRACE_BEGIN("test", "test after close");
+
+#ifdef WIN32
+	(void)_unlink("test_trace.json");
+#else
+	(void)unlink("test_trace.json");
+#endif
+
 out:
 	return err;
 }