Set property K for int type + write config to disk
This commit is contained in:
29
cmd/start.go
29
cmd/start.go
@ -9,7 +9,7 @@ import (
|
||||
// "os/exec"
|
||||
// "reflect"
|
||||
"strings"
|
||||
// "strconv"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func SetJailProperties(args []string) {
|
||||
@ -55,6 +55,7 @@ func SetJailProperties(args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : Support types. For now we just update int, other types will crash
|
||||
// WIP. Not working now (need to address the real struct field, not a copy of it)
|
||||
// setJailProperty takes a string as propValue, whatever the real property type is.
|
||||
// It will be converted.
|
||||
@ -88,23 +89,24 @@ func setJailProperty(jail *Jail, propName string, propValue string) error {
|
||||
return errors.New(fmt.Sprintf("Property %s have an unsupported type in setJailProperty!\n", propName))
|
||||
}*/
|
||||
|
||||
// panic: reflect: reflect.Value.Set using unaddressable value
|
||||
//val.Set(reflect.ValueOf(propValue).Elem())
|
||||
// ...Because val settability is false :-(
|
||||
fmt.Printf("settability of val %s: %v\n", val.Interface(), val.CanSet())
|
||||
|
||||
// This is OK, using the index to get the real jail object
|
||||
//gJails[i].Config.Allow_mlock = 1
|
||||
|
||||
|
||||
// TODO : integrate this function
|
||||
//setJailConfigUpdated(jail)
|
||||
if val.CanSet() {
|
||||
ival, err := strconv.Atoi(propValue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
val.SetInt(int64(ival))
|
||||
fmt.Printf("%s: %s set to %s\n", jail.Name, propName, propValue)
|
||||
gJails[i].ConfigUpdated = true
|
||||
} else {
|
||||
return errors.New(fmt.Sprintf("Field is not writable : %s", propName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FIXME : Do not work?!
|
||||
// We cant use internalName as the value exist only when jail is running
|
||||
func setJailConfigUpdated(jail *Jail) error {
|
||||
if len(jail.ConfigPath) == 0 {
|
||||
@ -112,7 +114,8 @@ func setJailConfigUpdated(jail *Jail) error {
|
||||
}
|
||||
|
||||
for i, j := range gJails {
|
||||
if jail.ConfigPath == j.ConfigPath {
|
||||
if jail.Name == j.Name {
|
||||
fmt.Printf("Tag %s as configUpdated\n", jail.Name)
|
||||
gJails[i].ConfigUpdated = true
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user