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