1
0
Fork 0
mirror of https://github.com/pygos/init.git synced 2024-05-19 20:26:14 +02:00

Add filter argument to status request

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-03-27 17:48:13 +01:00
parent affe9e4b88
commit d16d260181
6 changed files with 38 additions and 12 deletions

View file

@ -53,7 +53,7 @@ static int cmd_status(int argc, char **argv)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (init_socket_send_request(fd, EIR_STATUS)) if (init_socket_send_request(fd, EIR_STATUS, ESS_NONE))
goto out; goto out;
is_tty = (isatty(STDOUT_FILENO) == 1); is_tty = (isatty(STDOUT_FILENO) == 1);

View file

@ -68,7 +68,7 @@ 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, void supervisor_answer_status_request(int fd, const void *dest_addr,
size_t addrlen); size_t addrlen, E_SERVICE_STATE filter);
/********** signal_<platform>.c **********/ /********** signal_<platform>.c **********/

View file

@ -61,7 +61,8 @@ retry:
switch (rq.rq) { switch (rq.rq) {
case EIR_STATUS: case EIR_STATUS:
supervisor_answer_status_request(sockfd, &addr, addrlen); supervisor_answer_status_request(sockfd, &addr, addrlen,
rq.arg.status.filter);
break; break;
} }
} }

View file

@ -186,8 +186,12 @@ out:
} }
static int send_svc_list(int fd, const void *dst, size_t addrlen, static int send_svc_list(int fd, const void *dst, size_t addrlen,
E_SERVICE_STATE state, service_t *list) E_SERVICE_STATE filter, E_SERVICE_STATE state,
service_t *list)
{ {
if (filter != ESS_NONE && filter != state)
return 0;
while (list != NULL) { while (list != NULL) {
if (init_socket_send_status(fd, dst, addrlen, state, list)) if (init_socket_send_status(fd, dst, addrlen, state, list))
return -1; return -1;
@ -198,17 +202,18 @@ static int send_svc_list(int fd, const void *dst, size_t addrlen,
return 0; return 0;
} }
void supervisor_answer_status_request(int fd, const void *dst, size_t addrlen) void supervisor_answer_status_request(int fd, const void *dst, size_t addrlen,
E_SERVICE_STATE filter)
{ {
if (send_svc_list(fd, dst, addrlen, ESS_RUNNING, running)) if (send_svc_list(fd, dst, addrlen, filter, ESS_RUNNING, running))
return; return;
if (send_svc_list(fd, dst, addrlen, ESS_DONE, completed)) if (send_svc_list(fd, dst, addrlen, filter, ESS_DONE, completed))
return; return;
if (send_svc_list(fd, dst, addrlen, ESS_FAILED, failed)) if (send_svc_list(fd, dst, addrlen, filter, ESS_FAILED, failed))
return; return;
if (send_svc_list(fd, dst, addrlen, ESS_ENQUEUED, queue)) if (send_svc_list(fd, dst, addrlen, filter, ESS_ENQUEUED, queue))
return; return;
if (send_svc_list(fd, dst, addrlen, ESS_ENQUEUED, terminated)) if (send_svc_list(fd, dst, addrlen, filter, ESS_ENQUEUED, terminated))
return; return;
init_socket_send_status(fd, dst, addrlen, ESS_NONE, NULL); init_socket_send_status(fd, dst, addrlen, ESS_NONE, NULL);
} }

View file

@ -23,6 +23,14 @@ typedef enum {
typedef struct { typedef struct {
uint8_t rq; uint8_t rq;
uint8_t padd[3];
union {
struct {
uint8_t filter;
uint8_t padd[3];
} status;
} arg;
} init_request_t; } init_request_t;
typedef struct { typedef struct {
@ -36,7 +44,7 @@ int init_socket_create(void);
int init_socket_open(const char *tmppath); int init_socket_open(const char *tmppath);
int init_socket_send_request(int fd, E_INIT_REQUEST rq); int init_socket_send_request(int fd, E_INIT_REQUEST rq, ...);
int init_socket_send_status(int fd, const void *dest_addr, size_t addrlen, int init_socket_send_status(int fd, const void *dest_addr, size_t addrlen,
E_SERVICE_STATE state, service_t *svc); E_SERVICE_STATE state, service_t *svc);

View file

@ -1,19 +1,31 @@
/* SPDX-License-Identifier: ISC */ /* SPDX-License-Identifier: ISC */
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include "initsock.h" #include "initsock.h"
int init_socket_send_request(int fd, E_INIT_REQUEST rq) int init_socket_send_request(int fd, E_INIT_REQUEST rq, ...)
{ {
init_request_t request; init_request_t request;
ssize_t ret; ssize_t ret;
va_list ap;
memset(&request, 0, sizeof(request)); memset(&request, 0, sizeof(request));
request.rq = rq; request.rq = rq;
va_start(ap, rq);
switch (rq) {
case EIR_STATUS:
request.arg.status.filter = va_arg(ap, E_SERVICE_STATE);
break;
default:
break;
}
va_end(ap);
retry: retry:
ret = write(fd, &request, sizeof(request)); ret = write(fd, &request, sizeof(request));