From: Otto Moerbeek Date: Fri, 10 Nov 2023 08:19:58 +0000 (+0100) Subject: rec: warning if truncation occurred dumping the trace. X-Git-Tag: rec-5.0.0-rc1~51^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=68d5b3461a33aa913b7f49bb03b88b807cd1874e;p=thirdparty%2Fpdns.git rec: warning if truncation occurred dumping the trace. 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. --- diff --git a/pdns/recursordist/pdns_recursor.cc b/pdns/recursordist/pdns_recursor.cc index b2a90eaa0f..9d7d10a3d4 100644 --- a/pdns/recursordist/pdns_recursor.cc +++ b/pdns/recursordist/pdns_recursor.cc @@ -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 }