Call setvbuf at the beginning of main
From cppreference:
This function may only be used after stream has been
associated with an open file, but before any other operation
(other than a failed call to setbuf/setvbuf).
Test: watch TH
Change-Id: I70d331c9150efc2a2b5e92f8b2933ef8214d1ce9
diff --git a/microdroid/kdump/crashdump.c b/microdroid/kdump/crashdump.c
index 47d359a..8dc84e9 100644
--- a/microdroid/kdump/crashdump.c
+++ b/microdroid/kdump/crashdump.c
@@ -42,6 +42,12 @@
extern int __reboot(int, int, int, void*);
int main() {
+ // Disable buffering for better display of the progress
+ if (setvbuf(stdout, NULL, _IONBF, 0) != 0) {
+ fprintf(stderr, "Failed to disable buffering for stdout: %s\n", strerror(errno));
+ // This isn't a critical error. Continue.
+ }
+
printf("Crashdump started\n");
if (mount("proc", "/proc", "proc", 0, NULL) == -1) {
@@ -87,12 +93,6 @@
char buf[BUF_SIZE];
int progress = 0; // percentage
- // Disable buffering for better display of the progress
- if (setvbuf(stdout, NULL, _IONBF, 0) != 0) {
- fprintf(stderr, "Failed to disable buffering for stdout: %s\n", strerror(errno));
- // This isn't a critical error. Continue.
- }
-
while (dumped < statbuf.st_size) {
ssize_t read_bytes = read(vmcore, buf, BUF_SIZE);
if (read_bytes == -1) {