diff options
author | David Oberhollenzer <goliath@infraroot.at> | 2019-03-27 17:48:13 +0100 |
---|---|---|
committer | David Oberhollenzer <goliath@infraroot.at> | 2019-03-27 17:48:32 +0100 |
commit | d16d26018126d381954110e8cdb788650eb41d9e (patch) | |
tree | d398bc1c0dbbde87d22f0eb686e4bf6f90056e73 | |
parent | affe9e4b8802ccb2d9749300327969dcf4222bc1 (diff) |
Add filter argument to status request
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
-rw-r--r-- | cmd/service/status.c | 2 | ||||
-rw-r--r-- | initd/init.h | 2 | ||||
-rw-r--r-- | initd/main.c | 3 | ||||
-rw-r--r-- | initd/supervisor.c | 19 | ||||
-rw-r--r-- | lib/include/initsock.h | 10 | ||||
-rw-r--r-- | lib/init/init_socket_send_request.c | 14 |
6 files changed, 38 insertions, 12 deletions
diff --git a/cmd/service/status.c b/cmd/service/status.c index be5c930..abeeb15 100644 --- a/cmd/service/status.c +++ b/cmd/service/status.c @@ -53,7 +53,7 @@ static int cmd_status(int argc, char **argv) return EXIT_FAILURE; } - if (init_socket_send_request(fd, EIR_STATUS)) + if (init_socket_send_request(fd, EIR_STATUS, ESS_NONE)) goto out; is_tty = (isatty(STDOUT_FILENO) == 1); diff --git a/initd/init.h b/initd/init.h index 39e63a4..1d292d3 100644 --- a/initd/init.h +++ b/initd/init.h @@ -68,7 +68,7 @@ void supervisor_init(void); bool supervisor_process_queues(void); void supervisor_answer_status_request(int fd, const void *dest_addr, - size_t addrlen); + size_t addrlen, E_SERVICE_STATE filter); /********** signal_<platform>.c **********/ diff --git a/initd/main.c b/initd/main.c index 3a824e4..4eb4832 100644 --- a/initd/main.c +++ b/initd/main.c @@ -61,7 +61,8 @@ retry: switch (rq.rq) { case EIR_STATUS: - supervisor_answer_status_request(sockfd, &addr, addrlen); + supervisor_answer_status_request(sockfd, &addr, addrlen, + rq.arg.status.filter); break; } } diff --git a/initd/supervisor.c b/initd/supervisor.c index 451ad93..4f7ddc9 100644 --- a/initd/supervisor.c +++ b/initd/supervisor.c @@ -186,8 +186,12 @@ out: } 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) { if (init_socket_send_status(fd, dst, addrlen, state, list)) return -1; @@ -198,17 +202,18 @@ static int send_svc_list(int fd, const void *dst, size_t addrlen, 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; - if (send_svc_list(fd, dst, addrlen, ESS_DONE, completed)) + if (send_svc_list(fd, dst, addrlen, filter, ESS_DONE, completed)) return; - if (send_svc_list(fd, dst, addrlen, ESS_FAILED, failed)) + if (send_svc_list(fd, dst, addrlen, filter, ESS_FAILED, failed)) return; - if (send_svc_list(fd, dst, addrlen, ESS_ENQUEUED, queue)) + if (send_svc_list(fd, dst, addrlen, filter, ESS_ENQUEUED, queue)) return; - if (send_svc_list(fd, dst, addrlen, ESS_ENQUEUED, terminated)) + if (send_svc_list(fd, dst, addrlen, filter, ESS_ENQUEUED, terminated)) return; init_socket_send_status(fd, dst, addrlen, ESS_NONE, NULL); } diff --git a/lib/include/initsock.h b/lib/include/initsock.h index 76b2924..55321db 100644 --- a/lib/include/initsock.h +++ b/lib/include/initsock.h @@ -23,6 +23,14 @@ typedef enum { typedef struct { uint8_t rq; + uint8_t padd[3]; + + union { + struct { + uint8_t filter; + uint8_t padd[3]; + } status; + } arg; } init_request_t; typedef struct { @@ -36,7 +44,7 @@ int init_socket_create(void); 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, E_SERVICE_STATE state, service_t *svc); diff --git a/lib/init/init_socket_send_request.c b/lib/init/init_socket_send_request.c index dd88856..e9c7cb9 100644 --- a/lib/init/init_socket_send_request.c +++ b/lib/init/init_socket_send_request.c @@ -1,19 +1,31 @@ /* SPDX-License-Identifier: ISC */ #include <unistd.h> #include <string.h> +#include <stdarg.h> #include <stdio.h> #include <errno.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; ssize_t ret; + va_list ap; memset(&request, 0, sizeof(request)); 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: ret = write(fd, &request, sizeof(request)); |