fix linting errors

main
Jörg Thalheim 2 years ago
parent da1f3210f3
commit 7f6af15b82
No known key found for this signature in database

@ -34,7 +34,9 @@ func (s *server) handleEpoll() {
ready := events[:n] ready := events[:n]
for _, event := range ready { for _, event := range ready {
if event.Events&(syscall.EPOLLHUP|syscall.EPOLLERR) != 0 { if event.Events&(syscall.EPOLLHUP|syscall.EPOLLERR) != 0 {
s.epollDelete(int(event.Fd)) if err := s.epollDelete(int(event.Fd)); err != nil {
log.Printf("failed to remove socket from epoll: %s", err)
}
s.connectionClosed <- int(event.Fd) s.connectionClosed <- int(event.Fd)
} else { } else {
log.Printf("Unhandled epoll event: %d for fd %d", event.Events, event.Fd) log.Printf("Unhandled epoll event: %d for fd %d", event.Events, event.Fd)

@ -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)
} }

Loading…
Cancel
Save