File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 "fmt"
66 "net"
77 "os"
8+ "path/filepath"
9+ "strings"
810 "sync"
911 "syscall"
1012
@@ -298,6 +300,26 @@ func (n *network) initSubnetSandbox(s *subnet) error {
298300 return nil
299301}
300302
303+ func (n * network ) cleanupStaleSandboxes () {
304+ filepath .Walk (filepath .Dir (osl .GenerateKey ("walk" )),
305+ func (path string , info os.FileInfo , err error ) error {
306+ _ , fname := filepath .Split (path )
307+
308+ pList := strings .Split (fname , "-" )
309+ if len (pList ) <= 1 {
310+ return nil
311+ }
312+
313+ pattern := pList [1 ]
314+ if strings .Contains (n .id , pattern ) {
315+ syscall .Unmount (path , syscall .MNT_DETACH )
316+ os .Remove (path )
317+ }
318+
319+ return nil
320+ })
321+ }
322+
301323func (n * network ) initSandbox () error {
302324 n .Lock ()
303325 n .initEpoch ++
@@ -311,6 +333,10 @@ func (n *network) initSandbox() error {
311333 }
312334 }
313335
336+ // If there are any stale sandboxes related to this network
337+ // from previous daemon life clean it up here
338+ n .cleanupStaleSandboxes ()
339+
314340 sbox , err := osl .NewSandbox (
315341 osl .GenerateKey (fmt .Sprintf ("%d-" , n .initEpoch )+ n .id ), ! hostMode )
316342 if err != nil {
You can’t perform that action at this time.
0 commit comments