- if (options & SO_DEBUG)
- if (setsockopt(s, SOL_SOCKET, SO_DEBUG, 0, 0) < 0)
- perror("telnetd: setsockopt (SO_DEBUG)");
- if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, 0, 0) < 0)
- perror("telnetd: setsockopt (SO_KEEPALIVE)");
- while (bind(s, (caddr_t)&sin, sizeof (sin), 0) < 0) {
- perror("telnetd: bind");
- sleep(5);
- }
- sigset(SIGCHLD, reapchild);
- listen(s, 10);
- for (;;) {
- int s2;
-
- s2 = accept(s, (caddr_t)0, 0, 0);
- if (s2 < 0) {
- if (errno == EINTR)
- continue;
- perror("telnetd: accept");
- sleep(1);
- continue;
- }
- if ((pid = fork()) < 0)
- printf("Out of processes\n");
- else if (pid == 0) {
- signal(SIGCHLD, SIG_IGN);
- doit(s2);
- }
- close(s2);
- }
- /*NOTREACHED*/
-}
-
-reapchild()
-{
- union wait status;
-
- while (wait3(&status, WNOHANG, 0) > 0)
- ;