diff options
author | Calvin Morrison <calvin@fastmailteam.com> | 2023-02-27 17:44:20 -0500 |
---|---|---|
committer | Calvin Morrison <calvin@fastmailteam.com> | 2023-02-27 17:49:35 -0500 |
commit | cbc81ba76807acefecaa7cc60853fd7b35853266 (patch) | |
tree | e061bbe41c1b7d9eaad35f99732715ce00171d09 /moc_library.c | |
parent | e367ecdded2d9fecafd30f517c7043d19a75280c (diff) |
Diffstat (limited to 'moc_library.c')
-rw-r--r-- | moc_library.c | 16 |
1 files changed, 5 insertions, 11 deletions
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; |