Skip to content

Commit

Permalink
Name results and rename vars for gocritic
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Jan 7, 2024
1 parent ba0fa11 commit 5173ce3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/hostagent/sudo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
}

0 comments on commit 5173ce3

Please sign in to comment.