From cbc81ba76807acefecaa7cc60853fd7b35853266 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Mon, 27 Feb 2023 17:44:20 -0500 Subject: use $HOME for socket --- Makefile | 2 +- moc_library.c | 16 +++++----------- 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 #include -#include //Header file for sleep(). man 3 sleep for details. +#include #include #include #include #include -// 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; -- cgit v1.2.1