From 70623707fd76465c7d03fced48bfa14454ef9e09 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 3 Sep 2015 13:50:53 -0600 Subject: fix bugs in code calling inotify --- src/nshd/hackers_git/hackers_watch.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/nshd/hackers_git/hackers_watch.go b/src/nshd/hackers_git/hackers_watch.go index 99e5eb3..87c856d 100644 --- a/src/nshd/hackers_git/hackers_watch.go +++ b/src/nshd/hackers_git/hackers_watch.go @@ -46,7 +46,6 @@ func (o *Hackers) unwatchHomedir(wd inotify.Cint) { func (o *Hackers) close() { if o.in_fd != nil { o.in_fd.Close() - o.in_fd = nil } o.in_wd_home = -1 o.in_wd_yaml = -1 @@ -140,6 +139,9 @@ func (o *Hackers) worker() { worker_error("failed to load %q: %v", o.cfg.Yamldir, err) } } else if event.Mask&in_CHILD_ANY != 0 { + if (event.Name == nil) { + panic("recieved child event from inotify, but no child name") + } filename := o.cfg.Yamldir + "/" + *event.Name logger.Info("Loading yaml file: %s", filename) user, err := load_user_yaml(filename) @@ -170,10 +172,18 @@ func (o *Hackers) worker() { if event.Mask&in_DIR_INVALID != 0 { o.unwatchHomedir(event.Wd) o.worker_watch_homedirs() - } else if *event.Name == ".password" { - o.worker_handle_passwd(o.in_wd2uid[event.Wd]) + } else if event.Name != nil { + if *event.Name == ".password" { + o.worker_handle_passwd(o.in_wd2uid[event.Wd]) + } + } else { + logger.Debug("event didn't match: %#v", event) } } } - panic("not reached") + // This happens only sometimes--depending on if the main + // goroutine or this goroutine is killed by os.Exit first; + // this happens if the main goroutine calls inotify.Close() + // before this groutine is killed. + logger.Info("Stopping hackers.git inotify watcher") } -- cgit v1.2.2