From 7d550e5a83ddf6808d669f3093c2c4c6c27181c5 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Tue, 19 Nov 2024 10:43:39 +0900 Subject: [PATCH] btrfs-progs: utils: ask_user: flush stdout after prompt when stdio is line buffered printf will not flush anything (on musl?), leaving the program hanging without displaying any prompt and weird dialogs such as the following: ``` alpine:~# btrfstune -S 0 /dev/mmcblk1p1 WARNING: this is dangerous, clearing the seeding flag may cause the derived device not to be mountable! y WARNING: seeding flag is not set on /dev/mmcblk1p1 We are going to clear the seeding flag, are you sure? [y/N]: alpine:~# ``` forcing flush makes the prompt display properly Signed-off-by: Dominique Martinet Reviewed-by: Qu Wenruo --- common/utils.c | 1 + 1 file changed, 1 insertion(+) diff --git a/common/utils.c b/common/utils.c index 3ca7cff396..9515abd47a 100644 --- a/common/utils.c +++ b/common/utils.c @@ -416,6 +416,7 @@ int ask_user(const char *question) char *answer; printf("%s [y/N]: ", question); + fflush(stdout); return fgets(buf, sizeof(buf) - 1, stdin) && (answer = strtok_r(buf, " \t\n\r", &saveptr)) &&