M8 networkmanager: the folder's unknown is the module's
The folder the two parts share says unknown module, so the node-engine does nothing inside it and the watcher reacts: a path it does not know is left as it is and written to its journal once per path, at its start and at the file event that makes it; the README says so. Builds: design 08 sign-in-page §12, §24, §25, §27; lead answer L-1 (hq 3a3a18a9)
This commit is contained in:
@@ -4,6 +4,7 @@ package main
|
||||
// SessionNew, and the system bus's socket coming back, heard as a file event of the kernel on its folder.
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -338,3 +339,56 @@ func watchFiles(dirs []string, match func(string) bool, stop <-chan struct{}) <-
|
||||
}()
|
||||
return out
|
||||
}
|
||||
|
||||
// pathsMade hands each path a file event of the kernel makes in one of dirs, until stop closes; a folder that is not
|
||||
// there is not watched, and said.
|
||||
func pathsMade(dirs []string, stop <-chan struct{}) <-chan string {
|
||||
out := make(chan string, 16)
|
||||
fd, err := unix.InotifyInit1(unix.IN_CLOEXEC | unix.IN_NONBLOCK)
|
||||
if err != nil {
|
||||
journal("watching %v failed: %v", dirs, err)
|
||||
return out
|
||||
}
|
||||
wds := map[int32]string{}
|
||||
for _, dir := range dirs {
|
||||
wd, err := unix.InotifyAddWatch(fd, dir, unix.IN_CREATE|unix.IN_MOVED_TO)
|
||||
if err != nil {
|
||||
journal("watching %s failed: %v", dir, err)
|
||||
continue
|
||||
}
|
||||
wds[int32(wd)] = dir
|
||||
}
|
||||
f := os.NewFile(uintptr(fd), "inotify")
|
||||
go func() {
|
||||
<-stop
|
||||
f.Close()
|
||||
}()
|
||||
go func() {
|
||||
defer f.Close()
|
||||
buf := make([]byte, 64*(unix.SizeofInotifyEvent+unix.NAME_MAX+1))
|
||||
for {
|
||||
n, err := f.Read(buf)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for off := 0; off+unix.SizeofInotifyEvent <= n; {
|
||||
ev := (*unix.InotifyEvent)(unsafe.Pointer(&buf[off]))
|
||||
nameAt := off + unix.SizeofInotifyEvent
|
||||
end := nameAt + int(ev.Len)
|
||||
if end > n {
|
||||
break
|
||||
}
|
||||
name := string(bytes.TrimRight(buf[nameAt:end], "\x00"))
|
||||
off = end
|
||||
if dir, ok := wds[ev.Wd]; ok && name != "" {
|
||||
select {
|
||||
case out <- filepath.Join(dir, name):
|
||||
case <-stop:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user