|
|
@ -430,6 +430,29 @@ static client_instance_t *client_by_id(conn_instance_t *ci, int id) |
|
|
|
return client; |
|
|
|
return client; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void send_fd(int fd, int sockd) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
struct cmsghdr cmptr; |
|
|
|
|
|
|
|
struct iovec iov[1]; |
|
|
|
|
|
|
|
struct msghdr msg; |
|
|
|
|
|
|
|
char buf[2]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
memset(&cmptr, 0, sizeof(struct cmsghdr)); |
|
|
|
|
|
|
|
iov[0].iov_base = buf; |
|
|
|
|
|
|
|
iov[0].iov_len = 2; |
|
|
|
|
|
|
|
msg.msg_iov = iov; |
|
|
|
|
|
|
|
msg.msg_iovlen = 1; |
|
|
|
|
|
|
|
msg.msg_name = NULL; |
|
|
|
|
|
|
|
msg.msg_namelen = 0; |
|
|
|
|
|
|
|
cmptr.cmsg_level = SOL_SOCKET; |
|
|
|
|
|
|
|
cmptr.cmsg_type = SCM_RIGHTS; |
|
|
|
|
|
|
|
cmptr.cmsg_len = CMSG_LEN(sizeof(int)); |
|
|
|
|
|
|
|
*(int *)CMSG_DATA(&cmptr) = fd; |
|
|
|
|
|
|
|
buf[1] = 0; |
|
|
|
|
|
|
|
buf[0] = 0; |
|
|
|
|
|
|
|
send_unix_data(sockd, &msg, sizeof(struct msghdr)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int connector_loop(proc_instance_t *pi, conn_instance_t *ci) |
|
|
|
static int connector_loop(proc_instance_t *pi, conn_instance_t *ci) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int sockd, client_id, ret = 0, selret; |
|
|
|
int sockd, client_id, ret = 0, selret; |
|
|
@ -488,6 +511,10 @@ retry: |
|
|
|
LOGINFO("Connector dropped client id: %d", client_id); |
|
|
|
LOGINFO("Connector dropped client id: %d", client_id); |
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!strncasecmp(buf, "getfd", 5)) { |
|
|
|
|
|
|
|
send_fd(ci->serverfd, sockd); |
|
|
|
|
|
|
|
goto retry; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Anything else should be a json message to send to a client */ |
|
|
|
/* Anything else should be a json message to send to a client */ |
|
|
|
json_msg = json_loads(buf, 0, NULL); |
|
|
|
json_msg = json_loads(buf, 0, NULL); |
|
|
@ -504,6 +531,7 @@ retry: |
|
|
|
realloc_strcat(&buf, "\n"); |
|
|
|
realloc_strcat(&buf, "\n"); |
|
|
|
send_client(ci, client_id, buf); |
|
|
|
send_client(ci, client_id, buf); |
|
|
|
json_decref(json_msg); |
|
|
|
json_decref(json_msg); |
|
|
|
|
|
|
|
buf = NULL; |
|
|
|
|
|
|
|
|
|
|
|
goto retry; |
|
|
|
goto retry; |
|
|
|
out: |
|
|
|
out: |
|
|
|