summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ccache.c3
-rw-r--r--src/ccache.h1
-rw-r--r--src/exitfn.c22
-rw-r--r--src/stats.c2
4 files changed, 24 insertions, 4 deletions
diff --git a/src/ccache.c b/src/ccache.c
index e7790040..0665582f 100644
--- a/src/ccache.c
+++ b/src/ccache.c
@@ -3427,7 +3427,8 @@ ccache(int argc, char *argv[])
cc_log("Object file: %s", output_obj);
- exitfn_add(dump_log_buffer_exitfn, output_obj);
+ // Need to dump log buffer as the last exit function to not lose any logs.
+ exitfn_add_last(dump_log_buffer_exitfn, output_obj);
FILE *debug_text_file = NULL;
if (conf->debug) {
diff --git a/src/ccache.h b/src/ccache.h
index bb0a4292..1c769f82 100644
--- a/src/ccache.h
+++ b/src/ccache.h
@@ -228,6 +228,7 @@ void stats_write(const char *path, struct counters *counters);
void exitfn_init(void);
void exitfn_add_nullary(void (*function)(void));
void exitfn_add(void (*function)(void *), void *context);
+void exitfn_add_last(void (*function)(void *), void *context);
void exitfn_call(void);
// ----------------------------------------------------------------------------
diff --git a/src/exitfn.c b/src/exitfn.c
index 5c2c482c..5be5e220 100644
--- a/src/exitfn.c
+++ b/src/exitfn.c
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2016 Joel Rosdahl
+// Copyright (C) 2010-2018 Joel Rosdahl
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
@@ -56,7 +56,7 @@ exitfn_add_nullary(void (*function)(void))
}
// Add a function to be called with a context parameter when ccache exits.
-// Functions are called in reverse order.
+// Functions are called in LIFO order except when added via exitfn_add_last.
void
exitfn_add(void (*function)(void *), void *context)
{
@@ -67,6 +67,24 @@ exitfn_add(void (*function)(void *), void *context)
exit_functions = p;
}
+// Add a function to be called with a context parameter when ccache exits. In
+// contrast to exitfn_add, exitfn_add_last sets up the function to be called
+// last.
+void
+exitfn_add_last(void (*function)(void *), void *context)
+{
+ struct exit_function *p = x_malloc(sizeof(*p));
+ p->function = function;
+ p->context = context;
+ p->next = NULL;
+
+ struct exit_function **q = &exit_functions;
+ while (*q) {
+ q = &(*q)->next;
+ }
+ *q = p;
+}
+
// Call added functions.
void
exitfn_call(void)
diff --git a/src/stats.c b/src/stats.c
index d8b15c01..ef6a2914 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -389,7 +389,7 @@ stats_flush(void)
stats_write(stats_file, counters);
lockfile_release(stats_file);
- if (!str_eq(conf->log_file, "")) {
+ if (!str_eq(conf->log_file, "") || conf->debug) {
for (int i = 0; i < STATS_END; ++i) {
if (counter_updates->data[stats_info[i].stat] != 0
&& !(stats_info[i].flags & FLAG_NOZERO)) {