summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/monitor/request-handler.c64
1 files changed, 56 insertions, 8 deletions
diff --git a/src/monitor/request-handler.c b/src/monitor/request-handler.c
index 538892b..2251beb 100644
--- a/src/monitor/request-handler.c
+++ b/src/monitor/request-handler.c
@@ -1079,15 +1079,17 @@ static int create_request_client(int socket_fd)
return 0;
}
-static const char *server_socket_path = "/run/.pass.socket";
+static const char *server_uds_path = "/run/.pass.socket";
static int request_server_func(void *ctx, void **result)
{
struct sockaddr_un address;
+ struct sockaddr_in ip_address;
struct timeval wait;
int opt = true;
int server_socket;
- int addrlen;
+ int tcp_socket;
+ int addrlen, ip_addrlen;
int ret;
fd_set fds;
@@ -1106,31 +1108,62 @@ static int request_server_func(void *ctx, void **result)
if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR,
(char *)&opt, sizeof(opt)) < 0) {
_E("Failed to setsockopt");
- goto error_out_close;
+ goto error_out_close_server_socket;
}
bzero(&address, sizeof(address));
address.sun_family = AF_UNIX;
- strcpy(address.sun_path, server_socket_path);
+ strcpy(address.sun_path, server_uds_path);
- if (!access(server_socket_path, F_OK))
- unlink(server_socket_path);
+ if (!access(server_uds_path, F_OK))
+ unlink(server_uds_path);
if (bind(server_socket, (struct sockaddr *)&address, sizeof(address)) < 0) {
_E("Failed to bind");
- goto error_out_close;
+ goto error_out_close_server_socket;
}
if (listen(server_socket, PENDING_MAX) < 0) {
_E("Failed to begin listenning");
- goto error_out_close;
+ goto error_out_close_server_socket;
}
addrlen = sizeof(address);
+ /* initialize TCP socket */
+ tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
+ if (tcp_socket < 0) {
+ _E("Failed to initialize TCP socket");
+ goto error_out_close_server_socket;
+ }
+
+ if (setsockopt(tcp_socket, SOL_SOCKET, SO_REUSEADDR,
+ (char *)&opt, sizeof(opt)) < 0) {
+ _E("Failed to setsockopt for TCP socket");
+ goto error_out_close;
+ }
+
+ bzero(&ip_address, sizeof(ip_address));
+ ip_address.sin_family = AF_INET;
+ ip_address.sin_addr.s_addr = INADDR_ANY;
+ ip_address.sin_port = htons(REQUEST_SERVER_PORT);
+
+ if (bind(tcp_socket, (struct sockaddr *)&ip_address, sizeof(ip_address)) < 0) {
+ _E("Failed to bind for TCP socket");
+ goto error_out_close;
+ }
+
+ if (listen(tcp_socket, PENDING_MAX) < 0) {
+ _E("Failed to begin listenning for TCP socket");
+ goto error_out_close;
+ }
+
+ ip_addrlen = sizeof(address);
+
while (g_request_server_run) {
FD_ZERO(&fds);
FD_SET(server_socket, &fds);
+ FD_SET(tcp_socket, &fds);
wait.tv_sec = 1;
wait.tv_usec = 0;
@@ -1152,13 +1185,28 @@ static int request_server_func(void *ctx, void **result)
create_request_client(new_socket);
}
+
+ if (FD_ISSET(tcp_socket, &fds)) {
+ int new_socket = accept(tcp_socket, (struct sockaddr *)&ip_address,
+ (socklen_t *)&ip_addrlen);
+
+ if (new_socket < 0) {
+ _E("Failed to accept");
+ goto error_out_close;
+ }
+
+ create_request_client(new_socket);
+ }
}
+ close(tcp_socket);
close(server_socket);
return THREAD_RETURN_DONE;
error_out_close:
+ close(tcp_socket);
+error_out_close_server_socket:
close(server_socket);
error_out: