]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: warning if truncation occurred dumping the trace. 13477/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 10 Nov 2023 08:19:58 +0000 (09:19 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 10 Nov 2023 11:11:15 +0000 (12:11 +0100)
This can happen when writing to e.g. a terminal. While the detection is reliable
the message to stderr is not (it also might return EAGAIN). But often enough it works.
The existing log entry *is* reliable.

pdns/recursordist/pdns_recursor.cc

index b2a90eaa0fe9475d8b46ce92c3c1078fc1acc1cf..9d7d10a3d4cbf535765f507083dcd9b8754b8530 100644 (file)
@@ -870,11 +870,16 @@ static void dumpTrace(const string& trace, const timeval& timev)
   fprintf(filep.get(), " us === START OF TRACE %s ===\n", timebuf.data());
   fprintf(filep.get(), "%s", trace.c_str());
   isoDateTimeMillis(now, timebuf.data(), timebuf.size());
-  fprintf(filep.get(), "=== END OF TRACE %s ===\n", timebuf.data());
   if (ferror(filep.get()) != 0) {
     int err = errno;
     SLOG(g_log << Logger::Error << "Problems writing to trace file: " << stringerror(err) << endl,
          g_slog->withName("trace")->error(Logr::Error, err, "Problems writing to trace file"));
+    // There's no guarantee the message below will end up in the stream, but we try our best
+    clearerr(filep.get());
+    fprintf(filep.get(), "=== TRACE %s TRUNCATED; USE FILE ARGUMENT INSTEAD OF `-' ===\n", timebuf.data());
+  }
+  else {
+    fprintf(filep.get(), "=== END OF TRACE %s ===\n", timebuf.data());
   }
   // fclose by unique_ptr does implicit flush
 }