mirror of
https://gitlab.com/arm-research/smarter/smarter-device-manager.git
synced 2024-11-22 02:33:34 +00:00
32 lines
499 B
Go
32 lines
499 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/fsnotify/fsnotify"
|
||
|
"os"
|
||
|
"os/signal"
|
||
|
)
|
||
|
|
||
|
func newFSWatcher(files ...string) (*fsnotify.Watcher, error) {
|
||
|
watcher, err := fsnotify.NewWatcher()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
for _, f := range files {
|
||
|
err = watcher.Add(f)
|
||
|
if err != nil {
|
||
|
watcher.Close()
|
||
|
return nil, err
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return watcher, nil
|
||
|
}
|
||
|
|
||
|
func newOSWatcher(sigs ...os.Signal) chan os.Signal {
|
||
|
sigChan := make(chan os.Signal, 1)
|
||
|
signal.Notify(sigChan, sigs...)
|
||
|
|
||
|
return sigChan
|
||
|
}
|