Use getJailFromArray so we can handle same name jails + check pertinence before jailing non existing DS

This commit is contained in:
yo 2022-07-10 14:16:24 +02:00
parent e7a6bdd376
commit 484e05e8d1

View File

@ -212,6 +212,7 @@ func prepareJailedZfsDatasets(jail *Jail) error {
} }
func jailZfsDatasets(jail *Jail) error { func jailZfsDatasets(jail *Jail) error {
if jail.Config.Jail_zfs > 0 {
for _, d := range strings.Split(jail.Config.Jail_zfs_dataset, " ") { for _, d := range strings.Split(jail.Config.Jail_zfs_dataset, " ") {
// Jail dataset // Jail dataset
cmd := fmt.Sprintf("zfs jail %d %s/%s", jail.JID, jail.Zpool, d) cmd := fmt.Sprintf("zfs jail %d %s/%s", jail.JID, jail.Zpool, d)
@ -234,6 +235,7 @@ func jailZfsDatasets(jail *Jail) error {
} }
} }
} }
}
return nil return nil
} }
@ -1028,18 +1030,11 @@ func StartJail(args []string) {
var cj *Jail var cj *Jail
var err error var err error
for _, j := range args { for _, a := range args {
fmt.Printf("> Starting jail %s\n", j) // Check if jail exist and is distinctly named
cj, err = getJailFromArray(a, gJails)
for i, rj := range gJails { if err != nil {
if rj.Name == j { fmt.Printf("Error getting jail: %s\n", err)
// Get jail reference, not a copy of it; So we can modify attributes
cj = &gJails[i]
break
}
}
if cj == nil {
fmt.Printf("Jail not found: %s\n", j)
continue continue
} }
@ -1048,6 +1043,8 @@ func StartJail(args []string) {
continue continue
} }
fmt.Printf("> Starting jail %s\n", a)
// Set InternalName as it is used by some of these // Set InternalName as it is used by some of these
cj.InternalName = fmt.Sprintf("ioc-%s", cj.Name) cj.InternalName = fmt.Sprintf("ioc-%s", cj.Name)