MCPcopy Index your code
hub / github.com/google/gvisor / ResolveExecutablePath

Function ResolveExecutablePath

pkg/sentry/fsimpl/user/path.go:39–73  ·  view source on GitHub ↗

ResolveExecutablePath resolves the given executable name given the working dir and environment. Returns *ExecutableResolveError when the executable cannot be resolved.

(ctx context.Context, args *kernel.CreateProcessArgs)

Source from the content-addressed store, hash-verified

37// dir and environment.
38// Returns *ExecutableResolveError when the executable cannot be resolved.
39func ResolveExecutablePath(ctx context.Context, args *kernel.CreateProcessArgs) (string, error) {
40 name := args.Filename
41 if len(name) == 0 {
42 if len(args.Argv) == 0 {
43 return "", fmt.Errorf("no filename or command provided")
44 }
45 name = args.Argv[0]
46 }
47
48 // Absolute paths can be used directly.
49 if path.IsAbs(name) {
50 return name, nil
51 }
52
53 // Paths with '/' in them should be joined to the working directory, or
54 // to the root if working directory is not set.
55 if strings.IndexByte(name, '/') > 0 {
56 wd := args.WorkingDirectory
57 if wd == "" {
58 wd = "/"
59 }
60 if !path.IsAbs(wd) {
61 return "", fmt.Errorf("working directory %q must be absolute", wd)
62 }
63 return path.Join(wd, name), nil
64 }
65
66 // Otherwise, We must lookup the name in the paths.
67 paths := getPath(args.Envv)
68 f, err := resolve(ctx, args.Credentials, args.MountNamespace, paths, name)
69 if err != nil {
70 return "", &ExecutableResolveError{fmt.Errorf("error finding executable %q in PATH %v: %v", name, paths, err)}
71 }
72 return f, nil
73}
74
75// resolve searches for an executable in the given PATH directories.
76// Error handling follows glibc execvpe() (posix/execvpe.c).

Callers 3

StartContainerMethod · 0.92
execAsyncMethod · 0.92
setupContainerVFSFunction · 0.92

Calls 4

getPathFunction · 0.85
resolveFunction · 0.70
ErrorfMethod · 0.65
JoinMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…