Skip to content

Commit

Permalink
btrfs-progs: utils: ask_user: flush stdout after prompt
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Qu Wenruo <[email protected]>
  • Loading branch information
martinetd authored and adam900710 committed Nov 19, 2024
1 parent bc574b1 commit 206baf7
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) &&
Expand Down

0 comments on commit 206baf7

Please sign in to comment.