github.com/dara-project/godist@v0.0.0-20200823115410-e0c80c8f0c78/src/os/pipe_linux.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package os
     6  
     7  import "dara"
     8  import "runtime"
     9  import "syscall"
    10  
    11  // Pipe returns a connected pair of Files; reads from r return bytes written to w.
    12  // It returns the files and an error, if any.
    13  func Pipe() (r *File, w *File, err error) {
    14  	var p [2]int
    15  	// DARA Instrumentation
    16  	if runtime.Is_dara_profiling_on() {
    17  		runtime.Dara_Debug_Print(func() { println("[PIPE]") })
    18  		retInfo1 := dara.GeneralType{Type: dara.FILE}
    19          copy(retInfo1.String[:], r.name)
    20  		retInfo2 := dara.GeneralType{Type: dara.FILE}
    21          copy(retInfo2.String[:], w.name)
    22  		retInfo3 := dara.GeneralType{Type: dara.ERROR, Unsupported: dara.UNSUPPORTEDVAL}
    23  		syscallInfo := dara.GeneralSyscall{dara.DSYS_PIPE2, 0, 3, [10]dara.GeneralType{}, [10]dara.GeneralType{retInfo1, retInfo2, retInfo3}}
    24  		runtime.Report_Syscall_To_Scheduler(dara.DSYS_PIPE2, syscallInfo)
    25  	}
    26  	e := syscall.Pipe2(p[0:], syscall.O_CLOEXEC)
    27  	// pipe2 was added in 2.6.27 and our minimum requirement is 2.6.23, so it
    28  	// might not be implemented.
    29  	if e == syscall.ENOSYS {
    30  		// See ../syscall/exec.go for description of lock.
    31  		syscall.ForkLock.RLock()
    32  		e = syscall.Pipe(p[0:])
    33  		if e != nil {
    34  			syscall.ForkLock.RUnlock()
    35  			return nil, nil, NewSyscallError("pipe", e)
    36  		}
    37  		syscall.CloseOnExec(p[0])
    38  		syscall.CloseOnExec(p[1])
    39  		syscall.ForkLock.RUnlock()
    40  	} else if e != nil {
    41  		return nil, nil, NewSyscallError("pipe2", e)
    42  	}
    43  
    44  	return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil
    45  }
    46  
    47