getJailFromArray filtering by type

This commit is contained in:
yo 2023-08-05 19:49:50 +02:00
parent bce37e6541
commit 45e1c57ce4
7 changed files with 12 additions and 10 deletions

View File

@ -12,7 +12,7 @@ import (
func ShellJail(args []string) error {
// We cant shell more than one jail bc we replace gocage execution with jexec, so there wont be no return to gocage
if len(args) > 0 {
cj, err := getJailFromArray(args[0], gJails)
cj, err := getJailFromArray(args[0], []string{"jail"}, gJails)
if err != nil {
fmt.Printf("Error getting jail %s: %v\n", args[0], err)
return err

View File

@ -3,13 +3,14 @@ package cmd
import (
"fmt"
//"log"
"time"
//"errors"
"strings"
)
func DestroyJails(args []string) {
for _, a := range args {
cj, err := getJailFromArray(a, gJails)
cj, err := getJailFromArray(a, []string{""}, gJails)
if err != nil {
fmt.Printf("Error getting jail: %s\n", err)
return
@ -27,6 +28,8 @@ func DestroyJails(args []string) {
}
fmt.Printf("Stopping jail %s\n", cj.Name)
StopJail([]string{fmt.Sprintf("%s/%s", cj.Datastore, cj.Name)})
// Give some time to the host OS to free all mounts accessing processes
time.Sleep(1 * time.Second)
}
// Get root and config datasets, then destroy
@ -51,7 +54,6 @@ func DestroyJails(args []string) {
fmt.Printf("Error deleting config dataset: %s\n", err)
return
}
//TODO: Delete jail named directory
fmt.Printf("Jail %s is no more!\n", cj.Name)
}
}

View File

@ -26,7 +26,7 @@ func MigrateJail(args []string) {
}
for _, jn := range jailNames {
cj, err := getJailFromArray(jn, gJails)
cj, err := getJailFromArray(jn, []string{""}, gJails)
if cj == nil {
fmt.Printf("Error getting jail %s: Not found\n", jn)
return
@ -177,7 +177,7 @@ func CleanMigrateMess(args []string) error {
}
for _, jn := range jailNames {
cj, err := getJailFromArray(jn, gJails)
cj, err := getJailFromArray(jn, []string{""}, gJails)
if cj == nil {
return errors.New(fmt.Sprintf("Error getting jail %s: Not found\n", jn))
}

View File

@ -17,7 +17,7 @@ func GetJailProperties(args []string) {
for i, a := range args {
// Last arg is the jail name
if i == len(args)-1 {
jail, err = getJailFromArray(a, gJails)
jail, err = getJailFromArray(a, []string{""}, gJails)
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return

View File

@ -270,7 +270,7 @@ func StopJail(args []string) {
for _, a := range args {
// Check if jail exist and is distinctly named
cj, err = getJailFromArray(a, gJails)
cj, err = getJailFromArray(a, []string{"jail"}, gJails)
if err != nil {
fmt.Printf("Error getting jail: %s\n", err)
continue

View File

@ -53,7 +53,7 @@ func UpdateJail(args []string) {
for _, a := range args {
// Check if jail exist and is distinctly named
cj, err = getJailFromArray(a, gJails)
cj, err = getJailFromArray(a, []string{""}, gJails)
if err != nil {
fmt.Printf("Error getting jail: %s\n", err)
continue

View File

@ -91,7 +91,7 @@ func UpgradeJail(args []string) {
for _, a := range args {
// Check if jail exist and is distinctly named
cj, err = getJailFromArray(a, gJails)
cj, err = getJailFromArray(a, []string{""}, gJails)
if err != nil {
fmt.Printf("Error getting jail: %s\n", err)
continue