Skip to content
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

Merged
merged 5 commits into from
Feb 13, 2020
Merged

Fixed WASI isatty #1213

merged 5 commits into from
Feb 13, 2020

Conversation

syrusakbary
Copy link
Member

@syrusakbary syrusakbary commented Feb 13, 2020

Description

Current WASI implementation returns a wrong response when libc isatty is used for stdin, stdout or stderr.

This PR fixes it.

Review

  • Add a short description of the the change to the CHANGELOG.md file

@syrusakbary
Copy link
Member Author

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;

}

@syrusakbary
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Feb 13, 2020
@bors
Copy link
Contributor

bors bot commented Feb 13, 2020

try

Build succeeded

@Hywan Hywan added bug Something isn't working 📦 lib-wasi About wasmer-wasi 🧪 tests I love tests labels Feb 13, 2020
Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a 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

@syrusakbary
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Feb 13, 2020
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 <me@syrusakbary.com>
Co-authored-by: Syrus Akbary <me@syrusakbary.com>
@bors
Copy link
Contributor

bors bot commented Feb 13, 2020

Build succeeded

@bors bors bot merged commit 7a45bd8 into master Feb 13, 2020
@bors bors bot deleted the fix/isatty branch February 13, 2020 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-wasi About wasmer-wasi 🧪 tests I love tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants