From ee8a0897e154faf9ba8ca43ee8bc27e7bfc7e726 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 8 Nov 2024 06:44:21 -0600 Subject: [PATCH] use go-cmd/cmd --- http.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/http.go b/http.go index 5961022..9bc5b51 100644 --- a/http.go +++ b/http.go @@ -12,8 +12,8 @@ import ( "go.wit.com/lib/gui/shell" pb "go.wit.com/lib/protobuf/virtbuf" - "go.wit.com/log" "go.wit.com/lib/virtigolib" + "go.wit.com/log" ) // remove '?' part and trailing '/' @@ -173,15 +173,15 @@ func okHandler(w http.ResponseWriter, r *http.Request) { log.Warn("cmd :", cmd) fmt.Fprintln(w, "Handling start droplet", cmd) - err, ok, output := shell.RunCmd("/home/", cmd) - shell.Run(cmd) - if ok { + r := shell.PathRun("/home/", cmd) + output := strings.Join(r.Stdout, "\n") + if r.Error == nil { fmt.Fprintln(w, "START OK", me.Hostname) fmt.Fprintln(w, output) } else { fmt.Fprintln(w, "START FAILED", me.Hostname) - fmt.Fprintln(w, "error =", err) - fmt.Fprintln(w, "output =", output) + fmt.Fprintln(w, "error =", r.Error) + fmt.Fprintln(w, "output =", r.Stdout) } return } @@ -231,10 +231,15 @@ func virshDumpXML(name string) (string, error) { cmd := []string{"virsh", "dumpxml", "--security-info", name} log.Warn("Running:", cmd) - err, ok, output := shell.RunCmd("/home/", cmd) - shell.Run(cmd) - if !ok { - result := fmt.Sprintln(cmd, "failed:", err) + r := shell.PathRun("/home/", cmd) + output := strings.Join(r.Stdout, "\n") + if r.Error != nil { + result := fmt.Sprintln(cmd, "failed:", r.Error) + log.Warn(result) + return output, errors.New(result) + } + if r.Exit != 0 { + result := fmt.Sprintln(cmd, "failed exit:", r.Exit) log.Warn(result) return output, errors.New(result) }