cmd/syncthing: Start CPU usage monitoring not from init (fixes #4183)
Starting stuff from init() is an antipattern, and the innerProcess variable isn't 100% reliable. We should sort out the other uses of it as well in due time. Also removing the hack on innerProcess as I happened to see it and the affected versions are now <1% users. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4185
This commit is contained in:
committed by
Audrius Butkevicius
parent
b49bbe82dd
commit
803da92ca9
@@ -427,34 +427,6 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
// ---BEGIN TEMPORARY HACK---
|
||||
//
|
||||
// Remove once v0.14.21-v0.14.22 are rare enough. Those versions,
|
||||
// essentially:
|
||||
//
|
||||
// 1. os.Setenv("STMONITORED", "yes")
|
||||
// 2. os.Setenv("STNORESTART", "")
|
||||
//
|
||||
// where the intention was for 2 to cancel out 1 instead of setting
|
||||
// STNORESTART to the empty value. We check for exactly this combination
|
||||
// and pretend that neither was set. Looking through os.Environ lets us
|
||||
// distinguish. Luckily, we weren't smart enough to use os.Unsetenv.
|
||||
|
||||
matches := 0
|
||||
for _, str := range os.Environ() {
|
||||
if str == "STNORESTART=" {
|
||||
matches++
|
||||
}
|
||||
if str == "STMONITORED=yes" {
|
||||
matches++
|
||||
}
|
||||
}
|
||||
if matches == 2 {
|
||||
innerProcess = false
|
||||
}
|
||||
|
||||
// ---END TEMPORARY HACK---
|
||||
|
||||
if innerProcess || options.noRestart {
|
||||
syncthingMain(options)
|
||||
} else {
|
||||
@@ -1093,7 +1065,10 @@ func setupGUI(mainService *suture.Supervisor, cfg *config.Wrapper, m *model.Mode
|
||||
l.Warnln("Insecure admin access is enabled.")
|
||||
}
|
||||
|
||||
api := newAPIService(myID, cfg, locations[locHTTPSCertFile], locations[locHTTPSKeyFile], runtimeOptions.assetDir, m, defaultSub, diskSub, discoverer, connectionsService, errors, systemLog)
|
||||
cpu := newCPUService()
|
||||
mainService.Add(cpu)
|
||||
|
||||
api := newAPIService(myID, cfg, locations[locHTTPSCertFile], locations[locHTTPSKeyFile], runtimeOptions.assetDir, m, defaultSub, diskSub, discoverer, connectionsService, errors, systemLog, cpu)
|
||||
cfg.Subscribe(api)
|
||||
mainService.Add(api)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user