diff --git a/internal/gobackfill/gte_1_12.go b/internal/gobackfill/gte_1_12.go new file mode 100644 index 000000000..004581d1f --- /dev/null +++ b/internal/gobackfill/gte_1_12.go @@ -0,0 +1,18 @@ +// Copyright 2020 New Relic Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +// Golang code for Go versions greater or equal than 1.12. +// +// +build go1.12 + +package gobackfill + +import "os/exec" + +// ExitCode wrapping to backfill old Golang versions. +// Negative values mean: +// * -1: not exited +// * -2: unknown +func ExitCode(exitError *exec.ExitError) int { + return exitError.ExitCode() +} diff --git a/internal/gobackfill/lt_1_12.go b/internal/gobackfill/lt_1_12.go new file mode 100644 index 000000000..6e9e68fc2 --- /dev/null +++ b/internal/gobackfill/lt_1_12.go @@ -0,0 +1,15 @@ +// Copyright 2020 New Relic Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +// Golang code for Go versions lower than 1.12. +// +// +build !go1.12 + +package gobackfill + +import "os/exec" + +// ExitCode not supported, always value -2, as -1 belong to not finished. +func ExitCode(exitError *exec.ExitError) int { + return -2 +} diff --git a/internal/integrations/v4/executor/executor.go b/internal/integrations/v4/executor/executor.go index 381def23a..a0e4356a5 100644 --- a/internal/integrations/v4/executor/executor.go +++ b/internal/integrations/v4/executor/executor.go @@ -13,6 +13,7 @@ import ( "os/exec" "sync" + "github.com/newrelic/infrastructure-agent/internal/gobackfill" "github.com/newrelic/infrastructure-agent/internal/integrations/v4/constants" "github.com/newrelic/infrastructure-agent/pkg/helpers" "github.com/newrelic/infrastructure-agent/pkg/log" @@ -101,7 +102,7 @@ func (r *Executor) Execute(ctx context.Context, pidChan, exitCodeCh chan<- int) out.Errors <- err if exitCodeCh != nil { if exitError, ok := err.(*exec.ExitError); ok { - exitCodeCh <- exitError.ExitCode() + exitCodeCh <- gobackfill.ExitCode(exitError) } } }