Add Devfs_ruleset property to reflect generated RS
This commit is contained in:
parent
7809107ea4
commit
07eccffbd1
@ -273,6 +273,7 @@ func listJailsFromDirectory(dir string, dsname string) ([]Jail, error) {
|
||||
j.JID = rj.Jid
|
||||
j.Running = true
|
||||
j.InternalName = rj.Name
|
||||
j.Devfs_ruleset = rj.Devfs_ruleset
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
gVersion = "0.30"
|
||||
gVersion = "0.31"
|
||||
|
||||
// TODO : Get from $jail_zpool/defaults.json
|
||||
MIN_DYN_DEVFS_RULESET = 1000
|
||||
|
@ -1331,8 +1331,9 @@ func StartJail(args []string) {
|
||||
fmt.Printf(" > Start jail: OK\n")
|
||||
fmt.Printf(" > With devfs ruleset %d\n", dynrs)
|
||||
|
||||
// Update running state and JID
|
||||
// Update running state, JID and Devfs_ruleset
|
||||
cj.Running = true
|
||||
cj.Devfs_ruleset = dynrs
|
||||
rjails, err := jail.GetJails()
|
||||
if err != nil {
|
||||
fmt.Printf("Error: Unable to list running jails\n")
|
||||
|
16
cmd/stop.go
16
cmd/stop.go
@ -287,19 +287,12 @@ func StopJail(args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Get currently used ruleset from /var/run/jail.$internal_name.conf
|
||||
ruleset, err := getValueFromRunningConfig(cj.InternalName, "devfs_ruleset")
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR getting current devfs ruleset: %s\n", err.Error())
|
||||
return
|
||||
}
|
||||
rsi, _ := strconv.Atoi(ruleset)
|
||||
fmt.Printf(" > Remove devfs ruleset %d: \n", rsi)
|
||||
err = deleteDevfsRuleset(rsi)
|
||||
fmt.Printf(" > Remove devfs ruleset %d: \n", cj.Devfs_ruleset)
|
||||
err = deleteDevfsRuleset(cj.Devfs_ruleset)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err.Error())
|
||||
} else {
|
||||
fmt.Printf(" > Remove devfsruleset %d: OK\n", rsi)
|
||||
fmt.Printf(" > Remove devfsruleset %d: OK\n", cj.Devfs_ruleset)
|
||||
}
|
||||
|
||||
fmt.Printf(" > Stop jail %s:\n", cj.Name)
|
||||
@ -401,6 +394,9 @@ func StopJail(args []string) {
|
||||
if err = setStructFieldValue(&gJails[i], "InternalName", ""); err != nil {
|
||||
fmt.Printf("ERROR: clearing InternalName property: %s\n", err.Error())
|
||||
}
|
||||
if err = setStructFieldValue(&gJails[i], "Devfs_ruleset", "0"); err != nil {
|
||||
fmt.Printf("ERROR: setting Devfs_ruleset property to 0: %s\n", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ type Jail struct {
|
||||
Running bool
|
||||
// No need, Config.Release always represent what is running (plus it know release for non-running jails)
|
||||
//Release string
|
||||
Devfs_ruleset int // The effective devfs ruleset generated at runtime
|
||||
Zpool string
|
||||
Datastore string
|
||||
}
|
||||
@ -247,6 +248,8 @@ type JailSort struct {
|
||||
DatastoreDec jailLessFunc
|
||||
ZpoolInc jailLessFunc
|
||||
ZpoolDec jailLessFunc
|
||||
Devfs_rulesetInc jailLessFunc
|
||||
Devfs_rulesetDec jailLessFunc
|
||||
Config JailConfigSort
|
||||
}
|
||||
|
||||
|
36
jail/main.go
36
jail/main.go
@ -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(¶ms[0], csname)
|
||||
C.jailparam_init(¶ms[1], csjid)
|
||||
C.jailparam_init(¶ms[2], cspath)
|
||||
C.jailparam_init(¶ms[3], csdevfsrs)
|
||||
|
||||
// The key to retrieve jail. lastjid = 0 returns first jail and its jid as jailparam_get return value
|
||||
C.jailparam_init(¶ms[3], cslastjid)
|
||||
C.jailparam_init(¶ms[4], cslastjid)
|
||||
|
||||
lastjailid := 0
|
||||
cslastjidval := C.CString(strconv.Itoa(lastjailid))
|
||||
defer C.free(unsafe.Pointer(cslastjidval))
|
||||
|
||||
C.jailparam_import(¶ms[3], cslastjidval)
|
||||
C.jailparam_import(¶ms[4], cslastjidval)
|
||||
|
||||
// loop on existing jails
|
||||
for lastjailid >= 0 {
|
||||
// get parameter values
|
||||
lastjailid = int(C.jailparam_get(¶ms[0], 4, 0))
|
||||
lastjailid = int(C.jailparam_get(¶ms[0], 5, 0))
|
||||
if lastjailid > 0 {
|
||||
nametmp := C.jailparam_export(¶ms[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(¶ms[2])
|
||||
pathtmp := C.jailparam_export(¶ms[2])
|
||||
jl.Path = C.GoString(pathtmp)
|
||||
// Memory mgmt : Non gere par Go
|
||||
C.free(unsafe.Pointer(pathtmp))
|
||||
|
||||
drstmp := C.jailparam_export(¶ms[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(¶ms[3], cslastjidval)
|
||||
C.jailparam_import(¶ms[4], cslastjidval)
|
||||
}
|
||||
}
|
||||
|
||||
// Free 4 items of params list
|
||||
C.jailparam_free(¶ms[0], 4)
|
||||
// Free 5 items of params list
|
||||
C.jailparam_free(¶ms[0], 5)
|
||||
|
||||
return jls, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user