syscall (linux): waitid, pipe2
This commit is contained in:
@@ -21,7 +21,7 @@ const _P_PID = 1
|
||||
// int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
|
||||
//
|
||||
//go:linkname waitid C.waitid
|
||||
func waitid(idtype, id uintptr, infop *[16]uint64, options c.Int) c.Int
|
||||
func waitid(idtype, id uintptr, infop *uint64, options c.Int) c.Int
|
||||
|
||||
// blockUntilWaitable attempts to block until a call to p.Wait will
|
||||
// succeed immediately, and reports whether it has done so.
|
||||
@@ -35,7 +35,7 @@ func (p *Process) blockUntilWaitable() (bool, error) {
|
||||
psig := &siginfo[0]
|
||||
var e syscall.Errno
|
||||
for {
|
||||
e = syscall.Errno(waitid(_P_PID, uintptr(p.Pid), psig, syscall.WEXITED|syscall.WNOWAIT, 0, 0))
|
||||
e = syscall.Errno(waitid(_P_PID, uintptr(p.Pid), psig, syscall.WEXITED|syscall.WNOWAIT))
|
||||
if e != syscall.EINTR {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -6,12 +6,16 @@
|
||||
|
||||
package syscall
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/goplus/llgo/c/syscall"
|
||||
)
|
||||
|
||||
// forkExecPipe atomically opens a pipe with O_CLOEXEC set on both file
|
||||
// descriptors.
|
||||
func forkExecPipe(p []int) error {
|
||||
return Pipe2(p, O_CLOEXEC)
|
||||
return Pipe2(p, syscall.O_CLOEXEC)
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -11,6 +11,14 @@
|
||||
|
||||
package syscall
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type WaitStatus uint32
|
||||
|
||||
// Wait status is 7 bits at bottom, either 0 (exited),
|
||||
@@ -70,6 +78,35 @@ func (w WaitStatus) TrapCause() int {
|
||||
}
|
||||
*/
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// int pipe2(int pipefd[2], int flags);
|
||||
//
|
||||
//go:linkname pipe2 C.pipe2
|
||||
func pipe2(pipefd *[2]c.Int, flags c.Int) c.Int
|
||||
|
||||
func Pipe(p []int) error {
|
||||
return Pipe2(p, 0)
|
||||
}
|
||||
|
||||
func Pipe2(p []int, flags int) error {
|
||||
if len(p) != 2 {
|
||||
return EINVAL
|
||||
}
|
||||
var pp [2]c.Int
|
||||
ret := pipe2(&pp, c.Int(flags))
|
||||
if ret == 0 {
|
||||
p[0] = int(pp[0])
|
||||
p[1] = int(pp[1])
|
||||
return nil
|
||||
}
|
||||
return Errno(ret)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
|
||||
panic("todo: syscall.Faccessat")
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user