diff options
author | David Oberhollenzer <goliath@infraroot.at> | 2019-03-28 14:15:39 +0100 |
---|---|---|
committer | David Oberhollenzer <goliath@infraroot.at> | 2019-03-28 15:32:10 +0100 |
commit | ba1270008021470b2e451bce8e75053e0a00f662 (patch) | |
tree | 1a33a447af83e276c7642b73f9c1bcd9fde9416b /initd | |
parent | 9e7478397a6f3c7bc38be52268e805d5b094eeb2 (diff) |
Add start/stop commands to init socket
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'initd')
-rw-r--r-- | initd/init.h | 5 | ||||
-rw-r--r-- | initd/main.c | 8 | ||||
-rw-r--r-- | initd/supervisor.c | 42 |
3 files changed, 55 insertions, 0 deletions
diff --git a/initd/init.h b/initd/init.h index 1d292d3..b98da98 100644 --- a/initd/init.h +++ b/initd/init.h @@ -9,6 +9,7 @@ #include <string.h> #include <stdlib.h> #include <unistd.h> +#include <endian.h> #include <stdio.h> #include <errno.h> #include <poll.h> @@ -70,6 +71,10 @@ bool supervisor_process_queues(void); void supervisor_answer_status_request(int fd, const void *dest_addr, size_t addrlen, E_SERVICE_STATE filter); +void supervisor_start(int id); + +void supervisor_stop(int id); + /********** signal_<platform>.c **********/ /* diff --git a/initd/main.c b/initd/main.c index 4eb4832..2b1a1cc 100644 --- a/initd/main.c +++ b/initd/main.c @@ -64,6 +64,14 @@ retry: supervisor_answer_status_request(sockfd, &addr, addrlen, rq.arg.status.filter); break; + case EIR_START: + rq.arg.startstop.id = be32toh(rq.arg.startstop.id); + supervisor_start(rq.arg.startstop.id); + break; + case EIR_STOP: + rq.arg.startstop.id = be32toh(rq.arg.startstop.id); + supervisor_stop(rq.arg.startstop.id); + break; } } diff --git a/initd/supervisor.c b/initd/supervisor.c index 871618a..53a2aec 100644 --- a/initd/supervisor.c +++ b/initd/supervisor.c @@ -38,6 +38,9 @@ static void handle_terminated_service(service_t *svc) if (target == TGT_REBOOT || target == TGT_SHUTDOWN) break; + if (svc->flags & SVC_FLAG_ADMIN_STOPPED) + break; + if (svc->rspwn_limit > 0) { svc->rspwn_limit -= 1; @@ -221,3 +224,42 @@ void supervisor_answer_status_request(int fd, const void *dst, size_t addrlen, return; init_socket_send_status(fd, dst, addrlen, ESS_NONE, NULL); } + +void supervisor_start(int id) +{ + service_t *svc; + + for (svc = completed; svc != NULL; svc = svc->next) { + if (svc->id == id) + goto found; + } + + for (svc = failed; svc != NULL; svc = svc->next) { + if (svc->id == id) + goto found; + } + return; +found: + if (svc->type == SVC_RESPAWN) + svc->rspwn_limit = 0; + + svc->flags &= ~SVC_FLAG_ADMIN_STOPPED; + svc->next = queue; + queue = svc; +} + +void supervisor_stop(int id) +{ + service_t *svc; + + for (svc = running; svc != NULL; svc = svc->next) { + if (svc->id == id) + break; + } + + if (svc != NULL) { + /* TODO: something more sophisticated? */ + svc->flags |= SVC_FLAG_ADMIN_STOPPED; + kill(svc->pid, SIGTERM); + } +} |