MCPcopy Create free account
hub / github.com/containerd/nerdctl / generateExecProcessSpec

Function generateExecProcessSpec

pkg/cmd/container/exec.go:151–202  ·  view source on GitHub ↗
(ctx context.Context, client *containerd.Client, container containerd.Container, args []string, options types.ContainerExecOptions)

Source from the content-addressed store, hash-verified

149}
150
151func generateExecProcessSpec(ctx context.Context, client *containerd.Client, container containerd.Container, args []string, options types.ContainerExecOptions) (*specs.Process, error) {
152 spec, err := container.Spec(ctx)
153 if err != nil {
154 return nil, err
155 }
156 userOpts, err := generateUserOpts(options.User)
157 if err != nil {
158 return nil, err
159 }
160 if userOpts != nil {
161 c, err := container.Info(ctx)
162 if err != nil {
163 return nil, err
164 }
165 for _, opt := range userOpts {
166 if err := opt(ctx, client, &c, spec); err != nil {
167 return nil, err
168 }
169 }
170 }
171
172 pspec := spec.Process
173 pspec.Terminal = options.TTY
174 if pspec.Terminal {
175 con, err := consoleutil.Current()
176 if err != nil {
177 return nil, err
178 }
179 if size, err := con.Size(); err == nil {
180 pspec.ConsoleSize = &specs.Box{Height: uint(size.Height), Width: uint(size.Width)}
181 }
182 }
183 pspec.Args = args[1:]
184
185 if options.Workdir != "" {
186 pspec.Cwd = options.Workdir
187 }
188 envs, err := flagutil.MergeEnvFileAndOSEnv(options.EnvFile, options.Env)
189 if err != nil {
190 return nil, err
191 }
192 pspec.Env = flagutil.ReplaceOrAppendEnvValues(pspec.Env, envs)
193
194 if options.Privileged {
195 err = setExecCapabilities(pspec)
196 if err != nil {
197 return nil, err
198 }
199 }
200
201 return pspec, nil
202}

Callers 1

execActionWithContainerFunction · 0.85

Calls 7

CurrentFunction · 0.92
MergeEnvFileAndOSEnvFunction · 0.92
ReplaceOrAppendEnvValuesFunction · 0.92
generateUserOptsFunction · 0.85
InfoMethod · 0.80
SizeMethod · 0.80
setExecCapabilitiesFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…