smarter-device-manager/watchers.go

34 lines
531 B
Go
Raw Permalink Normal View History

2020-01-17 21:25:46 +00:00
// Copyright (c) 2019, Arm Ltd
2019-11-22 16:52:49 +00:00
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
}