blob: f285f8b464218934e59a350ae13595035319a0e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package jail
import (
"fmt"
"golang.org/x/sys/unix"
)
func (j *Jail) mount() error {
for dest, src := range j.bindMounts {
var opts uintptr = unix.MS_BIND | unix.MS_REC
if err := unix.Mount(src, dest, "none", opts, ""); err != nil {
return fmt.Errorf("Failed to bind mount %s on %s. %s", src, dest, err)
}
}
return nil
}
func (j *Jail) unmount() error {
for dest := range j.bindMounts {
if err := unix.Unmount(dest, unix.MNT_DETACH); err != nil {
// A second invocation on unmount with MNT_DETACH flag will return EINVAL
// there's no need to abort with an error if bind mountpoint is already unmounted
if err != unix.EINVAL {
return fmt.Errorf("Failed to unmount %s. %s", dest, err)
}
}
}
return nil
}
|