Skip to content

Commit

Permalink
telemetry: in Start skip uploading in certain cases
Browse files Browse the repository at this point in the history
It's possible for telemetry.LocalDir to not be set, which, depending
on the platform, could happen if there's no home or AppData
directory. Handle that case by skipping uploading so we don't end up
writing the upload.token file to the user's current directory. (There
would be no counters to upload anyway if there's no local directory).

Also, if telemetry.Mode() is "off" or "local" we don't do uploads, so
unless telemetry.Mode() is "on" don't attempt to do an upload.

Fixes golang/go#66111, golang/go#66099

Change-Id: I6b30835a1d3a147b2f94d97f13a2b793217b2639
Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/569217
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
  • Loading branch information
Pinkle-pash committed Mar 6, 2024
1 parent 626e10d commit 4f81198
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion start.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@ func Start(config Config) {
telemetry.LocalDir = filepath.Join(config.TelemetryDir, "local")
telemetry.UploadDir = filepath.Join(config.TelemetryDir, "upload")
}
mode, _ := telemetry.Mode()
if mode == "off" {
// Telemetry is turned off. Crash reporting doesn't work without telemetry
// at least set to "local", and the uploader isn't started in uploaderChild if
// mode is "off"
return
}

counter.Open()

// Crash monitoring and uploading both require a sidecar process.
if (config.ReportCrashes && crashmonitor.Supported()) || config.Upload {
if (config.ReportCrashes && crashmonitor.Supported()) || (config.Upload && mode != "off") {
if os.Getenv(telemetryChildVar) != "" {
child(config)
os.Exit(0)
Expand All @@ -101,6 +109,7 @@ func parent(config Config) {
cmd := exec.Command(exe, "** telemetry **") // this unused arg is just for ps(1)
daemonize(cmd)
cmd.Env = append(os.Environ(), telemetryChildVar+"=1")
cmd.Dir = telemetry.LocalDir

// The child process must write to a log file, not
// the stderr file it inherited from the parent, as
Expand Down Expand Up @@ -169,6 +178,16 @@ func child(config Config) {
}

func uploaderChild() {
if mode, _ := telemetry.Mode(); mode == "off" {
// There's no work to be done if telemetry is turned off.
return
}
if telemetry.LocalDir == "" {
// The telemetry dir wasn't initialized properly, probably because
// os.UserConfigDir did not complete successfully. In that case
// there are no counters to upload, so we should just do nothing.
return
}
tokenfilepath := filepath.Join(telemetry.LocalDir, "upload.token")
ok, err := acquireUploadToken(tokenfilepath)
if err != nil {
Expand Down

0 comments on commit 4f81198

Please sign in to comment.