Add Devfs_ruleset property to reflect generated RS

This commit is contained in:
yo
2022-10-15 16:33:29 +02:00
parent 7809107ea4
commit 07eccffbd1
6 changed files with 37 additions and 26 deletions

View File

@ -14,16 +14,17 @@ package jail
*/
import "C"
import (
"strconv"
"strconv"
// "syscall"
"unsafe"
)
type Jail struct {
Name string
Jid int
Path string
Name string
Jid int
Path string
Devfs_ruleset int
}
@ -33,8 +34,8 @@ func GetJails() ([]Jail, error) {
var jl Jail
var err error
// Make "params" a list of 4 jails parameters
params := make([]C.struct_jailparam, 4)
// Make "params" a list of 5 jails parameters
params := make([]C.struct_jailparam, 5)
// initialize parameter names
csname := C.CString("name")
@ -43,27 +44,31 @@ func GetJails() ([]Jail, error) {
defer C.free(unsafe.Pointer(csjid))
cspath := C.CString("path")
defer C.free(unsafe.Pointer(cspath))
csdevfsrs := C.CString("devfs_ruleset")
defer C.free(unsafe.Pointer(csdevfsrs))
cslastjid := C.CString("lastjid")
defer C.free(unsafe.Pointer(cslastjid))
// initialize params struct with parameter names
C.jailparam_init(&params[0], csname)
C.jailparam_init(&params[1], csjid)
C.jailparam_init(&params[2], cspath)
C.jailparam_init(&params[3], csdevfsrs)
// The key to retrieve jail. lastjid = 0 returns first jail and its jid as jailparam_get return value
C.jailparam_init(&params[3], cslastjid)
C.jailparam_init(&params[4], cslastjid)
lastjailid := 0
cslastjidval := C.CString(strconv.Itoa(lastjailid))
defer C.free(unsafe.Pointer(cslastjidval))
C.jailparam_import(&params[3], cslastjidval)
C.jailparam_import(&params[4], cslastjidval)
// loop on existing jails
for lastjailid >= 0 {
// get parameter values
lastjailid = int(C.jailparam_get(&params[0], 4, 0))
lastjailid = int(C.jailparam_get(&params[0], 5, 0))
if lastjailid > 0 {
nametmp := C.jailparam_export(&params[0])
jl.Name = C.GoString(nametmp)
@ -75,23 +80,28 @@ func GetJails() ([]Jail, error) {
// Memory mgmt : Non gere par Go
C.free(unsafe.Pointer(jidtmp))
pathtmp := C.jailparam_export(&params[2])
pathtmp := C.jailparam_export(&params[2])
jl.Path = C.GoString(pathtmp)
// Memory mgmt : Non gere par Go
C.free(unsafe.Pointer(pathtmp))
drstmp := C.jailparam_export(&params[3])
jl.Devfs_ruleset, _ = strconv.Atoi(C.GoString(drstmp))
// Memory mgmt : Non gere par Go
C.free(unsafe.Pointer(drstmp))
jls = append(jls, jl)
//log.Debug("Got jid " + strconv.Itoa(jl.jid) + " with name " + jl.name)
// Prepare next loop iteration
cslastjidval := C.CString(strconv.Itoa(lastjailid))
defer C.free(unsafe.Pointer(cslastjidval))
C.jailparam_import(&params[3], cslastjidval)
C.jailparam_import(&params[4], cslastjidval)
}
}
// Free 4 items of params list
C.jailparam_free(&params[0], 4)
// Free 5 items of params list
C.jailparam_free(&params[0], 5)
return jls, err
}