aboutsummaryrefslogtreecommitdiff
path: root/initd
diff options
context:
space:
mode:
authorDavid Oberhollenzer <goliath@infraroot.at>2020-05-07 22:04:42 +0200
committerDavid Oberhollenzer <goliath@infraroot.at>2020-05-07 22:08:37 +0200
commit13aa3840cc94ce37ef1e63c093c0f71ac84e90fd (patch)
treedb60e6ff38fd7477f5b76cdabcd9277357184b6b /initd
parentef0dd7cbe779b879f61bdbaf23a01bc1fb643243 (diff)
Temporarily remove initsock handling code
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'initd')
-rw-r--r--initd/Makemodule.am2
-rw-r--r--initd/init.h15
-rw-r--r--initd/initsock.c88
-rw-r--r--initd/main.c51
-rw-r--r--initd/supervisor.c89
5 files changed, 1 insertions, 244 deletions
diff --git a/initd/Makemodule.am b/initd/Makemodule.am
index c68e098..9491fa9 100644
--- a/initd/Makemodule.am
+++ b/initd/Makemodule.am
@@ -1,5 +1,5 @@
init_SOURCES = initd/main.c initd/init.h initd/runsvc.c
-init_SOURCES += initd/status.c initd/supervisor.c initd/initsock.c
+init_SOURCES += initd/status.c initd/supervisor.c
init_CPPFLAGS = $(AM_CPPFLAGS)
init_CFLAGS = $(AM_CFLAGS)
init_LDFLAGS = $(AM_LDFLAGS)
diff --git a/initd/init.h b/initd/init.h
index 0196861..67d5fc4 100644
--- a/initd/init.h
+++ b/initd/init.h
@@ -20,7 +20,6 @@
#include <stdbool.h>
#include <signal.h>
-#include "initsock.h"
#include "service.h"
#include "config.h"
@@ -70,18 +69,4 @@ void supervisor_init(void);
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);
-
-/********** initsock.c **********/
-
-int init_socket_create(void);
-
-int init_socket_send_status(int fd, const void *dest_addr, size_t addrlen,
- E_SERVICE_STATE state, service_t *svc);
-
#endif /* INIT_H */
diff --git a/initd/initsock.c b/initd/initsock.c
deleted file mode 100644
index 7016ef1..0000000
--- a/initd/initsock.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/* SPDX-License-Identifier: ISC */
-#include "init.h"
-
-static int send_retry(int fd, const void *dst, size_t addrlen,
- const void *buffer, size_t size)
-{
- ssize_t ret;
-retry:
- ret = sendto(fd, buffer, size, MSG_NOSIGNAL, dst, addrlen);
- if (ret < 0 && errno == EINTR)
- goto retry;
-
- if (ret < 0 || (size_t)ret < size)
- return -1;
-
- return 0;
-}
-
-static int send_string(int fd, const void *dst, size_t addrlen,
- const char *str)
-{
- size_t len = strlen(str);
- uint16_t raw;
-
- if (len > 0xFFFF)
- return -1;
-
- raw = htobe16(len);
- if (send_retry(fd, dst, addrlen, &raw, 2))
- return -1;
-
- return len > 0 ? send_retry(fd, dst, addrlen, str, len) : 0;
-}
-
-int init_socket_create(void)
-{
- struct sockaddr_un un;
- int fd;
-
- fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
- if (fd < 0) {
- perror("socket");
- return -1;
- }
-
- memset(&un, 0, sizeof(un));
- un.sun_family = AF_UNIX;
-
- strcpy(un.sun_path, INIT_SOCK_PATH);
- unlink(INIT_SOCK_PATH);
-
- if (bind(fd, (struct sockaddr *)&un, sizeof(un))) {
- perror("bind: " INIT_SOCK_PATH);
- close(fd);
- unlink(INIT_SOCK_PATH);
- return -1;
- }
-
- return fd;
-}
-
-int init_socket_send_status(int fd, const void *dest_addr, size_t addrlen,
- E_SERVICE_STATE state, service_t *svc)
-{
- init_response_status_t info;
-
- memset(&info, 0, sizeof(info));
-
- if (svc == NULL || state == ESS_NONE) {
- info.state = ESS_NONE;
- info.id = -1;
- } else {
- info.state = state;
- info.exit_status = svc->status & 0xFF;
- info.id = htobe32(svc->id);
- }
-
- if (send_retry(fd, dest_addr, addrlen, &info, sizeof(info)))
- return -1;
-
- if (svc != NULL && state != ESS_NONE) {
- if (send_string(fd, dest_addr, addrlen, svc->fname))
- return -1;
- if (send_string(fd, dest_addr, addrlen, svc->name))
- return -1;
- }
- return 0;
-}
diff --git a/initd/main.c b/initd/main.c
index e59d809..5a4c37a 100644
--- a/initd/main.c
+++ b/initd/main.c
@@ -2,7 +2,6 @@
#include "init.h"
static int sigfd = -1;
-static int sockfd = -1;
static void handle_signal(void)
{
@@ -33,46 +32,6 @@ static void handle_signal(void)
case SIGHUP:
break;
case SIGUSR1:
- if (sockfd >= 0) {
- close(sockfd);
- unlink(INIT_SOCK_PATH);
- sockfd = -1;
- }
- sockfd = init_socket_create();
- break;
- }
-}
-
-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,
- (struct sockaddr *)&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,
- 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;
}
}
@@ -81,8 +40,6 @@ void target_completed(int target)
{
switch (target) {
case TGT_BOOT:
- if (sockfd < 0)
- sockfd = init_socket_create();
break;
case TGT_SHUTDOWN:
for (;;)
@@ -145,12 +102,6 @@ int main(void)
pfd[count].events = POLLIN;
++count;
- if (sockfd >= 0) {
- pfd[count].fd = sockfd;
- pfd[count].events = POLLIN;
- ++count;
- }
-
ret = poll(pfd, count, -1);
if (ret <= 0)
continue;
@@ -159,8 +110,6 @@ int main(void)
if (pfd[i].revents & POLLIN) {
if (pfd[i].fd == sigfd)
handle_signal();
- if (pfd[i].fd == sockfd)
- handle_request();
}
}
}
diff --git a/initd/supervisor.c b/initd/supervisor.c
index 8c33bf3..32a23f2 100644
--- a/initd/supervisor.c
+++ b/initd/supervisor.c
@@ -191,92 +191,3 @@ out:
target_completed(target);
return true;
}
-
-static int send_svc_list(int fd, const void *dst, size_t addrlen,
- 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;
-
- list = list->next;
- }
-
- return 0;
-}
-
-void supervisor_answer_status_request(int fd, const void *dst, size_t addrlen,
- E_SERVICE_STATE filter)
-{
- if (send_svc_list(fd, dst, addrlen, filter, ESS_RUNNING, running))
- return;
- if (send_svc_list(fd, dst, addrlen, filter, ESS_DONE, completed))
- return;
- if (send_svc_list(fd, dst, addrlen, filter, ESS_FAILED, failed))
- return;
- if (send_svc_list(fd, dst, addrlen, filter, ESS_ENQUEUED, queue))
- return;
- if (send_svc_list(fd, dst, addrlen, filter, ESS_ENQUEUED, terminated))
- return;
- init_socket_send_status(fd, dst, addrlen, ESS_NONE, NULL);
-}
-
-static service_t *remove_by_id(service_t **list, int id)
-{
- service_t *svc = *list, *prev = NULL;
-
- while (svc != NULL && svc->id != id) {
- prev = svc;
- svc = svc->next;
- }
-
- if (svc != NULL) {
- if (prev == NULL) {
- *list = svc->next;
- } else {
- prev->next = svc->next;
- }
- }
-
- return svc;
-}
-
-void supervisor_start(int id)
-{
- service_t *svc;
-
- svc = remove_by_id(&completed, id);
- if (svc != NULL)
- goto found;
-
- svc = remove_by_id(&failed, id);
- if (svc != NULL)
- goto found;
-
- return;
-found:
- svc->rspwn_count = 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);
- }
-}