From d8c78cfd343cbfd9680b96e38e18bbcfc909445d Mon Sep 17 00:00:00 2001 From: yo Date: Sat, 18 Dec 2021 22:23:55 +0100 Subject: [PATCH] Check if there are rctl rules before calling removeRctlRules() --- cmd/stop.go | 62 ++++++++--------------------------------------------- 1 file changed, 9 insertions(+), 53 deletions(-) diff --git a/cmd/stop.go b/cmd/stop.go index 642778a..d8c0f9a 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -34,53 +34,6 @@ func removeRctlRules(jail string, rules []string) error { return nil } -/* Moved into cmd/utils.go -func executeCommand(cmdline string) (string, error) { - var cmd []string - var out []byte - var err error - - if gUseSudo { - cmd = append(cmd, "sudo") - } - cs := strings.Split(cmdline, " ") - - cmd = append(cmd, cs...) - - if len (cmd) > 1 { - out, err = exec.Command(cmd[0], cmd[1:]...).Output() - } else { - out, err = exec.Command(cmd[0]).Output() - } - - return string(out), err -} - - -func executeCommandInJail(jail *Jail, cmdline string) (string, error) { - var cmd []string - - if gUseSudo { - cmd = append(cmd, "sudo") - } - - cmd = append(cmd, "setfib") - if len(jail.Config.Exec_fib) > 0 { - cmd = append(cmd, jail.Config.Exec_fib) - } else { - cmd = append(cmd, "0") - } - - cmd = append(cmd, "jexec", jail.InternalName) - - cs := strings.Split(cmdline, " ") - cmd = append(cmd, cs...) - - out, err := exec.Command(cmd[0], cmd[1:]...).Output() - - return string(out), err -} -*/ // TODO func umountJailedZFS(jail *Jail) error { @@ -128,12 +81,15 @@ func stopJail(args []string) { continue } - fmt.Printf(" > Remove RCTL rules: ") - err := removeRctlRules(cj.InternalName, []string{""}) - if err != nil { - fmt.Printf("ERROR: %s\n", err.Error()) - } else { - fmt.Printf("OK\n") + out, err := executeCommand(fmt.Sprintf("rctl jail:%s", cj.InternalName)) + if err == nil && len(out) > 0 { + fmt.Printf(" > Remove RCTL rules: ") + err := removeRctlRules(cj.InternalName, []string{""}) + if err != nil { + fmt.Printf("ERROR: %s\n", err.Error()) + } else { + fmt.Printf("OK\n") + } } if len (cj.Config.Exec_prestop) > 0 {