cleanup old unix socket and set write permissions

This commit is contained in:
Balakrishnan Balasubramanian 2023-03-29 18:37:30 -04:00
parent a479dab96c
commit 0b1d455bc5

14
main.go
View File

@ -4,8 +4,10 @@ package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/fs"
"log"
"net"
"net/http"
@ -146,10 +148,20 @@ func main() {
}
})
if unixSocketPath != "" {
// Remove old one
if err := os.Remove(unixSocketPath); err != nil && !errors.Is(err, fs.ErrNotExist) {
log.Panicf("Failed to remove unix socket : %q err: %v\n", unixSocketPath, err)
}
l, err := net.Listen("unix", unixSocketPath)
if err != nil {
log.Panicf("Unable to listen to unix socket in path: %q err:%v\n", unixSocketPath, err)
log.Panicf("Unable to listen to unix socket : %q err: %v\n", unixSocketPath, err)
}
if err = os.Chmod(unixSocketPath, 0666); err != nil {
log.Panicf("Failed to set permission of unix socket %q err: %v\n", unixSocketPath, err)
}
log.Panicln(http.Serve(l, nil))
}
log.Panicln(http.ListenAndServe(fmt.Sprintf(":%v", port), nil))