{"record":{"id":"ca8124b6966fca45","repo":"txthinking/brook","slug":"pid-must-be-with-absolute-path","errorCode":null,"errorMessage":"--pid must be with absolute path","messagePattern":"--pid must be with absolute path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/brook/main.go","lineNumber":169,"sourceCode":"\t\t&cli.StringSliceFlag{\n\t\t\tName:  \"blockGeoIP\",\n\t\t\tUsage: \"Block IP by Geo country code, such as US. Works with server/wsserver/wssserver/quicserver\",\n\t\t},\n\t\t&cli.Int64Flag{\n\t\t\tName:  \"blockListUpdateInterval\",\n\t\t\tUsage: \"Update list --blockDomainList,--blockCIDR4List,--blockCIDR6List interval, second. default 0, only read one time on start\",\n\t\t},\n\t\t&cli.StringFlag{\n\t\t\tName:  \"pid\",\n\t\t\tUsage: \"A file path used to store pid. Send SIGUSR1 to me to reset the --serverLog file on unix system\",\n\t\t},\n\t}\n\tapp.Before = func(c *cli.Context) error {\n\t\tbrook.ClientHKDFInfo = []byte(c.String(\"clientHKDFInfo\"))\n\t\tbrook.ServerHKDFInfo = []byte(c.String(\"serverHKDFInfo\"))\n\t\tif c.String(\"pid\") != \"\" {\n\t\t\tif !filepath.IsAbs(c.String(\"pid\")) {\n\t\t\t\treturn errors.New(\"--pid must be with absolute path\")\n\t\t\t}\n\t\t\tif err := os.WriteFile(c.String(\"pid\"), []byte(strconv.Itoa(os.Getpid())), 0744); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t\tif c.String(\"pprof\") != \"\" {\n\t\t\tp, err := pprof.NewPprof(c.String(\"pprof\"))\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tg.Add(&runnergroup.Runner{\n\t\t\t\tStart: func() error {\n\t\t\t\t\treturn p.ListenAndServe()\n\t\t\t\t},\n\t\t\t\tStop: func() error {\n\t\t\t\t\treturn p.Shutdown()\n\t\t\t\t},\n\t\t\t})","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/txthinking/brook/blob/5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8/cli/brook/main.go#L151-L187","documentation":"The brook CLI's app.Before hook validates global flags before running any subcommand. If --pid is provided as a relative path, it refuses to run because the PID file location must be unambiguous regardless of working directory. The error aborts command execution.","triggerScenarios":"Running any brook subcommand with e.g. --pid brook.pid or --pid ./run/brook.pid — anything filepath.IsAbs returns false for.","commonSituations":"Copy-pasting example commands with relative paths; systemd/docker setups where CWD differs from what the operator assumed; scripts that cd around before writing the PID file.","solutions":["Pass an absolute path: --pid /var/run/brook.pid","Prefix the value with $PWD in shell: --pid \"$PWD/brook.pid\"","Fix the service/unit file to use an absolute PIDFile path"],"exampleFix":"// before\nbrook server -l :9999 --pid brook.pid\n// after\nbrook server -l :9999 --pid /var/run/brook.pid","handlingStrategy":"validation","validationCode":"if pidPath != \"\" && !filepath.IsAbs(pidPath) {\n\treturn fmt.Errorf(\"--pid must be absolute, got %q\", pidPath)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass absolute paths for --pid","Use \"$PWD/...\" in shell wrappers","Set absolute paths in systemd (RuntimeDirectory + PIDFile) configs"],"tags":["cli","pidfile","path-validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8","analyzedAt":"2026-09-06T04:35:00.432Z","contentChangedAt":"2026-09-06T04:35:00.432Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}