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 { 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 // 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 { if len(args) > 0 {
cj, err := getJailFromArray(args[0], gJails) cj, err := getJailFromArray(args[0], []string{"jail"}, gJails)
if err != nil { if err != nil {
fmt.Printf("Error getting jail %s: %v\n", args[0], err) fmt.Printf("Error getting jail %s: %v\n", args[0], err)
return err return err

View File

@ -3,13 +3,14 @@ package cmd
import ( import (
"fmt" "fmt"
//"log" //"log"
"time"
//"errors" //"errors"
"strings" "strings"
) )
func DestroyJails(args []string) { func DestroyJails(args []string) {
for _, a := range args { for _, a := range args {
cj, err := getJailFromArray(a, gJails) cj, err := getJailFromArray(a, []string{""}, gJails)
if err != nil { if err != nil {
fmt.Printf("Error getting jail: %s\n", err) fmt.Printf("Error getting jail: %s\n", err)
return return
@ -27,6 +28,8 @@ func DestroyJails(args []string) {
} }
fmt.Printf("Stopping jail %s\n", cj.Name) fmt.Printf("Stopping jail %s\n", cj.Name)
StopJail([]string{fmt.Sprintf("%s/%s", cj.Datastore, 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 // Get root and config datasets, then destroy
@ -51,7 +54,6 @@ func DestroyJails(args []string) {
fmt.Printf("Error deleting config dataset: %s\n", err) fmt.Printf("Error deleting config dataset: %s\n", err)
return return
} }
fmt.Printf("Jail %s is no more!\n", cj.Name)
//TODO: Delete jail named directory
} }
} }

View File

@ -26,7 +26,7 @@ func MigrateJail(args []string) {
} }
for _, jn := range jailNames { for _, jn := range jailNames {
cj, err := getJailFromArray(jn, gJails) cj, err := getJailFromArray(jn, []string{""}, gJails)
if cj == nil { if cj == nil {
fmt.Printf("Error getting jail %s: Not found\n", jn) fmt.Printf("Error getting jail %s: Not found\n", jn)
return return
@ -177,7 +177,7 @@ func CleanMigrateMess(args []string) error {
} }
for _, jn := range jailNames { for _, jn := range jailNames {
cj, err := getJailFromArray(jn, gJails) cj, err := getJailFromArray(jn, []string{""}, gJails)
if cj == nil { if cj == nil {
return errors.New(fmt.Sprintf("Error getting jail %s: Not found\n", jn)) 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 { for i, a := range args {
// Last arg is the jail name // Last arg is the jail name
if i == len(args)-1 { if i == len(args)-1 {
jail, err = getJailFromArray(a, gJails) jail, err = getJailFromArray(a, []string{""}, gJails)
if err != nil { if err != nil {
fmt.Printf("Error: %s\n", err.Error()) fmt.Printf("Error: %s\n", err.Error())
return return

View File

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

View File

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

View File

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