-
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
fix(wasi) Fix the logic behind inherited/captured stdin
, stdout
and stderr
#2059
Conversation
…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.
bors try |
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.
Thanks! Looks good
lib/c-api/src/wasm_c_api/wasi/mod.rs
Outdated
|
||
#[no_mangle] | ||
pub extern "C" fn wasi_config_capture_stdin(config: &mut wasi_config_t) { | ||
config.inherit_stdin = false; | ||
} | ||
|
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.
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.
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.
Let's keep wasi_config_capture_stdin
apart for the moment :-).
bors r+ |
Description
This patch is both a fix and a feature!
First, let's no longer derive from
Default
forwasi_config_t
. Bydefault, we want to inherit
stdin
,stdout
andstderr
. Thedefault for
bool
isfalse
; we wanttrue
here.Second, let's update
wasi_config_new
to correctly setinherit_*
fields to
true
.Third, lets' create
wasi_config_capture_*
functions. By default,std*
are inherited, so we need functions to capture them. That's thenew 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 itwould duplicate the API somehow.
Fourth, let's fix
wasi_env_new
. We want to capturestdout
andstderr
if and only if theinherit_*
fields are set tofalse
. There was bug here. That's why everything was workingcorrectly by the way:
bool::default()
isfalse
, and we have thisinverted 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