summary refs log tree commit diff
path: root/rvnit.c
diff options
context:
space:
mode:
Diffstat (limited to 'rvnit.c')
-rw-r--r--rvnit.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/rvnit.c b/rvnit.c
index b35850b..f427fe1 100644
--- a/rvnit.c
+++ b/rvnit.c
@@ -3,6 +3,7 @@
 
 #include <sys/wait.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/un.h>
 
 #include <ctype.h>
@@ -172,7 +173,19 @@ socket_loop(void* ignored)
 {
 	(void)ignored;
 
-	const char *path = "/tmp/rvnit.sock";
+	static const char default_sock[] = "/run/rvnit/rvnit.sock";
+	const char *path = getenv("RVNIT_SOCK");
+	if (!path || !*path)
+		path = default_sock;
+
+	char *last_slash = strrchr(path, '/');
+	if (last_slash) {
+		char dir[PATH_MAX];
+		memcpy(dir, path, last_slash - path);
+		dir[last_slash - path] = 0;
+		mkdir(dir, 0700);
+		// ignore errors
+	}
 
 	struct sockaddr_un addr = { 0 };
 	addr.sun_family = AF_UNIX;
@@ -183,7 +196,9 @@ socket_loop(void* ignored)
 		exit(111);
 	}
 	unlink(path);
+	mode_t mask = umask(0077);
 	int r = bind(listenfd, (struct sockaddr *)&addr, sizeof addr);
+	umask(mask);
 	if (r < 0) {
 		perror("bind");
 		exit(111);