mirror of
https://github.com/pygos/init.git
synced 2024-11-22 19:19:47 +01:00
initd: implement handling of socket requests
Actually process requests and send an answer to status inquiries. Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
23b713c3b5
commit
40ad83dc6a
3 changed files with 50 additions and 0 deletions
|
@ -67,6 +67,9 @@ void supervisor_init(void);
|
||||||
|
|
||||||
bool supervisor_process_queues(void);
|
bool supervisor_process_queues(void);
|
||||||
|
|
||||||
|
void supervisor_answer_status_request(int fd, const void *dest_addr,
|
||||||
|
size_t addrlen);
|
||||||
|
|
||||||
/********** signal_<platform>.c **********/
|
/********** signal_<platform>.c **********/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
21
initd/main.c
21
initd/main.c
|
@ -43,6 +43,27 @@ static void handle_signal(void)
|
||||||
|
|
||||||
static void handle_request(void)
|
static void handle_request(void)
|
||||||
{
|
{
|
||||||
|
struct sockaddr_un addr;
|
||||||
|
init_request_t rq;
|
||||||
|
socklen_t addrlen;
|
||||||
|
ssize_t ret;
|
||||||
|
retry:
|
||||||
|
memset(&rq, 0, sizeof(rq));
|
||||||
|
addrlen = sizeof(addr);
|
||||||
|
ret = recvfrom(sockfd, &rq, sizeof(rq), MSG_DONTWAIT | MSG_TRUNC,
|
||||||
|
&addr, &addrlen);
|
||||||
|
|
||||||
|
if (ret < 0 && errno == EINTR)
|
||||||
|
goto retry;
|
||||||
|
|
||||||
|
if ((size_t)ret < sizeof(rq))
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (rq.rq) {
|
||||||
|
case EIR_STATUS:
|
||||||
|
supervisor_answer_status_request(sockfd, &addr, addrlen);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void target_completed(int target)
|
void target_completed(int target)
|
||||||
|
|
|
@ -167,3 +167,29 @@ bool supervisor_process_queues(void)
|
||||||
target_completed(target);
|
target_completed(target);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int send_svc_list(int fd, const void *dst, size_t addrlen,
|
||||||
|
E_SERVICE_STATE state, service_t *list)
|
||||||
|
{
|
||||||
|
while (list != NULL) {
|
||||||
|
if (init_socket_send_status(fd, dst, addrlen, state, list))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void supervisor_answer_status_request(int fd, const void *dst, size_t addrlen)
|
||||||
|
{
|
||||||
|
if (send_svc_list(fd, dst, addrlen, ESS_RUNNING, running))
|
||||||
|
return;
|
||||||
|
if (send_svc_list(fd, dst, addrlen, ESS_EXITED, completed))
|
||||||
|
return;
|
||||||
|
if (send_svc_list(fd, dst, addrlen, ESS_ENQUEUED, queue))
|
||||||
|
return;
|
||||||
|
if (send_svc_list(fd, dst, addrlen, ESS_ENQUEUED, terminated))
|
||||||
|
return;
|
||||||
|
init_socket_send_status(fd, dst, addrlen, ESS_NONE, NULL);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue