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]
for _, event := range ready {
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)
} else {
log.Printf("Unhandled epoll event: %d for fd %d", event.Events, event.Fd)

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

Loading…
Cancel
Save