{"record":{"id":"e1fcc8ea75b5d522","repo":"containerd/containerd","slug":"set-binary-lib-directory-in-path-s-w","errorCode":null,"errorMessage":"set binary lib directory in path %s: %w","messagePattern":"set binary lib directory in path (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/services/opt/service.go","lineNumber":58,"sourceCode":"\t\t\tPath: defaultPath,\n\t\t},\n\t\tInitFn: func(ic *plugin.InitContext) (any, error) {\n\t\t\tpath := ic.Config.(*Config).Path\n\t\t\tic.Meta.Exports[\"path\"] = path\n\t\t\tbin := filepath.Join(path, \"bin\")\n\t\t\tif err := os.MkdirAll(bin, 0711); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif err := os.Setenv(\"PATH\", fmt.Sprintf(\"%s%c%s\", bin, os.PathListSeparator, os.Getenv(\"PATH\"))); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"set binary image directory in path %s: %w\", bin, err)\n\t\t\t}\n\n\t\t\tlib := filepath.Join(path, \"lib\")\n\t\t\tif err := os.MkdirAll(lib, 0711); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif err := os.Setenv(\"LD_LIBRARY_PATH\", fmt.Sprintf(\"%s%c%s\", lib, os.PathListSeparator, os.Getenv(\"LD_LIBRARY_PATH\"))); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"set binary lib directory in path %s: %w\", lib, err)\n\t\t\t}\n\t\t\treturn &manager{}, nil\n\t\t},\n\t})\n}\n\ntype manager struct {\n}\n","sourceCodeStart":40,"sourceCodeEnd":67,"githubUrl":"https://github.com/containerd/containerd/blob/4246446a2bf7d03837b0244118d858799393bd80/plugins/services/opt/service.go#L40-L67","documentation":"Same initialization flow as 1836 but for LD_LIBRARY_PATH: after creating <path>/lib, prepending it to LD_LIBRARY_PATH via os.Setenv failed and the os error is wrapped. The opt plugin init aborts, so binary image libs are not available.","triggerScenarios":"os.Setenv(\"LD_LIBRARY_PATH\", ...) errors during opt plugin init (restricted environment or invalid env state).","commonSituations":"Embedded containerd with locked environment; LD_LIBRARY_PATH already huge (OS env size limit); hardened runtimes that forbid setenv for select variables.","solutions":["Check the wrapped os error and fix the underlying Setenv failure.","Run containerd with a standard environment allowing LD_LIBRARY_PATH modification.","If embedding, do not strip or freeze the env before plugin initialization.","Restart containerd after correcting the environment."],"exampleFix":"// before\n// LD_LIBRARY_PATH stripped for hardening\nenv = stripSensitiveVars(os.Environ())\n// after\n// preserve LD_LIBRARY_PATH so opt plugin init can prepend its lib dir\nenv = append(os.Environ(), \"LD_LIBRARY_PATH=\"+libPath)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"set binary lib directory\") {\n    log.Fatalf(\"opt plugin env init failed: %v\", err)\n}","preventionTips":["Allow LD_LIBRARY_PATH modification in the containerd process environment","Avoid stripping env vars when embedding containerd","Monitor env size limits for LD_LIBRARY_PATH"],"tags":["containerd","plugin","environment","ld-library-path","opt"],"backgroundTag":"setenv-failed","analyzedSha":"4246446a2bf7d03837b0244118d858799393bd80","analyzedAt":"2026-09-02T00:14:43.053Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}