diff options
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -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) |