+ for (;;)
+ {
+ register int pid;
+ auto int lotherend;
+ extern int RefuseLA;
+
+ /* see if we are rejecting connections */
+ while ((la = getla()) > RefuseLA)
+ {
+ setproctitle("rejecting connections: load average: %.2f", (double)la);
+ sleep(5);
+ }
+
+ /* wait for a connection */
+ setproctitle("accepting connections");
+ do
+ {
+ errno = 0;
+ lotherend = sizeof RealHostAddr;
+ t = accept(DaemonSocket,
+ (struct sockaddr *)&RealHostAddr, &lotherend);
+ } while (t < 0 && errno == EINTR);
+ if (t < 0)
+ {
+ syserr("getrequests: accept");
+ sleep(5);
+ continue;
+ }
+
+ /*
+ ** Create a subprocess to process the mail.
+ */
+
+ if (tTd(15, 2))
+ printf("getrequests: forking (fd = %d)\n", t);
+
+ pid = fork();
+ if (pid < 0)
+ {
+ syserr("daemon: cannot fork");
+ sleep(10);
+ (void) close(t);
+ continue;
+ }
+
+ if (pid == 0)
+ {
+ extern struct hostent *gethostbyaddr();
+ register struct hostent *hp;
+ char buf[MAXNAME];
+
+ /*
+ ** CHILD -- return to caller.
+ ** Collect verified idea of sending host.
+ ** Verify calling user id if possible here.
+ */
+
+ (void) signal(SIGCHLD, SIG_DFL);
+
+ /* determine host name */
+ hp = gethostbyaddr((char *) &RealHostAddr.sin_addr, sizeof RealHostAddr.sin_addr, AF_INET);
+ if (hp != NULL)
+ (void) strcpy(buf, hp->h_name);
+ else
+ {
+ extern char *inet_ntoa();
+
+ /* produce a dotted quad */
+ (void) sprintf(buf, "[%s]",
+ inet_ntoa(RealHostAddr.sin_addr));
+ }
+
+ /* should we check for illegal connection here? XXX */
+
+ RealHostName = newstr(buf);
+
+ (void) close(DaemonSocket);
+ InChannel = fdopen(t, "r");
+ OutChannel = fdopen(dup(t), "w");
+ if (tTd(15, 2))
+ printf("getreq: returning\n");
+# ifdef LOG
+ if (LogLevel > 11)
+ syslog(LOG_DEBUG, "connected, pid=%d", getpid());
+# endif LOG
+ return;
+ }