crashing not allowed
Some checks failed
builder / build (push) Failing after 24s

This commit is contained in:
abs3nt 2024-10-26 19:44:41 -07:00
parent 88af3135fc
commit 785df8ee46
Signed by: abs3nt
GPG Key ID: A7BD96A8BAB04C09

View File

@ -5,6 +5,7 @@ import (
"net" "net"
"net/rpc" "net/rpc"
"os" "os"
"time"
"go.uber.org/fx" "go.uber.org/fx"
@ -13,34 +14,54 @@ import (
) )
func Run(c *commands.Commander, conf *config.Config, s fx.Shutdowner) { func Run(c *commands.Commander, conf *config.Config, s fx.Shutdowner) {
socketPath := conf.SocketPath
if _, err := os.Stat(socketPath); err == nil {
os.Remove(socketPath)
}
CommandHandler := Handler{
Commander: c,
}
server := rpc.NewServer()
server.Register(&CommandHandler)
listener, err := net.Listen("unix", socketPath)
if err != nil {
log.Fatal("Listen error:", err)
}
defer listener.Close()
os.Chmod(socketPath, 0o666)
log.Println("Daemon is listening on", socketPath)
for { for {
conn, err := listener.Accept() func() {
if err != nil { defer func() {
log.Println("Accept error:", err) if r := recover(); r != nil {
continue log.Printf("Recovered in Run: %v", r)
} }
codec := NewLoggingServerCodec(conn) }()
go server.ServeCodec(codec)
socketPath := conf.SocketPath
if _, err := os.Stat(socketPath); err == nil {
os.Remove(socketPath)
}
CommandHandler := Handler{
Commander: c,
}
server := rpc.NewServer()
server.Register(&CommandHandler)
listener, err := net.Listen("unix", socketPath)
if err != nil {
log.Println("Listen error:", err)
time.Sleep(time.Second)
return
}
defer listener.Close()
os.Chmod(socketPath, 0o666)
log.Println("Daemon is listening on", socketPath)
for {
conn, err := listener.Accept()
if err != nil {
log.Println("Accept error:", err)
continue
}
codec := NewLoggingServerCodec(conn)
go func() {
defer func() {
if r := recover(); r != nil {
log.Printf("Recovered in ServeCodec goroutine: %v", r)
}
}()
server.ServeCodec(codec)
}()
}
}()
time.Sleep(time.Second)
} }
} }