diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-09-05 13:59:36 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-09-05 13:59:36 -0600 |
commit | a3e3251f2ef27ddb33a74a679729d6d5447307b5 (patch) | |
tree | f39f5c50e139291597265c0a83339f02b4307eb3 /src/nshd/hackers_git/hackers_watch.go | |
parent | adc8af1a3a0d9077621d2b9b5e36b33452f31947 (diff) |
inotify: Avoid most of the race conditions, get rid of Cint
There's still a condition that could be a race with fd-reuse, if one
goroutine is calling inotify.{AddWatch,RmWatch,Read}(); another
goroutine is calling inotify.Close(), and several things happen between
loadFd() running and the add_watch/rm_watch/read syscall launching:
- syscall.Close() returns
- syscall.Open() reuses the filedescriptor
A B
syscall(loadFd()) inotify.Close(); syscall.Open()
----------------------------------------------------------
loadFd()
syscall.Close()
syscall.Open()
syscall()
Given that Read() can't be allowed to block Close() from running, I'm not
sure there's a way to fix this.
Diffstat (limited to 'src/nshd/hackers_git/hackers_watch.go')
-rw-r--r-- | src/nshd/hackers_git/hackers_watch.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/nshd/hackers_git/hackers_watch.go b/src/nshd/hackers_git/hackers_watch.go index da008f8..b273741 100644 --- a/src/nshd/hackers_git/hackers_watch.go +++ b/src/nshd/hackers_git/hackers_watch.go @@ -36,7 +36,7 @@ func (o *Hackers) watchHomedir(uid int32) { o.users[uid] = user } -func (o *Hackers) unwatchHomedir(wd inotify.Cint) { +func (o *Hackers) unwatchHomedir(wd inotify.Wd) { err := o.in_fd.RmWatch(wd) if err != nil { logger.Warning("hackers.git: %v", err) @@ -57,8 +57,8 @@ func (o *Hackers) close() { o.in_wd_home = -1 o.in_wd_yaml = -1 o.users = make(map[int32]user, 0) - o.in_uid2wd = make(map[int32]inotify.Cint, 0) - o.in_wd2uid = make(map[inotify.Cint]int32, 0) + o.in_uid2wd = make(map[int32]inotify.Wd, 0) + o.in_wd2uid = make(map[inotify.Wd]int32, 0) } func (o *Hackers) reload() (err error) { @@ -69,8 +69,8 @@ func (o *Hackers) reload() (err error) { filenames, err := filepath.Glob(o.cfg.Yamldir + "/*.yml") o.users = make(map[int32]user, len(filenames)) - o.in_uid2wd = make(map[int32]inotify.Cint, len(filenames)) - o.in_wd2uid = make(map[inotify.Cint]int32, len(filenames)) + o.in_uid2wd = make(map[int32]inotify.Wd, len(filenames)) + o.in_wd2uid = make(map[inotify.Wd]int32, len(filenames)) for _, filename := range filenames { logger.Debug("hackers.git: Loading yaml file: %s", filename) user, err := load_user_yaml(filename) |