diff --git a/check/check.go b/check/check.go index c912d98d04305658b7cead2bc95b5015e93faa0c..0e16a42dc0b91e0afbfbda287607b1c76ea48018 100644 --- a/check/check.go +++ b/check/check.go @@ -63,7 +63,7 @@ type Check struct { // Run executes the audit commands specified in a check and outputs // the results. func (c *Check) Run() { - var out, serr bytes.Buffer + var out bytes.Buffer // Check if command exists or exit with WARN. for _, cmd := range c.Commands { @@ -88,7 +88,7 @@ func (c *Check) Run() { cs := c.Commands // Initialize command pipeline - cs[0].Stderr = &serr + cs[0].Stderr = os.Stderr cs[n-1].Stdout = &out i := 1 @@ -96,25 +96,30 @@ func (c *Check) Run() { for i < n { cs[i-1].Stdout, err = cs[i].StdinPipe() if err != nil { - fmt.Fprintf(os.Stderr, "%s: %s\n", cs[i].Path, err) - os.Exit(1) + fmt.Fprintf(os.Stderr, "%s: %s\n", cs[i].Args, err) } - cs[i].Stderr = &serr + cs[i].Stderr = os.Stderr i++ } // Start command pipeline i = 0 for i < n { - cs[i].Start() + err := cs[i].Start() + if err != nil { + fmt.Fprintf(os.Stderr, "%s: %s\n", cs[i].Args, err) + } i++ } // Complete command pipeline i = 0 for i < n { - cs[i].Wait() + err := cs[i].Wait() + if err != nil { + fmt.Fprintf(os.Stderr, "%s: %s\n", cs[i].Args, err) + } if i < n-1 { cs[i].Stdout.(io.Closer).Close() diff --git a/cmd/common.go b/cmd/common.go index a2f51a5568f7e7e29988dc3276c5ca70ad873b8e..93a0c7e50a15d81a8d60c75d670fe84406aa2b81 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -238,7 +238,11 @@ func verifyBin(binPath []string) []string { // Run ps command cmd := exec.Command("ps", "-C", binList, "-o", "cmd", "--no-headers") - out, _ := cmd.Output() + cmd.Stderr = os.Stderr + out, err := cmd.Output() + if err != nil { + fmt.Fprintf(os.Stderr, "%s: %s\n", cmd.Args, err) + } // Actual verification for _, b := range binPath { @@ -266,7 +270,11 @@ func verifyKubeVersion(binPath []string) []string { // Check version cmd := exec.Command(b, "--version") - out, _ := cmd.Output() + cmd.Stderr = os.Stderr + out, err := cmd.Output() + if err != nil { + fmt.Fprintf(os.Stderr, "%s: %s\n", cmd.Args, err) + } matched := strings.Contains(string(out), kubeVersion) if !matched {