Skip to content

Go library to wait for the detached/unmounted state of a path.

Notifications You must be signed in to change notification settings

dwisiswant0/unmountpoint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unmountpoint

Unmountpoint is Go library to wait for the detached/unmounted state of a path.

DISCLAIMER: This project is under development and fully experimental mode.

Installation

$ go get -v github.com/dwisiswant0/unmountpoint/pkg/unmount

Usage

package main

import (
	"log"
	"os"
	"time"

	"github.com/dwisiswant0/unmountpoint/pkg/unmount"
)

func main() {
	p := "/media/dw1/USB-BUS1" // Mountpoint path to watch
	c := make(chan bool, 1)
	e := unmount.Wait(c, p)

	if e != nil {
		log.Fatal(e)
	}

	go func() {
		<-c
		// Unmounted!
		// Do stuff e.g. rm -rf /

		log.Println("Path unmounted!")
		os.Exit(1)
	}()

	log.Printf("Wait for %s path to detach/unmounted...\n", p)
	for {
		time.Sleep(10 * time.Second)
	}
}

Basically like signal.Notify. If /media/dw1/USB-BUS1 directory is unmounted; Wait assigns channel value then do some stuff (if any).

See examples.

TODO

See TODO.

Acknowledgements

  • BusKill served as my inspiration.

License

Unmountpoint is distributed under Apache-2.0. See LICENSE.

About

Go library to wait for the detached/unmounted state of a path.

Topics

Resources

Stars

Watchers

Forks

Languages