main.c revision ce6676db
1/*
2 * Font server main routine
3 */
4/*
5
6Copyright 1990, 1991, 1998  The Open Group
7
8Permission to use, copy, modify, distribute, and sell this software and its
9documentation for any purpose is hereby granted without fee, provided that
10the above copyright notice appear in all copies and that both that
11copyright notice and this permission notice appear in supporting
12documentation.
13
14The above copyright notice and this permission notice shall be included in
15all copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24Except as contained in this notice, the name of The Open Group shall not be
25used in advertising or otherwise to promote the sale, use or other dealings
26in this Software without prior written authorization from The Open Group.
27
28 * Copyright 1990, 1991 Network Computing Devices;
29 * Portions Copyright 1987 by Digital Equipment Corporation
30 *
31 * Permission to use, copy, modify, distribute, and sell this software and
32 * its documentation for any purpose is hereby granted without fee, provided
33 * that the above copyright notice appear in all copies and that both that
34 * copyright notice and this permission notice appear in supporting
35 * documentation, and that the names of Network Computing Devices or Digital
36 * not be used in advertising or publicity pertaining to distribution
37 * of the software without specific, written prior permission.
38 *
39 * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH
40 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
41 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES,
42 * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
43 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
44 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
45 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
46 * THIS SOFTWARE.
47 */
48
49#include	"xfs-config.h"
50
51#include	<stdlib.h>
52#include	<sys/types.h>
53#include	<sys/stat.h>
54#include	<X11/fonts/FS.h>
55#include	<X11/fonts/FSproto.h>
56#include	"clientstr.h"
57#include	"fsresource.h"
58#include	"misc.h"
59#include	"globals.h"
60#include	"servermd.h"
61#include	"cache.h"
62#include	"site.h"
63#include	"dispatch.h"
64#include	"extentst.h"
65#include	"difs.h"
66
67char       *ConnectionInfo;
68int         ConnInfoLen;
69
70Cache       serverCache;
71
72#define	SERVER_CACHE_SIZE	10000	/* for random server cacheables */
73
74static Bool create_connection_block(void);
75
76char       *configfilename;
77
78int
79main(int argc, char *argv[])
80{
81    int         i, oldumask;
82
83    argcGlobal = argc;
84    argvGlobal = argv;
85
86    configfilename = NULL;
87
88    /* init stuff */
89    ProcessCmdLine(argc, argv);
90
91    /*
92     * Do this first thing, to get any options that only take effect at
93     * startup time.  It is read again each time the server resets.
94     */
95    if (ReadConfigFile(configfilename) != FSSuccess) {
96	FatalError("couldn't read config file\n");
97    }
98    InitErrors();
99
100    /* make sure at least world write access is disabled */
101    if (((oldumask = umask(022)) & 002) == 002)
102	(void)umask(oldumask);
103
104    SetDaemonState();
105    SetUserId();
106
107    while (1) {
108	serverGeneration++;
109	OsInit();
110	if (serverGeneration == 1) {
111	    /* do first time init */
112	    serverCache = CacheInit(SERVER_CACHE_SIZE);
113	    CreateSockets(OldListenCount, OldListen);
114	    InitProcVectors();
115	    clients = (ClientPtr *) fsalloc(MAXCLIENTS * sizeof(ClientPtr));
116	    if (!clients)
117		FatalError("couldn't create client array\n");
118	    for (i = MINCLIENT; i < MAXCLIENTS; i++)
119		clients[i] = NullClient;
120	    /* make serverClient */
121	    serverClient = (ClientPtr) fsalloc(sizeof(ClientRec));
122	    if (!serverClient)
123		FatalError("couldn't create server client\n");
124	}
125	ResetSockets();
126
127	/* init per-cycle stuff */
128	InitClient(serverClient, SERVER_CLIENT, (pointer) 0);
129
130	clients[SERVER_CLIENT] = serverClient;
131	currentMaxClients = MINCLIENT;
132	currentClient = serverClient;
133
134	if (!InitClientResources(serverClient))
135	    FatalError("couldn't init server resources\n");
136
137	InitExtensions();
138	InitAtoms();
139	InitFonts();
140	SetConfigValues();
141	if (!create_connection_block())
142	    FatalError("couldn't create connection block\n");
143
144#ifdef DEBUG
145	fprintf(stderr, "Entering Dispatch loop\n");
146#endif
147
148	Dispatch();
149
150#ifdef DEBUG
151	fprintf(stderr, "Leaving Dispatch loop\n");
152#endif
153
154	/* clean up per-cycle stuff */
155	CacheReset();
156	CloseDownExtensions();
157	if ((dispatchException & DE_TERMINATE) || drone_server)
158	    break;
159	fsfree(ConnectionInfo);
160	/* note that we're parsing it again, for each time the server resets */
161	if (ReadConfigFile(configfilename) != FSSuccess)
162	    FatalError("couldn't read config file\n");
163    }
164
165    CloseSockets();
166    CloseErrors();
167    exit(0);
168}
169
170int
171NotImplemented(void)
172{
173    NoopDDA();			/* dummy to get difsutils.o to link */
174    /* Getting here can become the next xfs exploit... so don't exit */
175    ErrorF("not implemented\n");
176
177    return (FSBadImplementation);
178}
179
180static Bool
181create_connection_block(void)
182{
183    fsConnSetupAccept setup;
184    char       *pBuf;
185
186    setup.release_number = VENDOR_RELEASE;
187    setup.vendor_len = strlen(VENDOR_STRING);
188    setup.max_request_len = MAX_REQUEST_SIZE;
189    setup.length = (SIZEOF(fsConnSetupAccept) + setup.vendor_len + 3) >> 2;
190
191    ConnInfoLen = SIZEOF(fsConnSetupAccept) + ((setup.vendor_len + 3) & ~3);
192    ConnectionInfo = (char *) fsalloc(ConnInfoLen);
193    if (!ConnectionInfo)
194	return FALSE;
195
196    memmove( ConnectionInfo, (char *) &setup, SIZEOF(fsConnSetupAccept));
197    pBuf = ConnectionInfo + SIZEOF(fsConnSetupAccept);
198    memmove( pBuf, VENDOR_STRING, (int) setup.vendor_len);
199
200    return TRUE;
201}
202