clean-up sockfile on exit
This commit is contained in:
parent
a4b75bb90d
commit
c46ab056f5
12
main.go
12
main.go
|
@ -8,7 +8,13 @@ import (
|
|||
|
||||
var config Config
|
||||
|
||||
const sockfile = "/tmp/gopaper.sock"
|
||||
|
||||
func main() {
|
||||
//TODO:kill existing processes
|
||||
|
||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||
|
||||
err := config.load()
|
||||
if err != nil {
|
||||
log.Println("failed to load config", err)
|
||||
|
@ -20,6 +26,7 @@ func main() {
|
|||
var waitGroup sync.WaitGroup
|
||||
waitGroup.Add(1)
|
||||
slideshowDir := make(chan string)
|
||||
|
||||
go server(slideshowDir)
|
||||
go slideshow(slideshowDir)
|
||||
|
||||
|
@ -34,3 +41,8 @@ func main() {
|
|||
|
||||
waitGroup.Wait()
|
||||
}
|
||||
|
||||
func cleanExit(code int) {
|
||||
os.Remove(sockfile)
|
||||
os.Exit(code)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ import (
|
|||
|
||||
func server(slideshowDir chan string) {
|
||||
|
||||
sockfile := "/tmp/bg-go.sock"
|
||||
defer os.Remove(sockfile)
|
||||
|
||||
//Create a Unix domain socket and listen for incoming connections.
|
||||
socket, err := net.Listen("unix", sockfile)
|
||||
if err != nil {
|
||||
|
@ -27,7 +28,6 @@ func server(slideshowDir chan string) {
|
|||
os.Remove(sockfile)
|
||||
os.Exit(1)
|
||||
}()
|
||||
defer os.Remove(sockfile)
|
||||
|
||||
for {
|
||||
//Accept incoming
|
||||
|
|
Loading…
Reference in New Issue