Skip to content

move stdio fd handle checking in fd_determine_type_rights to ensure type is properly set before return #4395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SneezingCactus
Copy link

Before this change, fd_determine_type_rights would return early upon dealing with a stdio file handle without giving it any type (therefore being left as a __WASI_FILETYPE_UNKNOWN). This would end up having repercussions on wasi-sdk's implementation of vfprintf, which doesn't register line breaks properly if the file it's writing to (stdout in the case of printf) isn't a tty, which is mainly checked by seeing if the file is a CHARACTER_DEVICE.

@lum1n0us
Copy link
Collaborator

This would end up having repercussions on wasi-sdk's implementation of vfprintf, which doesn't register line breaks properly if the file it's writing to (stdout in the case of printf) isn't a tty, which is mainly checked by seeing if the file is a CHARACTER_DEVICE.

Would you mind pointing out the source code in wasi-libc related to that?

fd_determine_type_rights would return early upon dealing with a stdio file handle without giving it any type

IIUC, *type = buf.st_filetype; is the key to ⬆️ problem. So how about moving L527~L540 to L469 and return directly.

@yamt
Copy link
Collaborator

yamt commented Jun 24, 2025

This would end up having repercussions on wasi-sdk's implementation of vfprintf, which doesn't register line breaks properly if the file it's writing to (stdout in the case of printf) isn't a tty, which is mainly checked by seeing if the file is a CHARACTER_DEVICE.

Would you mind pointing out the source code in wasi-libc related to that?

https://github.com/WebAssembly/wasi-libc/blob/1377a93acea031acd9b6e77a830360d88477319c/libc-bottom-half/sources/isatty.c

fd_determine_type_rights would return early upon dealing with a stdio file handle without giving it any type

IIUC, *type = buf.st_filetype; is the key to ⬆️ problem. So how about moving L527~L540 to L469 and return directly.

i feel it's better to revert #3694 and investigate the original issue because it was based on a broken experiment: #3686 (comment)

@lum1n0us
Copy link
Collaborator

I feel this PR is primarily about ensuring *type is assigned as an output parameter, which the original code missed. We might want to reopen the discussion on 3686.

@yamt
Copy link
Collaborator

yamt commented Jul 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants