github.com/LanceLRQ/deer-common@v0.0.9-0.20210319081233-e8222ac018a8/sandbox/forkexec/syscall_linux.go (about)

     1  // +build linux,amd64
     2  
     3  package forkexec
     4  
     5  import "syscall"
     6  
     7  // 获取管道数据
     8  func GetPipe() ([]uintptr, error) {
     9  	var pipe = []int{0, 0}
    10  	err := Pipe2(pipe, syscall.O_CLOEXEC)
    11  	if err != nil {
    12  		return nil, err
    13  	}
    14  	return []uintptr{uintptr(pipe[0]), uintptr(pipe[1])}, nil
    15  }
    16  
    17  //sysnb pipe2(p *[2]_C_int, flags int) (err error)
    18  
    19  func Pipe2(p []int, flags int) (err error) {
    20  	if len(p) != 2 {
    21  		return syscall.EINVAL
    22  	}
    23  	var pp [2]_C_int
    24  	err = pipe2(&pp, flags)
    25  	p[0] = int(pp[0])
    26  	p[1] = int(pp[1])
    27  	return
    28  }