From ffb655126a7588ab9e1f56579ea2223f6f04c2ee Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 6 Apr 2018 23:49:05 +0200 Subject: Create init socket after reaching boot target Filesystem might not be available before then. Signed-off-by: David Oberhollenzer --- initd/main.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'initd') diff --git a/initd/main.c b/initd/main.c index 5f85641..49bbee7 100644 --- a/initd/main.c +++ b/initd/main.c @@ -196,7 +196,7 @@ static void handle_tellinit(int ti_sock) int main(void) { - int ti_sock, sfd, ret; + int ti_sock = -1, sfd, ret, count; struct pollfd pfd[2]; sigset_t mask; @@ -225,32 +225,37 @@ int main(void) return EXIT_FAILURE; } - ti_sock = mksock(); - if (ti_sock == -1) - return EXIT_FAILURE; - if (setup_tty()) return EXIT_FAILURE; memset(pfd, 0, sizeof(pfd)); pfd[0].fd = sfd; - pfd[1].fd = ti_sock; - pfd[0].events = pfd[1].events = POLLIN; + pfd[0].events = POLLIN; + count = 1; for (;;) { if (!svclist_have_singleshot() && target != runlevel) { start_runlevel(target); runlevel = target; + + if (target == TGT_BOOT && ti_sock == -1) { + ti_sock = mksock(); + if (ti_sock != -1) { + pfd[1].fd = ti_sock; + pfd[1].events = POLLIN; + count = 2; + } + } continue; } - ret = poll(pfd, sizeof(pfd) / sizeof(pfd[0]), -1); + ret = poll(pfd, count, -1); if (ret > 0) { if (pfd[0].revents & POLLIN) handle_signal(sfd); - if (pfd[1].revents & POLLIN) + if (ti_sock != -1 && pfd[1].revents & POLLIN) handle_tellinit(ti_sock); } } -- cgit v1.2.3