// TODO: Make the error code optional (as a parameter)
os.Exit(1)
}
funcwatchForConfigChanges(){
watcher,err:=fsnotify.NewWatcher()
iferr!=nil{
@ -21,12 +26,22 @@ func watchForConfigChanges() {
for{
select{
caseevent:=<-watcher.Events:
log.Println("event: ",event)
// The file is changed. This is the only event we are interested
// in. If the file is renamed, removed or something else, we drop
// an error to the user.
ifevent.Op&fsnotify.Write==fsnotify.Write{
log.Println("modified file:",event.Name)
log.Println("Reload the config file ...")
}
ifevent.Op&fsnotify.Rename==fsnotify.Rename||
event.Op&fsnotify.Remove==fsnotify.Remove{
log.Println("The 'keymap.conf' configuration file is renamed or removed. We cant do any further changes without the config file. So create the file or rename it back and restart the agent.")
stop()
}
caseerr:=<-watcher.Errors:
log.Println("error:",err)
log.Println("We have the following problem with the 'keymap.conf' configuration file: ",err)
log.Println("Try the fix this problem by yourself and restart the agent.")
stop()
}
}
}()
@ -37,7 +52,6 @@ func watchForConfigChanges() {
// places where windows will put it).
config_path,err:=os.Getwd()
config_file:=path.Join(config_path,"keymap.conf")
err=watcher.Add(config_file)
iferr!=nil{
log.Fatal("Can't find the 'keymap.conf' configuration file. Please create one.")