Fix disableRcKey bug when key do not exist

This commit is contained in:
yo 2022-06-19 19:14:58 +02:00
parent 0f4f76a9a2
commit 42e1085ad4

View File

@ -217,7 +217,6 @@ func executeCommandInJail(jail *Jail, cmdline string) (string, error) {
return string(out), err return string(out), err
} }
/******************************************************************************** /********************************************************************************
* Execute a script, or shell command. Need to double escape special characters * Execute a script, or shell command. Need to double escape special characters
* Ex.: executeScript("echo '\\\\_o\\< \\~ COINCOIN' > /tmp/coincoin.txt") * Ex.: executeScript("echo '\\\\_o\\< \\~ COINCOIN' > /tmp/coincoin.txt")
@ -365,8 +364,19 @@ func enableRcKeyValue(rcconfpath string, key string, value string) error {
} }
func disableRcKey(rcconfpath string, key string) error { func disableRcKey(rcconfpath string, key string) error {
cmd := fmt.Sprintf("/usr/sbin/sysrc -f %s -x %s", rcconfpath, key) // First check if key exist
_, err := executeCommand(cmd) cmd := fmt.Sprintf("/usr/sbin/sysrc -f %s %s", rcconfpath, key)
out, err := executeCommand(cmd)
if err != nil {
if strings.HasPrefix(out, "sysrc: unknown variable") {
return nil
} else {
return err
}
}
cmd = fmt.Sprintf("/usr/sbin/sysrc -f %s -x %s", rcconfpath, key)
_, err = executeCommand(cmd)
if err != nil { if err != nil {
return err return err
} }