moved utilities into cmd/utils.go, started working on stop command
This commit is contained in:
53
cmd/utils.go
Normal file
53
cmd/utils.go
Normal file
@ -0,0 +1,53 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
Reference in New Issue
Block a user