int SetAlternateServers(char *list) { char *t, *st; AlternateServerPtr alts, a; int num, i; t = list; num = 1; while (*t) { if (*t == ',') num++; t++; } a = alts = (AlternateServerPtr) fsalloc(sizeof(AlternateServerRec) * num); if (!alts) return FSBadAlloc; st = t = list; a->namelen = 0; while (*t) { if (*t == ',') { a->name = (char *) fsalloc(a->namelen); if (!a->name) { /* XXX -- leak */ return FSBadAlloc; } memmove( a->name, st, a->namelen); a->subset = FALSE; /* XXX */ a++; t++; st = t; a->namelen = 0; } else { a->namelen++; t++; } } a->name = (char *) fsalloc(a->namelen); if (!a->name) { /* XXX -- leak */ return FSBadAlloc; } memmove( a->name, st, a->namelen); a->subset = FALSE; /* XXX */ for (i = 0; i < num_alts; i++) { fsfree((char *) alt_servers[i].name); } fsfree((char *) alt_servers); num_alts = num; alt_servers = alts; return FSSuccess; }
int ListCatalogues(const char *pattern, int patlen, int maxnames, char **catalogues, int *len) { int count = 0; char *catlist = NULL; int size = 0; if (maxnames) { if (pattern_match(pattern, patlen, catalogue_name)) { size = strlen(catalogue_name); catlist = (char *) fsalloc(size + 1); if (!catlist) goto bail; *catlist = size; memmove( &catlist[1], catalogue_name, size); size++; /* for length */ count++; } } bail: *len = size; *catalogues = catlist; return count; }
Bool AddExtensionAlias(char *alias, ExtensionEntry *ext) { char *name; char **aliases; aliases = (char **) fsrealloc(ext->aliases, (ext->num_aliases + 1) * sizeof(char *)); if (!aliases) return FALSE; ext->aliases = aliases; name = (char *) fsalloc(strlen(alias) + 1); if (!name) return FALSE; strcpy(name, alias); ext->aliases[ext->num_aliases++] = name; return TRUE; }
static Bool create_connection_block(void) { fsConnSetupAccept setup; char *pBuf; setup.release_number = VENDOR_RELEASE; setup.vendor_len = strlen(VENDOR_STRING); setup.max_request_len = MAX_REQUEST_SIZE; setup.length = (SIZEOF(fsConnSetupAccept) + setup.vendor_len + 3) >> 2; ConnInfoLen = SIZEOF(fsConnSetupAccept) + ((setup.vendor_len + 3) & ~3); ConnectionInfo = (char *) fsalloc(ConnInfoLen); if (!ConnectionInfo) return FALSE; memmove( ConnectionInfo, (char *) &setup, SIZEOF(fsConnSetupAccept)); pBuf = ConnectionInfo + SIZEOF(fsConnSetupAccept); memmove( pBuf, VENDOR_STRING, (int) setup.vendor_len); return TRUE; }
int main(int argc, char *argv[]) { int i, oldumask; argcGlobal = argc; argvGlobal = argv; configfilename = NULL; /* init stuff */ ProcessCmdLine(argc, argv); /* * Do this first thing, to get any options that only take effect at * startup time. It is read again each time the server resets. */ if (ReadConfigFile(configfilename) != FSSuccess) { FatalError("couldn't read config file\n"); } InitErrors(); /* make sure at least world write access is disabled */ if (((oldumask = umask(022)) & 002) == 002) (void)umask(oldumask); SetDaemonState(); SetUserId(); while (1) { serverGeneration++; OsInit(); if (serverGeneration == 1) { /* do first time init */ CreateSockets(OldListenCount, OldListen); InitProcVectors(); clients = (ClientPtr *) fsalloc(MAXCLIENTS * sizeof(ClientPtr)); if (!clients) FatalError("couldn't create client array\n"); for (i = MINCLIENT; i < MAXCLIENTS; i++) clients[i] = NullClient; /* make serverClient */ serverClient = (ClientPtr) fsalloc(sizeof(ClientRec)); if (!serverClient) FatalError("couldn't create server client\n"); } ResetSockets(); /* init per-cycle stuff */ InitClient(serverClient, SERVER_CLIENT, (pointer) 0); clients[SERVER_CLIENT] = serverClient; currentMaxClients = MINCLIENT; currentClient = serverClient; if (!InitClientResources(serverClient)) FatalError("couldn't init server resources\n"); InitAtoms(); InitFonts(); SetConfigValues(); if (!create_connection_block()) FatalError("couldn't create connection block\n"); #ifdef DEBUG fprintf(stderr, "Entering Dispatch loop\n"); #endif Dispatch(); #ifdef DEBUG fprintf(stderr, "Leaving Dispatch loop\n"); #endif /* clean up per-cycle stuff */ if ((dispatchException & DE_TERMINATE) || drone_server) break; fsfree(ConnectionInfo); /* note that we're parsing it again, for each time the server resets */ if (ReadConfigFile(configfilename) != FSSuccess) FatalError("couldn't read config file\n"); } CloseSockets(); CloseErrors(); exit(0); }
ExtensionEntry * AddExtension( char *name, int num_events, int num_errors, int (*main_proc) (ClientPtr), int (*smain_proc) (ClientPtr), void (*closedown_proc) (struct _ExtensionEntry *), unsigned short (*minorop_proc) (ClientPtr)) { int i; ExtensionEntry *ext, **newexts; if (!main_proc || !smain_proc || !closedown_proc || !minorop_proc) return ((ExtensionEntry *) 0); if ((lastEvent + num_events > LAST_EVENT) || (unsigned) (lastError + num_errors > LAST_ERROR)) return ((ExtensionEntry *) 0); ext = (ExtensionEntry *) fsalloc(sizeof(ExtensionEntry)); if (!ext) return ((ExtensionEntry *) 0); ext->name = (char *) fsalloc(strlen(name) + 1); ext->num_aliases = 0; ext->aliases = (char **) NULL; if (!ext->name) { fsfree(ext); return ((ExtensionEntry *) 0); } strcpy(ext->name, name); i = NumExtensions; newexts = (ExtensionEntry **) fsrealloc(extensions, (i + 1) * sizeof(ExtensionEntry *)); if (!newexts) { fsfree(ext->name); fsfree(ext); return ((ExtensionEntry *) 0); } NumExtensions++; extensions = newexts; extensions[i] = ext; ext->index = i; ext->base = i + EXTENSION_BASE; ext->CloseDown = closedown_proc; ext->MinorOpcode = minorop_proc; ProcVector[i + EXTENSION_BASE] = main_proc; SwappedProcVector[i + EXTENSION_BASE] = smain_proc; if (num_events) { ext->eventBase = lastEvent; ext->eventLast = lastEvent + num_events; lastEvent += num_events; } else { ext->eventBase = 0; ext->eventLast = 0; } if (num_errors) { ext->errorBase = lastError; ext->errorLast = lastError + num_errors; lastError += num_errors; } else { ext->errorBase = 0; ext->errorLast = 0; } return ext; }
/* * accepts new connections */ void MakeNewConnections(void) { fd_mask readyconnections; int curconn; int newconn; long connect_time; int i; ClientPtr client; OsCommPtr oc; fd_set tmask; XFD_ANDSET (&tmask, &LastSelectMask, &WellKnownConnections); readyconnections = tmask.fds_bits[0]; if (!readyconnections) return; connect_time = GetTimeInMillis(); /* kill off stragglers */ for (i = MINCLIENT; i < currentMaxClients; i++) { if ((client = clients[i]) != NullClient) { oc = (OsCommPtr) client->osPrivate; if ((oc && (oc->conn_time != 0) && (connect_time - oc->conn_time) >= TimeOutValue) || ((client->noClientException != FSSuccess) && (client->clientGone != CLIENT_GONE))) CloseDownClient(client); } } while (readyconnections) { XtransConnInfo trans_conn, new_trans_conn; int status; curconn = ffs(readyconnections) - 1; readyconnections &= ~(1 << curconn); if ((trans_conn = lookup_trans_conn (curconn)) == NULL) continue; if ((new_trans_conn = _FontTransAccept (trans_conn, &status)) == NULL) continue; newconn = _FontTransGetConnectionNumber (new_trans_conn); _FontTransSetOption(new_trans_conn, TRANS_NONBLOCKING, 1); oc = (OsCommPtr) fsalloc(sizeof(OsCommRec)); if (!oc) { fsfree(oc); error_conn_max(new_trans_conn); _FontTransClose(new_trans_conn); continue; } FD_SET(newconn, &AllClients); FD_SET(newconn, &AllSockets); oc->fd = newconn; oc->trans_conn = new_trans_conn; oc->input = (ConnectionInputPtr) NULL; oc->output = (ConnectionOutputPtr) NULL; oc->conn_time = connect_time; if ((newconn < lastfdesc) && (client = NextAvailableClient((pointer) oc))) { ConnectionTranslation[newconn] = client->index; } else { error_conn_max(new_trans_conn); close_fd(oc); } } }