BUGFIX umounting jail fstab, add umountFsFromHost

This commit is contained in:
yo 2023-08-06 14:50:32 +02:00
parent 346fd52a8e
commit 14984f417c

View File

@ -123,7 +123,7 @@ func deleteDevfsRuleset(ruleset int) error {
return nil
}
func umountJailFsFromHost(jail *Jail, mountpoint string) error {
func umountFsFromHost(mountpoint string) error {
cmd := "mount -p"
out, err := executeCommand(cmd)
if err != nil {
@ -134,11 +134,11 @@ func umountJailFsFromHost(jail *Jail, mountpoint string) error {
for _, l := range strings.Split(out, "\n") {
f := strings.Split(remSpPtrn.ReplaceAllString(l, " "), " ")
if len(f) > 2 {
if strings.EqualFold(f[1], fmt.Sprintf("%s%s", jail.RootPath, mountpoint)) {
cmd = fmt.Sprintf("umount %s%s", jail.RootPath, mountpoint)
if strings.EqualFold(f[1], mountpoint) {
cmd = fmt.Sprintf("umount %s", mountpoint)
_, err := executeCommand(cmd)
if err != nil {
return errors.New(fmt.Sprintf("Error umounting %s%s: %s", jail.RootPath, mountpoint, err.Error()))
return errors.New(fmt.Sprintf("Error umounting %s: %s", mountpoint, err.Error()))
}
return nil
}
@ -148,6 +148,10 @@ func umountJailFsFromHost(jail *Jail, mountpoint string) error {
return nil
}
func umountJailFsFromHost(jail *Jail, mountpoint string) error {
return umountFsFromHost(fmt.Sprintf("%s%s", jail.RootPath, mountpoint))
}
// Internal usage only
func stopJail(jail *Jail) error {
cmd := "jail -q"
@ -270,7 +274,7 @@ func StopJail(args []string) {
for _, a := range args {
// Check if jail exist and is distinctly named
cj, err = getJailFromArray(a, []string{"jail"}, gJails)
cj, err = getJailFromArray(a, []string{"basejail", "jail"}, gJails)
if err != nil {
fmt.Printf("Error getting jail: %s\n", err)
continue
@ -404,7 +408,8 @@ func StopJail(args []string) {
fmt.Printf(" > Umount mountpoints from %s\n", fstab)
errs := 0
for _, m := range mounts {
err = umountJailFsFromHost(cj, m.Mountpoint)
log.Debugf("Umounting %s\n", m.Mountpoint)
err = umountFsFromHost(m.Mountpoint)
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
errs += 1