diff --git a/libc/intrin/kdos2errno.S b/libc/intrin/kdos2errno.S index 5640a4a12..180d796c6 100644 --- a/libc/intrin/kdos2errno.S +++ b/libc/intrin/kdos2errno.S @@ -97,6 +97,7 @@ kDos2Errno: // .e WSAEALREADY,EALREADY # in consts.sh // .e WSAESTALE,ESTALE # in consts.sh // .e WSAEREMOTE,EREMOTE # in consts.sh +// .e WSAEINTR,EINTR # in consts.sh .e kNtErrorModNotFound,ENOSYS .e kNtErrorBadCommand,EACCES .e kNtErrorBadLength,EACCES diff --git a/tool/net/demo/unix-subprocess.lua b/tool/net/demo/unix-subprocess.lua index 71c9e9576..13e14980a 100644 --- a/tool/net/demo/unix-subprocess.lua +++ b/tool/net/demo/unix-subprocess.lua @@ -8,6 +8,9 @@ function main() syscall = 'pipe' reader, writer, errno = unix.pipe() if reader then + oldint = unix.sigaction(unix.SIGINT, unix.SIG_IGN) + oldquit = unix.sigaction(unix.SIGQUIT, unix.SIG_IGN) + oldmask = unix.sigprocmask(unix.SIG_BLOCK, unix.SIGCHLD) syscall = 'fork' child, errno = unix.fork() if child then @@ -16,6 +19,9 @@ function main() unix.dup(writer) unix.close(writer) unix.close(reader) + unix.sigaction(unix.SIGINT, oldint) + unix.sigaction(unix.SIGQUIT, oldquit) + unix.sigprocmask(unix.SIG_SETMASK, oldmask) unix.execve(ls, {ls, "-Shal"}) unix.exit(127) else @@ -23,15 +29,23 @@ function main() SetStatus(200) SetHeader('Content-Type', 'text/plain') while true do - data = unix.read(reader) - if data ~= "" then - Write(data) - else + data, errno = unix.read(reader) + if data then + if data ~= "" then + Write(data) + else + break + end + elseif errno ~= unix.EINTR then + Log(kLogWarn, string.format('read() failed: %s', unix.strerror(errno))) break end end unix.close(reader) unix.wait(-1) + unix.sigaction(unix.SIGINT, oldint) + unix.sigaction(unix.SIGQUIT, oldquit) + unix.sigprocmask(unix.SIG_SETMASK, oldmask) return end end diff --git a/tool/net/help.txt b/tool/net/help.txt index 72830b9b0..b48076d03 100644 --- a/tool/net/help.txt +++ b/tool/net/help.txt @@ -1639,11 +1639,12 @@ UNIX MODULE `CLOCK_TAI`, `CLOCK_PROF`, `CLOCK_BOOTTIME`, `CLOCK_REALTIME_ALARM`, and `CLOCK_BOOTTIME_ALARM`, - unix.nanosleep(seconds, nanos) → remseconds, remnanos, errno:int + unix.nanosleep(seconds:int[, nanos:int]) + → remseconds:int, remnanos:int, errno:int Sleeps with nanosecond precision. - unix.sync(fd:int) + unix.sync() unix.fsync(fd:int) → rc:int[, errno:int] unix.fdatasync(fd:int) → rc:int[, errno:int] diff --git a/tool/net/lunix.c b/tool/net/lunix.c index 74d9013cc..e20022b9e 100644 --- a/tool/net/lunix.c +++ b/tool/net/lunix.c @@ -643,7 +643,7 @@ static int LuaUnixNanosleep(lua_State *L) { } } -// unix.sync(fd:int) +// unix.sync() static int LuaUnixSync(lua_State *L) { sync(); return 0;