{"record":{"id":"fa5907d8e9c9ee7c","repo":"shadow1ng/fscan","slug":"service-dir-create-failed","errorCode":null,"errorMessage":"service_dir_create_failed","messagePattern":"service_dir_create_failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/local/systemdservice.go","lineNumber":163,"sourceCode":"// copyToServicePath 复制文件到服务目录\nfunc (p *SystemdServicePlugin) copyToServicePath(targetFile string) (string, error) {\n\t// 选择服务目录\n\tserviceDirs := []string{\n\t\t\"/usr/local/bin\",\n\t\t\"/opt/local\",\n\t\t\"/usr/bin\",\n\t}\n\n\tvar targetDir string\n\tfor _, dir := range serviceDirs {\n\t\tif err := os.MkdirAll(dir, 0755); err == nil {\n\t\t\ttargetDir = dir\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif targetDir == \"\" {\n\t\treturn \"\", fmt.Errorf(\"%s\", i18n.GetText(\"service_dir_create_failed\"))\n\t}\n\n\t// 生成服务可执行文件名\n\tbasename := filepath.Base(targetFile)\n\tserviceName := strings.TrimSuffix(basename, filepath.Ext(basename))\n\tif serviceName == \"\" {\n\t\tserviceName = \"system-service\"\n\t}\n\n\ttargetPath := filepath.Join(targetDir, serviceName)\n\n\t// 复制文件\n\terr := p.copyFile(targetFile, targetPath)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\t// 设置执行权限","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/local/systemdservice.go#L145-L181","documentation":"copyToServicePath tries to create/locate the systemd service directory (e.g. /etc/systemd/system or the user unit dirs) from a candidate list; none could be created or found, so it returns service_dir_create_failed.","triggerScenarios":"All candidate service directories failed os.MkdirAll (permission denied, read-only filesystem, or the candidates list yielded no usable path).","commonSituations":"Running unprivileged without sudo on a system where unit dirs are not writable; immutable or read-only /etc (containers, live ISOs); SELinux/AppArmor blocking directory creation.","solutions":["Run the process with sufficient privileges (sudo/root) or ensure the user unit dir (~/.config/systemd/user) is writable","Check that at least one candidate directory exists or can be created: ls -ld /etc/systemd/system","Verify the filesystem is writable (not mounted ro); remount rw or use a writable unit directory","Check SELinux/AppArmor denials in audit logs"],"exampleFix":"// run with elevated privileges or ensure user unit dir\nsudo ./tool scan\n// or verify:\nmkdir -p ~/.config/systemd/user","handlingStrategy":"fallback","validationCode":"for _, d := range []string{\"/etc/systemd/system\", \"/usr/lib/systemd/system\", os.ExpandEnv(\"$HOME/.config/systemd/user\")} {\n    if fi, err := os.Stat(d); err == nil && fi.IsDir() { break }\n}\n// verify writability with a test create","typeGuard":null,"tryCatchPattern":"if _, err := copyToServicePath(...); err != nil {\n    log.Printf(\"no writable systemd unit dir: %v — run privileged or use user units\", err)\n}","preventionTips":["Check writability of the unit directory before invoking the plugin","Prefer ~/.config/systemd/user for unprivileged runs","Avoid read-only filesystems (containers) for unit installation"],"tags":["systemd","filesystem","permissions","linux"],"backgroundTag":"permission-denied","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}