-
Notifications
You must be signed in to change notification settings - Fork 950
/
Copy pathcio.go
46 lines (37 loc) · 959 Bytes
/
cio.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
42
43
44
45
46
package containerio
import (
"io/ioutil"
"os"
"path/filepath"
"github.com/alibaba/pouch/pkg/log"
"github.com/containerd/containerd/cio"
)
// NewFIFOSet prepares fifo files.
func NewFIFOSet(processID string, withStdin bool, withTerminal bool) (*cio.FIFOSet, error) {
root := "/run/containerd/fifo"
if err := os.MkdirAll(root, 0700); err != nil {
return nil, err
}
fifoDir, err := ioutil.TempDir(root, "")
if err != nil {
return nil, err
}
cfg := cio.Config{
Terminal: withTerminal,
Stdout: filepath.Join(fifoDir, processID+"-stdout"),
}
if withStdin {
cfg.Stdin = filepath.Join(fifoDir, processID+"-stdin")
}
if !withTerminal {
cfg.Stderr = filepath.Join(fifoDir, processID+"-stderr")
}
closeFn := func() error {
err := os.RemoveAll(fifoDir)
if err != nil {
log.With(nil).WithError(err).Warnf("failed to remove process(id=%v) fifo dir", processID)
}
return err
}
return cio.NewFIFOSet(cfg, closeFn), nil
}