aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--tools/ok.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/tools/ok.cpp b/tools/ok.cpp
index edda9bede0..8d24b4ddcb 100644
--- a/tools/ok.cpp
+++ b/tools/ok.cpp
@@ -69,13 +69,14 @@ static thread_local const char* tls_currently_running = "";
static void defer_logging() {
log_fd = fileno(tmpfile());
- atexit([] {
- lseek(log_fd, 0, SEEK_SET);
- char buf[1024];
- while (size_t bytes = read(log_fd, buf, sizeof(buf))) {
- write(2, buf, bytes);
- }
- });
+ }
+
+ static void print_deferred_logs() {
+ lseek(log_fd, 0, SEEK_SET);
+ char buf[1024];
+ while (size_t bytes = read(log_fd, buf, sizeof(buf))) {
+ write(2/*stderr*/, buf, bytes);
+ }
}
void ok_log(const char* msg) {
@@ -91,6 +92,7 @@ static thread_local const char* tls_currently_running = "";
#else
static void setup_crash_handler() {}
static void defer_logging() {}
+ static void print_deferred_logs() {}
void ok_log(const char* msg) {
fprintf(stderr, "%s\n", msg);
@@ -153,7 +155,7 @@ struct ThreadEngine : Engine {
struct ForkEngine : Engine {
bool spawn(std::function<Status(void)> fn) override {
switch (fork()) {
- case 0: _exit((int)fn());
+ case 0: exit((int)fn());
case -1: return false;
default: return true;
}
@@ -332,6 +334,7 @@ int main(int argc, char** argv) {
update_stats(s);
}
printf("\n");
+ print_deferred_logs();
return (failed || crashed) ? 1 : 0;
}