Skip to content

Commit

Permalink
do not re-use exec.Cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Aug 12, 2024
1 parent 332887e commit 63b606d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/snapshot/synology.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,13 @@ func getSynoHAStats() (map[string]string, error) {
"remote-name", "remote-role", "rnode-status", "remote-status", "remote-ip",
}

output := make(map[string]string) // This is the returned value.
cmd := exec.Command("sudo", synoha, "placeholder") // Reuse *exec.Cmd to save memory.
cmd.Stderr = io.Discard // Do not care about error output.
cmdout := bytes.Buffer{} // Reuse buffer for every command.
cmd.Stdout = &cmdout // Use buffer for command output.
output := make(map[string]string) // This is the returned value.
cmdout := bytes.Buffer{} // Reuse buffer for every command.

for _, arg := range cmds {
cmd.Args[2] = "--" + arg // replace the last argument with the correct value.
cmd := exec.Command("sudo", synoha, "--"+arg)
cmd.Stderr = io.Discard // Do not care about error output.
cmd.Stdout = &cmdout // Use buffer for command output.

if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("synoha failed: %w", err)
Expand Down

0 comments on commit 63b606d

Please sign in to comment.