use ::write and ::fsync in error path (#443)
* use ::write and ::fsync in error path Signed-off-by: SchrodingerZhu <i@zhuyi.fan> * mark return value unused Signed-off-by: SchrodingerZhu <i@zhuyi.fan> * adjust fsync positions Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
This commit is contained in:
committed by
GitHub
parent
d0df2d028a
commit
37d2ac42af
@@ -151,10 +151,9 @@ namespace snmalloc
|
||||
constexpr int SIZE = 1024;
|
||||
void* buffer[SIZE];
|
||||
auto nptrs = backtrace(buffer, SIZE);
|
||||
fflush(stdout);
|
||||
backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO);
|
||||
puts("");
|
||||
fflush(stdout);
|
||||
UNUSED(write(STDOUT_FILENO, "\n", 1));
|
||||
UNUSED(fsync(STDOUT_FILENO));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -163,7 +162,14 @@ namespace snmalloc
|
||||
*/
|
||||
[[noreturn]] static void error(const char* const str) noexcept
|
||||
{
|
||||
puts(str);
|
||||
/// by this part, the allocator is failed; so we cannot assume
|
||||
/// subsequent allocation will work.
|
||||
/// @attention: since the program is failing, we do not guarantee that
|
||||
/// previous bytes in stdout will be flushed
|
||||
UNUSED(write(STDOUT_FILENO, "\n", 1));
|
||||
UNUSED(write(STDOUT_FILENO, str, strlen(str)));
|
||||
UNUSED(write(STDOUT_FILENO, "\n", 1));
|
||||
UNUSED(fsync(STDOUT_FILENO));
|
||||
print_stack_trace();
|
||||
abort();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user