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); } }