From 59fc8d81a567e802e8d28f5b0f44144253b2e77b Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Sun, 13 Aug 2023 14:19:10 +0900 Subject: [PATCH] Fixes, print on error --- src/plugin.c | 2 +- src/socket.c | 11 +++++++++-- src/socket.h | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index 8af859f..b879892 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -16,7 +16,7 @@ OBS_MODULE_USE_DEFAULT_LOCALE("unix-socket-control", "en-US") bool obs_module_load(void) { init_unix_socket_handler(&global_unix_socket_handler); - return is_unix_socket_handler_valid(global_unix_socket_handler) ? true : false; + return is_unix_socket_handler_valid(&global_unix_socket_handler) ? true : false; } void obs_module_unload(void) { diff --git a/src/socket.c b/src/socket.c index 8e2f8fd..71150a5 100644 --- a/src/socket.c +++ b/src/socket.c @@ -2,6 +2,7 @@ // standard library includes #include +#include // unix includes #include @@ -122,6 +123,7 @@ void init_unix_socket_handler(UnixSocketHandler *handler) { handler->socket_descriptor = socket(AF_UNIX, SOCK_SEQPACKET, 0); if (handler->socket_descriptor == -1) { handler->flags = 0xFFFFFFFFFFFFFFFF; + fprintf(stderr, "ERROR: unix-socket-control: Failed to create socket!\n"); return; } @@ -130,6 +132,7 @@ void init_unix_socket_handler(UnixSocketHandler *handler) { close(handler->socket_descriptor); handler->socket_descriptor = -1; handler->flags = 0xFFFFFFFFFFFFFFFF; + fprintf(stderr, "ERROR: unix-socket-control: Failed to set socket non-blocking!\n"); return; } @@ -145,6 +148,7 @@ void init_unix_socket_handler(UnixSocketHandler *handler) { close(handler->socket_descriptor); handler->socket_descriptor = -1; handler->flags = 0xFFFFFFFFFFFFFFFF; + fprintf(stderr, "ERROR: unix-socket-control: Failed to bind socket to filename!\n"); return; } @@ -154,6 +158,7 @@ void init_unix_socket_handler(UnixSocketHandler *handler) { handler->socket_descriptor = -1; unlink(handler->socket_filename); handler->flags = 0xFFFFFFFFFFFFFFFF; + fprintf(stderr, "ERROR: unix-socket-control: Failed to set socket listen!\n"); return; } @@ -165,6 +170,7 @@ void init_unix_socket_handler(UnixSocketHandler *handler) { handler->socket_descriptor = -1; unlink(handler->socket_filename); handler->flags = 0xFFFFFFFFFFFFFFFF; + fprintf(stderr, "ERROR: unix-socket-control: Failed to init mutex!\n"); return; } @@ -178,6 +184,7 @@ void init_unix_socket_handler(UnixSocketHandler *handler) { unlink(handler->socket_filename); mtx_destroy(handler->mutex); handler->flags = 0xFFFFFFFFFFFFFFFF; + fprintf(stderr, "ERROR: unix-socket-control: Failed to init thread!\n"); return; } @@ -211,6 +218,6 @@ void cleanup_unix_socket_handler(UnixSocketHandler *handler) { handler->flags = 0xFFFFFFFFFFFFFFFF; } -int is_unix_socket_handler_valid(UnixSocketHandler handler) { - return handler.flags == 0xFFFFFFFFFFFFFFFF ? 0 : 1; +int is_unix_socket_handler_valid(const UnixSocketHandler *handler) { + return handler->flags == 0xFFFFFFFFFFFFFFFF ? 0 : 1; } diff --git a/src/socket.h b/src/socket.h index d756119..72d4fb2 100644 --- a/src/socket.h +++ b/src/socket.h @@ -31,6 +31,6 @@ typedef struct UnixSocketHandler { void init_unix_socket_handler(UnixSocketHandler *handler); void cleanup_unix_socket_handler(UnixSocketHandler *handler); -int is_unix_socket_handler_valid(UnixSocketHandler handler); +int is_unix_socket_handler_valid(const UnixSocketHandler *handler); #endif