summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/utils.c b/utils.c
index f2ca2a7..6178d3b 100644
--- a/utils.c
+++ b/utils.c
@@ -66,7 +66,27 @@ int init_command_socket(const char* path)
int connect_command_socket(const char* path)
{
- return -1;
+ int fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if(fd < 0) {
+ log_printf(ERROR, "unable to open socket: %s", strerror(errno));
+ return -1;
+ }
+
+ struct sockaddr_un remote;
+ remote.sun_family = AF_UNIX;
+ if(sizeof(remote.sun_path) <= strlen(path)) {
+ log_printf(ERROR, "socket path is to long (max %d)", sizeof(remote.sun_path)-1);
+ return -1;
+ }
+ strcpy(remote.sun_path, path);
+ int len = SUN_LEN(&remote);
+ int ret = connect(fd, (struct sockaddr*)&remote, len);
+ if(ret) {
+ log_printf(ERROR, "unable to connect to '%s': %s", remote.sun_path, strerror(errno));
+ return -1;
+ }
+
+ return fd;
}
int send_string(int fd, const char* string)