From: =?utf-8?b?0L3QsNCx?= <nabijaczleweli@nabijaczleweli.xyz>
Date: Fri, 22 Nov 2024 00:29:12 +0100
Subject: Try harder to make xbsndsrv.pid. Don't segfault if can't make
 xbsndsrv.pid (Closes: #716488)

---
 xbsndsrv.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/xbsndsrv.c b/xbsndsrv.c
index 24fe3aa..c13a984 100644
--- a/xbsndsrv.c
+++ b/xbsndsrv.c
@@ -542,14 +542,20 @@ RunningInstances (void)
 	/* set private xblast path */
 	home = getenv ("HOME");
 	if (NULL == home) {
-		strcpy (userPath, "./user/xbsndsrv.pid");
+		strcpy (userPath, "./user");
 	}
 	else {
-		sprintf (userPath, "%s/.xblast_tnt/xbsndsrv.pid", home);
+		sprintf (userPath, "%s/.xblast_tnt", home);
 	}
+	mkdir (userPath, 0755);
+	strcat (userPath, "/xbsndsrv.pid");
 	ptr = fopen (userPath, "r+");
 	if (ptr == NULL) {
 		ptr = fopen (userPath, "w+");
+		if (!ptr) {
+			fprintf (stderr, "xbsndsrv: %s: %s\n", userPath, strerror(errno));
+			exit (1);
+		}
 		sprintf (tmp, PID_FORMAT, getpid ());
 		fwrite (tmp, 1, strlen (tmp), ptr);
 		fclose (ptr);
