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