Check if there are rctl rules before calling removeRctlRules()

This commit is contained in:
yo 2021-12-18 22:23:55 +01:00
parent b5faac0705
commit d8c78cfd34

View File

@ -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,6 +81,8 @@ func stopJail(args []string) {
continue
}
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 {
@ -135,6 +90,7 @@ func stopJail(args []string) {
} else {
fmt.Printf("OK\n")
}
}
if len (cj.Config.Exec_prestop) > 0 {
fmt.Printf(" > Execute prestop: ")