|
|
@ -18,21 +18,11 @@ type inotifyRequest struct {
|
|
|
|
conn *net.UnixConn
|
|
|
|
conn *net.UnixConn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type watcher struct {
|
|
|
|
|
|
|
|
requests chan inotifyRequest
|
|
|
|
|
|
|
|
connectionEvents chan int
|
|
|
|
|
|
|
|
dir string
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type connection struct {
|
|
|
|
type connection struct {
|
|
|
|
fd int
|
|
|
|
fd int
|
|
|
|
connection *net.UnixConn
|
|
|
|
connection *net.UnixConn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type watch struct {
|
|
|
|
|
|
|
|
connections []connection
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func readEvents(inotifyFd int, events chan string) {
|
|
|
|
func readEvents(inotifyFd int, events chan string) {
|
|
|
|
var buf [syscall.SizeofInotifyEvent * 4096]byte // Buffer for a maximum of 4096 raw events
|
|
|
|
var buf [syscall.SizeofInotifyEvent * 4096]byte // Buffer for a maximum of 4096 raw events
|
|
|
|
for {
|
|
|
|
for {
|
|
|
@ -111,7 +101,7 @@ func (s *server) watch(inotifyFd int) {
|
|
|
|
fdToPath[fd] = req.filename
|
|
|
|
fdToPath[fd] = req.filename
|
|
|
|
conns, ok := connsForPath[req.filename]
|
|
|
|
conns, ok := connsForPath[req.filename]
|
|
|
|
if ok {
|
|
|
|
if ok {
|
|
|
|
conns = append(conns, connection{fd, req.conn})
|
|
|
|
connsForPath[req.filename] = append(conns, connection{fd, req.conn})
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -128,18 +118,21 @@ func (s *server) watch(inotifyFd int) {
|
|
|
|
delete(connsForPath, fname)
|
|
|
|
delete(connsForPath, fname)
|
|
|
|
|
|
|
|
|
|
|
|
for _, conn := range conns {
|
|
|
|
for _, conn := range conns {
|
|
|
|
f, err := os.Open(filepath.Join(s.SecretDir, fname))
|
|
|
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
defer delete(fdToPath, conn.fd)
|
|
|
|
defer delete(fdToPath, conn.fd)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f, err := os.Open(filepath.Join(s.SecretDir, fname))
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
|
|
|
|
_, err := io.Copy(conn.connection, f)
|
|
|
|
_, err := io.Copy(conn.connection, f)
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
log.Printf("Served %s to %s", fname, conn.connection.RemoteAddr().String())
|
|
|
|
log.Printf("Served %s to %s", fname, conn.connection.RemoteAddr().String())
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.Printf("Failed to send secret: %v", err)
|
|
|
|
log.Printf("Failed to send secret: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.epollDelete(conn.fd)
|
|
|
|
if err := s.epollDelete(conn.fd); err != nil {
|
|
|
|
|
|
|
|
log.Printf("failed to remove socket from epoll: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
if err := syscall.Shutdown(conn.fd, syscall.SHUT_RDWR); err != nil {
|
|
|
|
if err := syscall.Shutdown(conn.fd, syscall.SHUT_RDWR); err != nil {
|
|
|
|
log.Printf("Failed to shutdown socket: %v", err)
|
|
|
|
log.Printf("Failed to shutdown socket: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|