Skip to content

Commit ae16cf7

Browse files
committed
syscall: Accept O_NONBLOCK flag in pipe2
pipe2 only accepted O_CLOEXEC, rejecting O_NONBLOCK with ENOTSUP. Accept O_NONBLOCK and set it on the created pipe streams. This is needed by GLib's GWakeup which uses pipe2(fds, O_CLOEXEC | O_NONBLOCK).
1 parent 7840305 commit ae16cf7

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/lib/libsyscall.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,18 @@ var SyscallsLibrary = {
199199
if (fdPtr == 0) {
200200
throw new FS.ErrnoError({{{ cDefs.EFAULT }}});
201201
}
202-
if (flags && flags != {{{ cDefs.O_CLOEXEC }}}) {
202+
var validFlags = {{{ cDefs.O_CLOEXEC }}} | {{{ cDefs.O_NONBLOCK }}};
203+
if (flags & ~validFlags) {
203204
throw new FS.ErrnoError({{{ cDefs.ENOTSUP }}});
204205
}
205206
206207
var res = PIPEFS.createPipe();
207208
209+
if (flags & {{{ cDefs.O_NONBLOCK }}}) {
210+
FS.getStream(res.readable_fd).flags |= {{{ cDefs.O_NONBLOCK }}};
211+
FS.getStream(res.writable_fd).flags |= {{{ cDefs.O_NONBLOCK }}};
212+
}
213+
208214
{{{ makeSetValue('fdPtr', 0, 'res.readable_fd', 'i32') }}};
209215
{{{ makeSetValue('fdPtr', 4, 'res.writable_fd', 'i32') }}};
210216

0 commit comments

Comments
 (0)