-
Notifications
You must be signed in to change notification settings - Fork 824
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
Fixed WASI isatty #1213
Fixed WASI isatty #1213
Conversation
This is a C file I created to debug the issue: #include <wasi/core.h>
#include <__errno.h>
int __isatty_check(int fd) {
__wasi_fdstat_t statbuf;
int r = __wasi_fd_fdstat_get(fd, &statbuf);
if (r != 0) {
errno = r;
return 0;
}
printf("fs_filetype: %i %i (=%i), rightbase: %i %i\n", statbuf.fs_filetype, __WASI_FILETYPE_CHARACTER_DEVICE, statbuf.fs_filetype != __WASI_FILETYPE_CHARACTER_DEVICE, statbuf.fs_rights_base, statbuf.fs_rights_base & (__WASI_RIGHT_FD_SEEK | __WASI_RIGHT_FD_TELL)); fflush(stdout);
// A tty is a character device that we can't seek or tell on.
if (statbuf.fs_filetype != __WASI_FILETYPE_CHARACTER_DEVICE ||
(statbuf.fs_rights_base & (__WASI_RIGHT_FD_SEEK | __WASI_RIGHT_FD_TELL)) != 0) {
errno = __WASI_ENOTTY;
return 0;
}
return 1;
} |
bors try |
tryBuild succeeded
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice fix!
We'll probably want to update the WasiFile
trait so that our file swapping API works properly with this too, but that can be done as a follow up.
Edit: to clarify I mean pushing the "is this a TTY?" logic into the trait so that users can control the output here and that stdout, stdin, and stderr continue to return the correct results even when they're not FDs 0, 1, 2
bors r+ |
1213: Fixed WASI isatty r=syrusakbary a=syrusakbary <!-- Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test: https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests --> # Description Current WASI implementation returns a wrong response when libc `isatty` is used for `stdin`, `stdout` or `stderr`. This PR fixes it. <!-- Provide details regarding the change including motivation, links to related issues, and the context of the PR. --> # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Syrus <[email protected]> Co-authored-by: Syrus Akbary <[email protected]>
Build succeeded
|
Description
Current WASI implementation returns a wrong response when libc
isatty
is used forstdin
,stdout
orstderr
.This PR fixes it.
Review