(ctx context.Context, opts *types.Any, onClose func())
| 64 | } |
| 65 | |
| 66 | func (b *binary) Start(ctx context.Context, opts *types.Any, onClose func()) (_ *shim, err error) { |
| 67 | // containerd daemon is the intended caller of client.Command; the deprecation |
| 68 | // targets external callers. |
| 69 | cmd, err := client.Command( //nolint:staticcheck // SA1019 |
| 70 | ctx, |
| 71 | &client.CommandConfig{ |
| 72 | ID: b.bundle.ID, |
| 73 | RuntimePath: b.runtime, |
| 74 | GRPCAddress: b.containerdAddress, |
| 75 | TTRPCAddress: b.containerdTTRPCAddress, |
| 76 | WorkDir: b.bundle.Path, |
| 77 | Opts: opts, |
| 78 | Env: b.env, |
| 79 | LogLevel: log.GetLevel(), |
| 80 | Action: "start", |
| 81 | SocketDir: b.socketDir, |
| 82 | }) |
| 83 | if err != nil { |
| 84 | return nil, err |
| 85 | } |
| 86 | // Windows needs a namespace when openShimLog |
| 87 | ns, _ := namespaces.Namespace(ctx) |
| 88 | shimCtx, cancelShimLog := context.WithCancel(namespaces.WithNamespace(context.Background(), ns)) |
| 89 | defer func() { |
| 90 | if err != nil { |
| 91 | cancelShimLog() |
| 92 | } |
| 93 | }() |
| 94 | f, err := openShimLog(shimCtx, b.bundle, client.AnonDialer) |
| 95 | if err != nil { |
| 96 | return nil, fmt.Errorf("open shim log pipe: %w", err) |
| 97 | } |
| 98 | defer func() { |
| 99 | if err != nil { |
| 100 | f.Close() |
| 101 | } |
| 102 | }() |
| 103 | // open the log pipe and block until the writer is ready |
| 104 | // this helps with synchronization of the shim |
| 105 | // copy the shim's logs to containerd's output |
| 106 | go func() { |
| 107 | defer f.Close() |
| 108 | _, err := io.Copy(os.Stderr, f) |
| 109 | // To prevent flood of error messages, the expected error |
| 110 | // should be reset, like os.ErrClosed or os.ErrNotExist, which |
| 111 | // depends on platform. |
| 112 | err = checkCopyShimLogError(ctx, err) |
| 113 | if err != nil { |
| 114 | log.G(ctx).WithError(err).Error("copy shim log") |
| 115 | } |
| 116 | }() |
| 117 | out, err := cmd.CombinedOutput() |
| 118 | if err != nil { |
| 119 | return nil, fmt.Errorf("%s: %w", out, err) |
| 120 | } |
| 121 | response := bytes.TrimSpace(out) |
| 122 | |
| 123 | onCloseWithShimLog := func() { |
nothing calls this directly
no test coverage detected