mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Make improvements
- Add GetCpuCount() API to redbean - Add unix.gmtime() API to redbean - Add unix.readlink() API to redbean - Add unix.localtime() API to redbean - Perfect the new redbean UNIX module APIs - Integrate with Linux clock_gettime() vDSO - Run Lua garbage collector when malloc() fails - Fix another regression quirk with linenoise repl - Fix GetProgramExecutableName() for systemwide installs - Fix a build flake with test/libc/mem/test.mk SRCS list
This commit is contained in:
parent
860ea18a87
commit
d57b81aac7
51 changed files with 3096 additions and 1395 deletions
|
@ -9,55 +9,48 @@ function main()
|
|||
end
|
||||
syscall = 'commandv'
|
||||
ls = assert(unix.commandv(cmd))
|
||||
if ls then
|
||||
syscall = 'pipe'
|
||||
reader, writer, errno = unix.pipe()
|
||||
if reader then
|
||||
-- oldint = assert(unix.sigaction(unix.SIGINT, unix.SIG_IGN))
|
||||
-- oldquit = assert(unix.sigaction(unix.SIGQUIT, unix.SIG_IGN))
|
||||
-- oldmask = assert(unix.sigprocmask(unix.SIG_BLOCK, (1 << (unix.SIGCHLD - 1))))
|
||||
syscall = 'fork'
|
||||
child, errno = unix.fork()
|
||||
if child then
|
||||
if child == 0 then
|
||||
unix.close(1)
|
||||
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)
|
||||
syscall = 'pipe'
|
||||
reader, writer = assert(unix.pipe(unix.O_CLOEXEC))
|
||||
oldint = assert(unix.sigaction(unix.SIGINT, unix.SIG_IGN))
|
||||
oldquit = assert(unix.sigaction(unix.SIGQUIT, unix.SIG_IGN))
|
||||
oldmask = assert(unix.sigprocmask(unix.SIG_BLOCK, unix.Sigset(unix.SIGCHLD)))
|
||||
syscall = 'fork'
|
||||
child = assert(unix.fork())
|
||||
if child == 0 then
|
||||
unix.close(0)
|
||||
unix.open("/dev/null", unix.O_RDONLY)
|
||||
unix.close(1)
|
||||
unix.dup(writer)
|
||||
unix.close(2)
|
||||
unix.open("/dev/null", unix.O_RDONLY)
|
||||
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
|
||||
unix.close(writer)
|
||||
SetStatus(200)
|
||||
SetHeader('Content-Type', 'text/plain')
|
||||
while true do
|
||||
data, err = unix.read(reader)
|
||||
if data then
|
||||
if data ~= '' then
|
||||
Write(data)
|
||||
else
|
||||
unix.close(writer)
|
||||
SetStatus(200)
|
||||
SetHeader('Content-Type', 'text/plain')
|
||||
while true do
|
||||
data, errno = unix.read(reader)
|
||||
if data then
|
||||
if data ~= '' then
|
||||
Write(data)
|
||||
else
|
||||
break
|
||||
end
|
||||
elseif errno ~= unix.EINTR then
|
||||
Log(kLogWarn, '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
|
||||
break
|
||||
end
|
||||
elseif err:errno() ~= unix.EINTR then
|
||||
Log(kLogWarn, 'read() failed: %s' % {tostring(err)})
|
||||
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
|
||||
SetStatus(200)
|
||||
SetHeader('Content-Type', 'text/plain')
|
||||
Write('error %s calling %s()' % {unix.strerrno(errno), syscall})
|
||||
end
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue