github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/plugin/rpcplugin/ipc.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package rpcplugin 5 6 import ( 7 "io" 8 "os" 9 ) 10 11 // Returns a new IPC for the parent process and a set of files to pass on to the child. 12 // 13 // The returned files must be closed after the child process is started. 14 func NewIPC() (io.ReadWriteCloser, []*os.File, error) { 15 parentReader, childWriter, err := os.Pipe() 16 if err != nil { 17 return nil, nil, err 18 } 19 childReader, parentWriter, err := os.Pipe() 20 if err != nil { 21 parentReader.Close() 22 childWriter.Close() 23 return nil, nil, err 24 } 25 return NewReadWriteCloser(parentReader, parentWriter), []*os.File{childReader, childWriter}, nil 26 } 27 28 // Returns the IPC instance inherited by the process from its parent. 29 func InheritedIPC(fd0, fd1 uintptr) (io.ReadWriteCloser, error) { 30 return NewReadWriteCloser(os.NewFile(fd0, ""), os.NewFile(fd1, "")), nil 31 }