dwisiswant0 / unmountpoint

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.


Languages

Language:Go 100.0%