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

fix(wasi) Fix the logic behind inherited/captured stdin, stdout and stderr #2059

Merged
merged 6 commits into from
Jan 26, 2021

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Jan 26, 2021

Description

This patch is both a fix and a feature!

First, let's no longer derive from Default for wasi_config_t. By
default, we want to inherit stdin, stdout and stderr. The
default for bool is false; we want true here.

Second, let's update wasi_config_new to correctly set inherit_*
fields to true.

Third, lets' create wasi_config_capture_* functions. By default,
std* are inherited, so we need functions to capture them. That's the
new feature this patch introduces. The wasi_config_inherit_*
functions are kept for the sake of backward compatibility. Ideally, we
would want an API like wasi_config_capture_*(capture: bool), but it
would duplicate the API somehow.

Fourth, let's fix wasi_env_new. We want to capture stdout and
stderr if and only if the inherit_* fields are set to
false. There was bug here. That's why everything was working
correctly by the way: bool::default() is false, and we have this
inverted condition here, so everything was working as expected because
of a double error. The only bug was that it wasn't possible to capture
std* before.

Review

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

Hywan added 2 commits January 26, 2021 14:12
…nd `stderr`.

First, let's no longer derive from `Default` for `wasi_config_t`. By
default, we want to inherit `stdin`, `stdout` and `stderr`. The
default for `bool` is `false`; we want `true` here.

Second, let's update `wasi_config_new` to correctly set `inherit_*`
fields to `true`.

Third, lets' create `wasi_config_capture_*` functions. By default,
`std*` are inherited, so we need functions to capture them. That's the
new feature this patch introduces. The `wasi_config_inherit_*`
functions are kept for the sake of backward compatibility. Ideally, we
would want an API like `wasi_config_capture_*(capture: bool)`, but it
would duplicate the API somehow.

Fourth, let's fix `wasi_env_new`. We want to capture `stdout` and
`stderr` if and only if the `inherit_*` fields are set to
`false`. There was bug here. That's why everything was working
correctly by the way: `bool::default()` is `false`, and we have this
inverted condition here, so everything was working as expected because
of a double error. The only bug was that it wasn't possible to capture
`std*` before.
@Hywan Hywan added bug Something isn't working 🎉 enhancement New feature! 📦 lib-c-api About wasmer-c-api labels Jan 26, 2021
@Hywan Hywan requested a review from MarkMcCaskey January 26, 2021 13:30
@Hywan Hywan self-assigned this Jan 26, 2021
@Hywan Hywan requested a review from jubianchi as a code owner January 26, 2021 13:30
@Hywan
Copy link
Contributor Author

Hywan commented Jan 26, 2021

bors try

bors bot added a commit that referenced this pull request Jan 26, 2021
@bors
Copy link
Contributor

bors bot commented Jan 26, 2021

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.

Thanks! Looks good

Comment on lines 155 to 160

#[no_mangle]
pub extern "C" fn wasi_config_capture_stdin(config: &mut wasi_config_t) {
config.inherit_stdin = false;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it mean to capture stdin here?

I don't think we have any APIs to make use of this, perhaps keep it commented out so we don't export this symbol until we have a use for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep wasi_config_capture_stdin apart for the moment :-).

@Hywan
Copy link
Contributor Author

Hywan commented Jan 26, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Jan 26, 2021

@bors bors bot merged commit ee328e0 into wasmerio:master Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🎉 enhancement New feature! 📦 lib-c-api About wasmer-c-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants