Skip to content

Commit

Permalink
Handle stdio permission error (#72)
Browse files Browse the repository at this point in the history
This change allows `wasi-go` tests to run on gitpod, see
gitpod-io/gitpod#17551

---------

Signed-off-by: Achille Roussel <[email protected]>
  • Loading branch information
achille-roussel authored Jun 26, 2023
1 parent bfe9c24 commit 341ced8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion imports/builder_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (b *Builder) Instantiate(ctx context.Context, runtime wazero.Runtime) (ctxr
system = wrap(system)
}

for _, stdio := range []struct {
for fd, stdio := range []struct {
fd int
open int
path string
Expand All @@ -109,6 +109,15 @@ func (b *Builder) Instantiate(ctx context.Context, runtime wazero.Runtime) (ctxr
var err error
if stdio.fd < 0 {
stdio.fd, err = syscall.Open(stdio.path, stdio.open, 0)
// Some systems may not allow opening stdio files on /dev, fallback
// duplicating the process file descriptors which comes with the
// limitation that setting the file descriptors to non-blocking will
// also impact the behavior of stdio streams on the host.
//
// See: https://github.com/gitpod-io/gitpod/issues/17551
if errors.Is(err, syscall.EACCES) {
stdio.fd, err = dup(fd)
}
} else {
stdio.fd, err = dup(stdio.fd)
}
Expand Down

0 comments on commit 341ced8

Please sign in to comment.