From ae05433278739b1faafef7e18debccefc920c046 Mon Sep 17 00:00:00 2001
From: anatasluo <luolongjuna@gmail.com>
Date: Wed, 31 Mar 2021 15:37:52 +0800
Subject: [PATCH 11/20] nvwa: move unix socket from /run to /run/nvwa

Signed-off-by: anatasluo <luolongjuna@gmail.com>
---
 src/main.go   |  2 +-
 src/server.go | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/main.go b/src/main.go
index d139f78..bcb5bb4 100644
--- a/src/main.go
+++ b/src/main.go
@@ -4,7 +4,7 @@ import (
 	"flag"
 )
 
-var socketPath = "/run/nvwa.socket"
+var socketPath = "/run/nvwa/nvwa.socket"
 
 func main() {
 	server := flag.Int("server", 0,
diff --git a/src/server.go b/src/server.go
index 1185789..3de06a5 100644
--- a/src/server.go
+++ b/src/server.go
@@ -6,6 +6,7 @@ import (
 	"net"
 	"os"
 	"path"
+	"path/filepath"
 	"reflect"
 	"runtime"
 	"strconv"
@@ -431,12 +432,23 @@ func ExitServer(msg string) int {
 	return 0
 }
 
+func may_init_socket(path string) error {
+	socketDir := filepath.Dir(path)
+	log.Debugf("Socket directory %s \n", socketDir)
+	return os.Mkdir(socketDir, 0700)
+}
+
 func runServer(path string) {
 	registerRPC("update", UpdateImage)
 	registerRPC("restore", RestoreService)
 	registerRPC("init", InitEnv)
 	registerRPC("exit", ExitServer)
 
+	err := may_init_socket(path)
+	if err != nil {
+		log.Fatal(err)
+	}
+
 	addr, err := net.ResolveUnixAddr("unix", path)
 	if err != nil {
 		log.Fatal(err)
-- 
2.31.1

