From 8436272d180b007e265ac2493767d1bfd21914c8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 12 Sep 2015 00:24:08 -0600 Subject: hackers_watch: fix double-lock error --- src/nshd/hackers_git/hackers_watch.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/nshd/hackers_git/hackers_watch.go') diff --git a/src/nshd/hackers_git/hackers_watch.go b/src/nshd/hackers_git/hackers_watch.go index 919a578..c10ec78 100644 --- a/src/nshd/hackers_git/hackers_watch.go +++ b/src/nshd/hackers_git/hackers_watch.go @@ -70,7 +70,7 @@ func (o *Hackers) reload() (err error) { o.in_uid2wd = make(map[int32]inotify.Wd, len(filenames)) o.in_wd2uid = make(map[inotify.Wd]int32, len(filenames)) for _, filename := range filenames { - o.load_yaml_file(filename) + o.load_yaml_file(filename, false) } err = nil @@ -97,14 +97,16 @@ func (o *Hackers) del_user_from_group(username string, groupname string) { } } -func (o *Hackers) load_yaml_file(filename string) { +func (o *Hackers) load_yaml_file(filename string, uselock bool) { logger.Debug("hackers.git: Loading YAML file: %s", filename) user, err := parse_user_yaml(filename) uid := user.passwd.UID if err == nil { logger.Debug("hackers.git: -> User %d added/updated", uid) - o.lock.Lock() - defer o.lock.Unlock() + if uselock { + o.lock.Lock() + defer o.lock.Unlock() + } if olduser, found := o.users[uid]; found { for _, groupname := range olduser.groups { o.del_user_from_group(olduser.passwd.Name, groupname) @@ -118,8 +120,10 @@ func (o *Hackers) load_yaml_file(filename string) { } else if uid >= 0 { // User became invalid logger.Debug("hackers.git: -> User %d invalidated: %v", uid, err) - o.lock.Lock() - defer o.lock.Unlock() + if uselock { + o.lock.Lock() + defer o.lock.Unlock() + } if wd, found := o.in_uid2wd[uid]; found { o.unwatchHomedir(wd) } -- cgit v1.2.2