()
| 377 | } |
| 378 | |
| 379 | func unmountAll() { |
| 380 | mounts, err := os.Open("/proc/mounts") |
| 381 | if err != nil { |
| 382 | log.Printf("Cannot open /proc/mounts: %v", err) |
| 383 | return |
| 384 | } |
| 385 | defer mounts.Close() |
| 386 | scanner := bufio.NewScanner(mounts) |
| 387 | for scanner.Scan() { |
| 388 | line := scanner.Text() |
| 389 | parts := strings.Split(line, " ") |
| 390 | if len(parts) > 3 { |
| 391 | dest := parts[1] |
| 392 | tp := parts[2] |
| 393 | switch tp { |
| 394 | // do not unmount tmpfs or virtual filesystems, just ones that need to write data |
| 395 | case "ext2", "ext3", "ext4", "btrfs", "xfs", "vfat", "msdos", "overlay": |
| 396 | if err := unix.Unmount(dest, 0); err != nil { |
| 397 | log.Printf("error unmounting %s: %v", dest, err) |
| 398 | } |
| 399 | case "nfs", "nfs4", "cifs": |
| 400 | // lazy unmount as we do not want to block on network mounts |
| 401 | if err := unix.Unmount(dest, unix.MNT_DETACH); err != nil { |
| 402 | log.Printf("error unmounting %s: %v", dest, err) |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | func doShutdown(action string) { |
| 410 | runInit("/etc/shutdown.d") |
no test coverage detected