aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@fastmailteam.com>2023-02-27 17:44:20 -0500
committerCalvin Morrison <calvin@fastmailteam.com>2023-02-27 17:49:35 -0500
commitcbc81ba76807acefecaa7cc60853fd7b35853266 (patch)
treee061bbe41c1b7d9eaad35f99732715ce00171d09
parente367ecdded2d9fecafd30f517c7043d19a75280c (diff)
use $HOME for socketHEADmaster
-rw-r--r--Makefile2
-rw-r--r--moc_library.c16
2 files changed, 6 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 9e4af55..e3951eb 100644
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ mocicon: ${OBJ}
clean:
@echo cleaning
- @rm -f mocicon moc_x11 *.o mocicon-${VERSION}.tar.gz
+ rm -f mocicon moc_x11 *.o mocicon-${VERSION}.tar.gz
dist: clean
@echo creating dist tarball
diff --git a/moc_library.c b/moc_library.c
index cdc1cf6..6b2441c 100644
--- a/moc_library.c
+++ b/moc_library.c
@@ -1,18 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h> //Header file for sleep(). man 3 sleep for details.
+#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <sys/socket.h>
#include <sys/un.h>
-// A normal C function that is executed as a thread
-// when its name is specified in pthread_create()
-//
-
-char *moc_socket_path = "/home/calvin/.moc/socket2";
-
/* State of the server. */
#define STATE_PLAY 0x01
#define STATE_STOP 0x02
@@ -207,18 +201,18 @@ static int moc_server_connect ()
{
struct sockaddr_un sock_name;
int sock;
-
/* Create a socket */
if ((sock = socket (PF_LOCAL, SOCK_STREAM, 0)) == -1)
return -1;
sock_name.sun_family = AF_LOCAL;
- strcpy (sock_name.sun_path, moc_socket_path);
+
+ snprintf(sock_name.sun_path, sizeof(sock_name.sun_path), "%s/.moc/socket2", getenv("HOME"));
if (connect(sock, (struct sockaddr *)&sock_name,
SUN_LEN(&sock_name)) == -1) {
close (sock);
- fprintf(stderr, "%s at (%s)\n", strerror(errno), moc_socket_path);
+ fprintf(stderr, "%s at (%s)\n", strerror(errno), sock_name.sun_path);
return -1;
}
@@ -313,7 +307,7 @@ void *moc_loop(void *input) {
pthread_mutex_unlock(&data->lock);
}
else {
- fprintf(stderr, "moc: shit i have data IDK what it is\n");
+ fprintf(stderr, "moc: UNKNOWN STATE\n");
}
last_cmd = -1;