/* * creates the sockets for listening to clients * * only called when server first started */ void CreateSockets(int old_listen_count, OldListenRec *old_listen) { int i; FD_ZERO(&AllSockets); FD_ZERO(&AllClients); FD_ZERO(&LastSelectMask); FD_ZERO(&ClientsWithInput); FD_ZERO(&WellKnownConnections); for (i = 0; i < MAXSOCKS; i++) ConnectionTranslation[i] = 0; #ifdef XNO_SYSCONF /* should only be on FreeBSD 1.x and NetBSD 0.x */ #undef _SC_OPEN_MAX #endif #ifdef _SC_OPEN_MAX lastfdesc = sysconf(_SC_OPEN_MAX) - 1; #else #if defined(hpux) || defined(__UNIXOS2__) lastfdesc = _NFILE - 1; #else lastfdesc = getdtablesize() - 1; #endif /* hpux */ #endif if (lastfdesc > MAXSOCKS) { lastfdesc = MAXSOCKS; } if (old_listen_count > 0) { /* * The font server cloned itself. Re-use previously opened * transports for listening. */ ListenTransConns = (XtransConnInfo *) malloc ( old_listen_count * sizeof (XtransConnInfo)); ListenTransFds = (int *) malloc (old_listen_count * sizeof (int)); ListenTransCount = 0; for (i = 0; i < old_listen_count; i++) { char portnum[10]; if (old_listen[i].portnum != ListenPort) continue; /* this should never happen */ else sprintf (portnum, "%d", old_listen[i].portnum); if ((ListenTransConns[ListenTransCount] = _FontTransReopenCOTSServer (old_listen[i].trans_id, old_listen[i].fd, portnum)) != NULL) { ListenTransFds[ListenTransCount] = old_listen[i].fd; FD_SET (old_listen[i].fd, &WellKnownConnections); NoticeF("reusing existing file descriptor %d\n", old_listen[i].fd); ListenTransCount++; } } } else { char port[20]; int partial; sprintf (port, "%d", ListenPort); if ((_FontTransMakeAllCOTSServerListeners (port, &partial, &ListenTransCount, &ListenTransConns) >= 0) && (ListenTransCount >= 1)) { ListenTransFds = (int *) malloc (ListenTransCount * sizeof (int)); for (i = 0; i < ListenTransCount; i++) { int fd = _FontTransGetConnectionNumber (ListenTransConns[i]); ListenTransFds[i] = fd; FD_SET (fd, &WellKnownConnections); } } } if (! XFD_ANYSET(&WellKnownConnections)) FatalError("cannot establish any listening sockets\n"); /* set up all the signal handlers */ signal(SIGPIPE, SIG_IGN); signal(SIGHUP, AutoResetServer); signal(SIGINT, GiveUp); signal(SIGTERM, GiveUp); signal(SIGUSR1, ServerReconfig); signal(SIGUSR2, ServerCacheFlush); signal(SIGCHLD, CleanupChild); XFD_COPYSET (&WellKnownConnections, &AllSockets); }
/* * creates the sockets for listening to clients * * only called when server first started */ void CreateSockets(int old_listen_count, OldListenRec *old_listen) { int i; struct sigaction act; FD_ZERO(&AllSockets); FD_ZERO(&AllClients); FD_ZERO(&LastSelectMask); FD_ZERO(&ClientsWithInput); FD_ZERO(&WellKnownConnections); for (i = 0; i < MAXSOCKS; i++) ConnectionTranslation[i] = 0; lastfdesc = sysconf(_SC_OPEN_MAX) - 1; if ((lastfdesc < 0) || (lastfdesc > MAXSOCKS)) { lastfdesc = MAXSOCKS; } if (old_listen_count > 0) { /* * The font server cloned itself. Re-use previously opened * transports for listening. */ ListenTransConns = (XtransConnInfo *) malloc ( old_listen_count * sizeof (XtransConnInfo)); ListenTransFds = (int *) malloc (old_listen_count * sizeof (int)); ListenTransCount = 0; for (i = 0; i < old_listen_count; i++) { char portnum[10]; if (old_listen[i].portnum != ListenPort) continue; /* this should never happen */ else sprintf (portnum, "%d", old_listen[i].portnum); if ((ListenTransConns[ListenTransCount] = _FontTransReopenCOTSServer (old_listen[i].trans_id, old_listen[i].fd, portnum)) != NULL) { ListenTransFds[ListenTransCount] = old_listen[i].fd; FD_SET (old_listen[i].fd, &WellKnownConnections); NoticeF("reusing existing file descriptor %d\n", old_listen[i].fd); ListenTransCount++; } } } else { char port[20]; int partial; sprintf (port, "%d", ListenPort); if ((_FontTransMakeAllCOTSServerListeners (port, &partial, &ListenTransCount, &ListenTransConns) >= 0) && (ListenTransCount >= 1)) { ListenTransFds = (int *) malloc (ListenTransCount * sizeof (int)); for (i = 0; i < ListenTransCount; i++) { int fd = _FontTransGetConnectionNumber (ListenTransConns[i]); ListenTransFds[i] = fd; FD_SET (fd, &WellKnownConnections); } } } if (! XFD_ANYSET(&WellKnownConnections)) FatalError("cannot establish any listening sockets\n"); /* set up all the signal handlers */ sigemptyset(&act.sa_mask); act.sa_flags = SA_RESTART; #define HANDLE_SIGNAL(s, h) act.sa_handler = h; sigaction(s, &act, NULL) HANDLE_SIGNAL(SIGPIPE, SIG_IGN); HANDLE_SIGNAL(SIGHUP, AutoResetServer); HANDLE_SIGNAL(SIGINT, GiveUp); HANDLE_SIGNAL(SIGTERM, GiveUp); HANDLE_SIGNAL(SIGUSR1, ServerReconfig); HANDLE_SIGNAL(SIGUSR2, ServerCacheFlush); HANDLE_SIGNAL(SIGCHLD, CleanupChild); XFD_COPYSET (&WellKnownConnections, &AllSockets); }