{"record":{"id":"406bb96a8677c76d","repo":"v2rayA/v2rayA","slug":"tinytun-route-script-s-failed-to-chmod-temp-fi","errorCode":null,"errorMessage":"tinytun route script (%s): failed to chmod temp file: %w","messagePattern":"tinytun route script \\((.+?)\\): failed to chmod temp file: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/kernel/v2ray/tinytun_enabled.go","lineNumber":751,"sourceCode":"\tbinPath := si.bin\n\tif !filepath.IsAbs(binPath) {\n\t\tif resolved, err := exec.LookPath(binPath); err == nil {\n\t\t\tbinPath = resolved\n\t\t}\n\t}\n\n\t// Write script to a temp file with restricted permissions.\n\ttmpFile, err := os.CreateTemp(\"\", \"tinytun_*\"+si.ext)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"tinytun route script (%s): failed to create temp file: %w\", stage, err)\n\t}\n\tdefer os.Remove(tmpFile.Name())\n\n\t// Restrict permissions immediately after creation (before writing content).\n\tif runtime.GOOS != \"windows\" {\n\t\tif err = os.Chmod(tmpFile.Name(), 0600); err != nil {\n\t\t\ttmpFile.Close()\n\t\t\treturn fmt.Errorf(\"tinytun route script (%s): failed to chmod temp file: %w\", stage, err)\n\t\t}\n\t}\n\n\tif _, err = tmpFile.WriteString(script); err != nil {\n\t\ttmpFile.Close()\n\t\treturn fmt.Errorf(\"tinytun route script (%s): failed to write temp file: %w\", stage, err)\n\t}\n\ttmpFile.Close()\n\n\t// Make the file executable on non-Windows systems.\n\tif runtime.GOOS != \"windows\" {\n\t\tif err = os.Chmod(tmpFile.Name(), 0700); err != nil {\n\t\t\treturn fmt.Errorf(\"tinytun route script (%s): failed to chmod temp file executable: %w\", stage, err)\n\t\t}\n\t}\n\n\t// Build command arguments.\n\tvar args []string","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/v2rayA/v2rayA/blob/71e5442fc548c05680ee55eae943e6c0afe9ac51/service/kernel/v2ray/tinytun_enabled.go#L733-L769","documentation":"This wraps os.Chmod failing when restricting the just-created temp script file to 0600 (non-Windows only) before writing content. The library throws it because the script must be private to avoid executing user-writable content from a world-readable/writable temp file.","triggerScenarios":"os.Chmod(tmpFile.Name(), 0600) at tinytun_enabled.go:751 returns an error right after CreateTemp succeeded — rare, but possible with unusual filesystems (e.g. some FUSE/NFS/vfat mounts) or concurrent removal of the temp file.","commonSituations":"Temp dir on a filesystem that does not support chmod (FAT/exFAT USB mounts, certain network mounts); TMPDIR on an overlay with odd ACLs; external cleanup racing the file.","solutions":["Point TMPDIR at a local filesystem that supports permission bits (e.g. /tmp on ext4).","Check the wrapped OS error to confirm the filesystem limitation and relocate the temp dir.","Re-run; transient races with temp-file cleaners usually resolve on retry."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"probe, err := os.CreateTemp(os.TempDir(), \"perm_probe*\")\nif err == nil {\n    if err2 := probe.Chmod(0600); err2 != nil {\n        return fmt.Errorf(\"temp fs does not support chmod: %w\", err2)\n    }\n    probe.Close(); os.Remove(probe.Name())\n}","typeGuard":null,"tryCatchPattern":"if err := runTinyTunScript(stage, script); err != nil {\n    if strings.Contains(err.Error(), \"failed to chmod temp file\") {\n        log.Warnf(\"temp filesystem lacks permission support: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep TMPDIR on a POSIX filesystem with permission-bit support (ext4/xfs/btrfs)","Avoid FAT/exFAT or network mounts for temp storage","Check mount options (fmask/dmask) on removable filesystems","Probe chmod support before relying on temp-file permissions"],"tags":["filesystem","permissions","tinytun"],"backgroundTag":"chmod-failed","analyzedSha":"71e5442fc548c05680ee55eae943e6c0afe9ac51","analyzedAt":"2026-09-05T20:04:37.459Z","contentChangedAt":"2026-09-05T20:04:37.459Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}