{"record":{"id":"cd697c24e8ee78af","repo":"shadow1ng/fscan","slug":"systemdservice-create-none","errorCode":null,"errorMessage":"systemdservice_create_none","messagePattern":"systemdservice_create_none","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/local/systemdservice.go","lineNumber":276,"sourceCode":"Type=oneshot\nUser=root\nExecStart=%s\nStandardOutput=null\nStandardError=null\n`, execPath),\n\t\t},\n\t}\n\n\tvar created []string\n\tfor _, service := range services {\n\t\tservicePath := filepath.Join(systemDir, service.name)\n\t\tif err := os.WriteFile(servicePath, []byte(service.content), 0644); err == nil {\n\t\t\tcreated = append(created, service.name)\n\t\t}\n\t}\n\n\tif len(created) == 0 {\n\t\treturn nil, fmt.Errorf(\"%s\", i18n.GetText(\"systemdservice_create_none\"))\n\t}\n\n\treturn created, nil\n}\n\n// enableAndStartServices 启用并启动服务\nfunc (p *SystemdServicePlugin) enableAndStartServices(serviceFiles []string) error {\n\tvar errors []string\n\n\tfor _, serviceName := range serviceFiles {\n\t\t// 重新加载systemd配置\n\t\t_ = exec.Command(\"systemctl\", \"daemon-reload\").Run()\n\n\t\t// 启用服务\n\t\tif err := exec.Command(\"systemctl\", \"enable\", serviceName).Run(); err != nil {\n\t\t\terrors = append(errors, fmt.Sprintf(\"enable %s: %v\", serviceName, err))\n\t\t}\n","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/local/systemdservice.go#L258-L294","documentation":"Guard in createSystemdServices: none of the candidate systemd unit files could be written to the system directory (every os.WriteFile failed, e.g. missing privileges or read-only filesystem). Since no service was planted, the function reports total failure instead of returning an empty list.","triggerScenarios":"All unit file writes failed — service directory exists but is not writable, wrong path, or disk full.","commonSituations":"Non-root user writing to /etc/systemd/system; typo'd unit directory from a previous failed step; read-only root filesystem in containers.","solutions":["Run with write permission on the unit directory (root or writable ~/.config/systemd/user)","Check disk space and mount status (df -h, mount | grep ro)","Log per-file WriteFile errors during the loop so the actual cause is visible instead of a generic none-created error"],"exampleFix":"// before\nif err := os.WriteFile(servicePath, []byte(service.content), 0644); err == nil {\n    created = append(created, service.name)\n}\n// after\nif err := os.WriteFile(servicePath, []byte(service.content), 0644); err != nil {\n    return nil, fmt.Errorf(\"write %s: %w\", servicePath, err)\n}\ncreated = append(created, service.name)","handlingStrategy":"validation","validationCode":"testPath := filepath.Join(unitDir, \"writetest\")\nif err := os.WriteFile(testPath, []byte(\"x\"), 0644); err != nil {\n    return fmt.Errorf(\"unit dir not writable: %w\", err)\n}\n_ = os.Remove(testPath)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify write access to the unit directory before writing units","Log individual WriteFile errors instead of collapsing to a generic error","Ensure adequate disk space and rw mounts"],"tags":["systemd","file-write","permissions","linux"],"backgroundTag":"file-write-failed","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"}