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 <dominique.martinet@atmark-techno.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
This commit is contained in:
Dominique Martinet 2024-11-19 10:43:39 +09:00 committed by Qu Wenruo
parent 479103c705
commit 7d550e5a83
1 changed files with 1 additions and 0 deletions

View File

@ -416,6 +416,7 @@ int ask_user(const char *question)
char *answer; char *answer;
printf("%s [y/N]: ", question); printf("%s [y/N]: ", question);
fflush(stdout);
return fgets(buf, sizeof(buf) - 1, stdin) && return fgets(buf, sizeof(buf) - 1, stdin) &&
(answer = strtok_r(buf, " \t\n\r", &saveptr)) && (answer = strtok_r(buf, " \t\n\r", &saveptr)) &&