golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/telemetry v0.0.0-20240515213752-9ff3ad9b3e68 h1:UpbHwFpoVYf6i5cMzwsNuPGNsZzfJXFr8R4uUv2HVgk=
-golang.org/x/telemetry v0.0.0-20240515213752-9ff3ad9b3e68/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
+golang.org/x/telemetry v0.0.0-20240520205152-bf80d5667fb9 h1:YjhQ60ZAs9YrTY7Fz05TnZ8jS7kN+w50q4dihOdsqGM=
+golang.org/x/telemetry v0.0.0-20240520205152-bf80d5667fb9/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
}
// Crash monitoring and uploading both require a sidecar process.
- if (config.ReportCrashes && crashmonitor.Supported()) || (config.Upload && mode != "off") {
+ var (
+ reportCrashes = config.ReportCrashes && crashmonitor.Supported()
+ upload = config.Upload && mode != "off"
+ )
+ if reportCrashes || upload {
switch v := os.Getenv(telemetryChildVar); v {
case "":
// The subprocess started by parent has X_TELEMETRY_CHILD=1.
- parent(config, result)
+ parent(reportCrashes, result)
case "1":
// golang/go#67211: be sure to set telemetryChildVar before running the
// child, because the child itself invokes the go command to download the
// delegated go commands would fork themselves recursively. Short-circuit
// this recursion.
os.Setenv(telemetryChildVar, "2")
- child(config)
+ child(reportCrashes, upload, config.UploadStartTime, config.UploadURL)
os.Exit(0)
case "2":
// Do nothing: see note above.
// further forking should occur.
const telemetryChildVar = "X_TELEMETRY_CHILD"
-func parent(config Config, result *StartResult) {
+func parent(reportCrashes bool, result *StartResult) {
// This process is the application (parent).
// Fork+exec the telemetry child.
exe, err := os.Executable()
// to gather the output of the parent.
//
// By default, we discard the child process's stderr,
- // but in line with the uploader, log to a file in local/debug
+ // but in line with the uploader, log to a file in debug
// only if that directory was created by the user.
- localDebug := filepath.Join(telemetry.Default.LocalDir(), "debug")
- fd, err := os.Stat(localDebug)
+ fd, err := os.Stat(telemetry.Default.DebugDir())
if err != nil {
if !os.IsNotExist(err) {
log.Fatalf("failed to stat debug directory: %v", err)
} else if fd.IsDir() {
// local/debug exists and is a directory. Set stderr to a log file path
// in local/debug.
- childLogPath := filepath.Join(localDebug, "sidecar.log")
+ childLogPath := filepath.Join(telemetry.Default.DebugDir(), "sidecar.log")
childLog, err := os.OpenFile(childLogPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
log.Fatalf("opening sidecar log file for child: %v", err)
cmd.Stderr = childLog
}
- if config.ReportCrashes {
+ if reportCrashes {
pipe, err := cmd.StdinPipe()
if err != nil {
log.Fatalf("StdinPipe: %v", err)
}()
}
-func child(config Config) {
+func child(reportCrashes, upload bool, uploadStartTime time.Time, uploadURL string) {
log.SetPrefix(fmt.Sprintf("telemetry-sidecar (pid %v): ", os.Getpid()))
// Start crashmonitoring and uploading depending on what's requested
// upload to finish before exiting
var g errgroup.Group
- if config.Upload {
+ if reportCrashes {
g.Go(func() error {
- uploaderChild(config.UploadStartTime, config.UploadURL)
+ crashmonitor.Child()
return nil
})
}
- if config.ReportCrashes {
+ if upload {
g.Go(func() error {
- crashmonitor.Child()
+ uploaderChild(uploadStartTime, uploadURL)
return nil
})
}