/
stellar_core_runner_posix.go
41 lines (33 loc) · 1.02 KB
/
stellar_core_runner_posix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//go:build !windows
// +build !windows
package ledgerbackend
import (
"os"
"github.com/pkg/errors"
)
// Posix-specific methods for the HcnetCoreRunner type.
func (c *hcnetCoreRunner) getPipeName() string {
// The exec.Cmd.ExtraFiles field carries *io.File values that are assigned
// to child process fds counting from 3, and we'll be passing exactly one
// fd: the write end of the anonymous pipe below.
return "fd:3"
}
func (c *hcnetCoreRunner) start(cmd cmdI) (pipe, error) {
// First make an anonymous pipe.
// Note io.File objects close-on-finalization.
readFile, writeFile, err := os.Pipe()
if err != nil {
return pipe{}, errors.Wrap(err, "error making a pipe")
}
p := pipe{Reader: readFile, File: writeFile}
// Add the write-end to the set of inherited file handles. This is defined
// to be fd 3 on posix platforms.
cmd.setExtraFiles([]*os.File{writeFile})
err = cmd.Start()
if err != nil {
writeFile.Close()
readFile.Close()
return pipe{}, errors.Wrap(err, "error starting hcnet-core")
}
return p, nil
}