|
|
1.1 ! root 1: #ifndef lint ! 2: static char *sccsid = "@(#)main.c 1.8 (Berkeley) 7/17/87"; ! 3: #endif ! 4: ! 5: /* ! 6: * Network News Transfer Protocol server ! 7: * ! 8: * Phil Lapsley ! 9: * University of California, Berkeley ! 10: * (Internet: [email protected]; UUCP: ...!ucbvax!phil) ! 11: */ ! 12: ! 13: #include "common.h" ! 14: #include <sys/socket.h> ! 15: #include <netinet/in.h> ! 16: #include <netdb.h> ! 17: #include <signal.h> ! 18: ! 19: main() ! 20: { ! 21: ! 22: #ifdef ALONE /* If no inetd */ ! 23: ! 24: int sockt, client, length; ! 25: struct sockaddr_in from; ! 26: extern int reaper(); ! 27: ! 28: disassoc(); ! 29: ! 30: /* fd 0-2 should be open and point to / now. */ ! 31: ! 32: #ifdef SYSLOG ! 33: #ifdef BSD_42 ! 34: openlog("nntpd", LOG_PID); /* fd 3 */ ! 35: #else ! 36: openlog("nntpd", LOG_PID, SYSLOG); /* fd 3 */ ! 37: #endif ! 38: #endif ! 39: ! 40: #ifdef FASTFORK ! 41: num_groups = read_groups(); /* Read active file now (fd 4) */ ! 42: /* and then do it every */ ! 43: set_timer(); /* so often later */ ! 44: #endif ! 45: ! 46: sockt = get_socket(); /* should be fd 4 or 5 */ ! 47: ! 48: (void) signal(SIGCHLD, reaper); ! 49: ! 50: if (listen(sockt, SOMAXCONN) < 0) { ! 51: #ifdef SYSLOG ! 52: syslog(LOG_ERR, "main: listen: %m"); ! 53: #endif ! 54: exit(1); ! 55: } ! 56: ! 57: for (;;) { ! 58: length = sizeof (from); ! 59: client = accept(sockt, &from, &length); ! 60: if (client < 0) { ! 61: #ifdef SYSLOG ! 62: if (errno != EINTR) ! 63: syslog(LOG_ERR, "accept: %m\n"); ! 64: #endif ! 65: continue; ! 66: } ! 67: ! 68: switch (fork()) { ! 69: case -1: ! 70: #ifdef SYSLOG ! 71: syslog(LOG_ERR, "fork: %m\n"); ! 72: #endif ! 73: (void) close(client); ! 74: break; ! 75: ! 76: case 0: (void) close(sockt); ! 77: make_stdio(client); ! 78: serve(); ! 79: break; ! 80: ! 81: default: (void) close(client); ! 82: break; ! 83: } ! 84: } ! 85: ! 86: #else /* We have inetd */ ! 87: ! 88: serve(); ! 89: ! 90: #endif ! 91: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.