write_string(fmt_buf);
}
+int SigSafePrinter::flush()
+{
+ if (fd >= 0)
+ return fsync(fd);
+ return 0;
+}
+
#ifdef CATCH_TEST_BUILD
#include <cinttypes>
+#include <iostream>
#include "catch/catch.hpp"
SigSafePrinter(actual, sizeof(actual)).hex_dump(data, sizeof(data));
CHECK_THAT(expected, Equals(actual));
}
+ SECTION("flush buffer")
+ {
+ snprintf(expected, sizeof(expected), "%32s", "test");
+ SigSafePrinter ssp(actual, sizeof(actual));
+ ssp.printf("%32s", "test");
+ ssp.flush();
+ CHECK_THAT(expected, Equals(actual));
+ }
+ SECTION("flush fd")
+ {
+ SigSafePrinter ssp(STDOUT_FILENO);
+ ssp.flush();
+ }
}
#endif
SigSafePrinter(char *buf, size_t size);
SigSafePrinter(int fd) : fd(fd) { }
+ int flush();
void hex_dump(const uint8_t* data, unsigned len);
void printf(const char* format, ...);
if ( !is_main_thread )
OopsHandler::handle_crash(STDERR_FILENO);
+ if (ssp.flush() != 0)
+ ssp.printf("Failed to flush output. Error: %s\n", strerror(errno));
+
// Finally, raise the signal so that the original handler can handle it.
raise(signal);
}