diff options
author | David Oberhollenzer <goliath@infraroot.at> | 2019-03-17 18:33:12 +0100 |
---|---|---|
committer | David Oberhollenzer <goliath@infraroot.at> | 2019-03-18 14:15:58 +0100 |
commit | 08f72865b29598faa5074ef21f583508f94dea98 (patch) | |
tree | f816f3cbdaefc2c45fbaa5827c2e5bd4cfebe1dd | |
parent | c78bbd2f731ae44c7d2588b9bb3d19005f192fc6 (diff) |
Add init socket to initd
Create a socket if boot target is done. Close and reopen socket
if SIGUSR1 is received.
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
-rw-r--r-- | initd/init.h | 2 | ||||
-rw-r--r-- | initd/main.c | 43 |
2 files changed, 38 insertions, 7 deletions
diff --git a/initd/init.h b/initd/init.h index 42ef193..ce0bb1f 100644 --- a/initd/init.h +++ b/initd/init.h @@ -5,6 +5,7 @@ #include <sys/types.h> #include <sys/wait.h> #include <sys/socket.h> +#include <sys/un.h> #include <string.h> #include <stdlib.h> #include <unistd.h> @@ -17,6 +18,7 @@ #include <sys/reboot.h> #include <signal.h> +#include "initsock.h" #include "service.h" #include "util.h" diff --git a/initd/main.c b/initd/main.c index 6cd0500..db44dc5 100644 --- a/initd/main.c +++ b/initd/main.c @@ -2,6 +2,7 @@ #include "init.h" static int sigfd = -1; +static int sockfd = -1; static void handle_signal(void) { @@ -29,13 +30,27 @@ static void handle_signal(void) case SIGINT: supervisor_set_target(TGT_REBOOT); break; + case SIGUSR1: + if (sockfd >= 0) { + close(sockfd); + unlink(INIT_SOCK_PATH); + sockfd = -1; + } + sockfd = init_socket_create(); + break; } } +static void handle_request(void) +{ +} + void target_completed(int target) { switch (target) { case TGT_BOOT: + if (sockfd < 0) + sockfd = init_socket_create(); break; case TGT_SHUTDOWN: for (;;) @@ -50,7 +65,7 @@ void target_completed(int target) int main(void) { - int ret, count; + int i, ret, count; struct pollfd pfd[2]; if (getpid() != 1) { @@ -69,15 +84,29 @@ int main(void) ; memset(pfd, 0, sizeof(pfd)); - pfd[0].fd = sigfd; - pfd[0].events = POLLIN; - count = 1; + count = 0; + + pfd[count].fd = sigfd; + 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; - if (ret > 0) { - if (pfd[0].revents & POLLIN) - handle_signal(); + for (i = 0; i < count; ++i) { + if (pfd[i].revents & POLLIN) { + if (pfd[i].fd == sigfd) + handle_signal(); + if (pfd[i].fd == sockfd) + handle_request(); + } } } |