Don't expose a -delay paramater

This commit is contained in:
Jakob Borg 2014-03-09 08:35:38 +01:00
parent a88e4db1ee
commit ae94b726a7

View File

@ -34,12 +34,11 @@ var (
) )
var ( var (
showVersion bool showVersion bool
confDir string confDir string
trace string trace string
profiler string profiler string
verbose bool verbose bool
startupDelay int
) )
func main() { func main() {
@ -48,12 +47,12 @@ func main() {
flag.StringVar(&profiler, "debug.profiler", "", "(addr)") flag.StringVar(&profiler, "debug.profiler", "", "(addr)")
flag.BoolVar(&showVersion, "version", false, "Show version") flag.BoolVar(&showVersion, "version", false, "Show version")
flag.BoolVar(&verbose, "v", false, "Be more verbose") flag.BoolVar(&verbose, "v", false, "Be more verbose")
flag.IntVar(&startupDelay, "delay", 0, "Startup delay (s)")
flag.Usage = usageFor(flag.CommandLine, "syncthing [options]") flag.Usage = usageFor(flag.CommandLine, "syncthing [options]")
flag.Parse() flag.Parse()
if startupDelay > 0 { if len(os.Getenv("STRESTART")) > 0 {
time.Sleep(time.Duration(startupDelay) * time.Second) // Give the parent process time to exit and release sockets etc.
time.Sleep(1 * time.Second)
} }
if showVersion { if showVersion {
@ -293,24 +292,17 @@ func main() {
func restart() { func restart() {
infoln("Restarting") infoln("Restarting")
args := os.Args env := os.Environ()
doAppend := true if len(os.Getenv("STRESTART")) == 0 {
for _, arg := range args { env = append(env, "STRESTART=1")
if arg == "-delay" {
doAppend = false
break
}
}
if doAppend {
args = append(args, "-delay", "2")
} }
pgm, err := exec.LookPath(os.Args[0]) pgm, err := exec.LookPath(os.Args[0])
if err != nil { if err != nil {
warnln(err) warnln(err)
return return
} }
proc, err := os.StartProcess(pgm, args, &os.ProcAttr{ proc, err := os.StartProcess(pgm, os.Args, &os.ProcAttr{
Env: os.Environ(), Env: env,
Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}, Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
}) })
if err != nil { if err != nil {