...
1
2
3 package runhcs
4
5 import (
6 "bytes"
7 "errors"
8 "fmt"
9 "io"
10 "os"
11 "syscall"
12 "time"
13
14 "github.com/Microsoft/go-winio/pkg/guid"
15 )
16
17
18
19 type ContainerState struct {
20
21 Version string `json:"ociVersion"`
22
23 ID string `json:"id"`
24
25 InitProcessPid int `json:"pid"`
26
27 Status string `json:"status"`
28
29 Bundle string `json:"bundle"`
30
31 Rootfs string `json:"rootfs"`
32
33 Created time.Time `json:"created"`
34
35 Annotations map[string]string `json:"annotations,omitempty"`
36
37 Owner string `json:"owner"`
38 }
39
40
41
42
43 func GetErrorFromPipe(pipe io.Reader, p *os.Process) error {
44 serr, err := io.ReadAll(pipe)
45 if err != nil {
46 return err
47 }
48
49 if bytes.Equal(serr, ShimSuccess) {
50 return nil
51 }
52
53 extra := ""
54 if p != nil {
55 _ = p.Kill()
56 state, err := p.Wait()
57 if err != nil {
58 panic(err)
59 }
60 extra = fmt.Sprintf(", exit code %d", state.Sys().(syscall.WaitStatus).ExitCode)
61 }
62 if len(serr) == 0 {
63 return fmt.Errorf("unknown shim failure%s", extra)
64 }
65
66 return errors.New(string(serr))
67 }
68
69
70 func VMPipePath(hostUniqueID guid.GUID) string {
71 return SafePipePath("runhcs-vm-" + hostUniqueID.String())
72 }
73
View as plain text