]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fix bugs in the newly introduced tracing mode (#386)
authorAnders Björklund <anders.f.bjorklund@gmail.com>
Mon, 22 Apr 2019 13:09:18 +0000 (15:09 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 22 Apr 2019 13:09:18 +0000 (15:09 +0200)
* The tracefile variable is not used anymore

This caused trace files to be left in /tmp

* Fix crash in tracing mode, caused by logging

Unfortunately cc_log() requires conf to work

src/ccache.c

index 1433eb179da6ce722c13274a09d4b596136c1b1e..da6bf360246bafd72d24e2c038f8b792ff45d0ed 100644 (file)
@@ -3554,7 +3554,6 @@ static void
 trace_start(const char *json)
 {
        trace_file = json;
-       cc_log("Starting tracing: %s", json);
        MTR_META_PROCESS_NAME(MYNAME);
        trace_id = (void *) ((long) getpid());
        MTR_START("program", "ccache", trace_id);
@@ -3563,17 +3562,12 @@ trace_start(const char *json)
 static void
 trace_stop(void *context)
 {
-       const char *json = (const char *) context;
-       if (str_eq(json, "")) {
-               json = format("%s%s", output_obj, ".ccache-trace");
-       }
-       cc_log("Stopping tracing: %s", json);
+       (void) context;
+       const char *json = format("%s%s", output_obj, ".ccache-trace");
        MTR_FINISH("program", "ccache", trace_id);
        mtr_flush();
        mtr_shutdown();
-       if (!str_eq(trace_file, json)) {
-               move_file(trace_file, json, 0);
-       }
+       move_file(trace_file, json, 0);
 }
 
 static const char *
@@ -3608,8 +3602,6 @@ initialize(void)
                tracefile = format("%s/trace.%d.json", tmpdir(), (int)getpid());
 
                trace_init(tracefile);
-#else
-               cc_log("Error: tracing is not enabled!");
 #endif
        }
 
@@ -3683,12 +3675,14 @@ initialize(void)
                umask(conf->umask);
        }
 
-#ifdef MTR_ENABLED
        if (tracefile != NULL) {
+#ifdef MTR_ENABLED
                trace_start(tracefile);
-               exitfn_add(trace_stop, tracefile);
-       }
+               exitfn_add(trace_stop, NULL);
+#else
+               cc_log("Error: tracing is not enabled!");
 #endif
+       }
 }
 
 // Reset the global state. Used by the test suite.