From 5173ce3ca522c5663a2a873f2eed08d89be91782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 7 Jan 2024 22:32:24 +0100 Subject: [PATCH] Name results and rename vars for gocritic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Anders F Björklund --- pkg/hostagent/sudo.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/hostagent/sudo.go b/pkg/hostagent/sudo.go index 30e86ef271f1..cae95c0c7e64 100644 --- a/pkg/hostagent/sudo.go +++ b/pkg/hostagent/sudo.go @@ -16,7 +16,7 @@ import ( // Returns stdout and stderr. // // scriptName is used only for readability of error strings. -func sudoExecuteScript(host string, port int, c *ssh.SSHConfig, script, scriptName string) (string, string, error) { +func sudoExecuteScript(host string, port int, c *ssh.SSHConfig, script, scriptName string) (stdout, stderr string, err error) { if c == nil { return "", "", errors.New("got nil SSHConfig") } @@ -32,12 +32,12 @@ func sudoExecuteScript(host string, port int, c *ssh.SSHConfig, script, scriptNa sshArgs = append(sshArgs, host, "--", "sudo", interpreter) sshCmd := exec.Command(sshBinary, sshArgs...) sshCmd.Stdin = strings.NewReader(script) - var stderr bytes.Buffer - sshCmd.Stderr = &stderr + var buf bytes.Buffer + sshCmd.Stderr = &buf logrus.Debugf("executing ssh for script %q: %s %v", scriptName, sshCmd.Path, sshCmd.Args) out, err := sshCmd.Output() if err != nil { - return string(out), stderr.String(), fmt.Errorf("failed to execute script %q: stdout=%q, stderr=%q: %w", scriptName, string(out), stderr.String(), err) + return string(out), buf.String(), fmt.Errorf("failed to execute script %q: stdout=%q, stderr=%q: %w", scriptName, string(out), buf.String(), err) } - return string(out), stderr.String(), nil + return string(out), buf.String(), nil }