1 /***********************************************************
2
3 Copyright 1987, 1998 The Open Group
4
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24
25 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
26
27 All Rights Reserved
28
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
36
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43 SOFTWARE.
44
45 ******************************************************************/
46
47 /* The panoramix components contained the following notice */
48 /*****************************************************************
49
50 Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
51
52 Permission is hereby granted, free of charge, to any person obtaining a copy
53 of this software and associated documentation files (the "Software"), to deal
54 in the Software without restriction, including without limitation the rights
55 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
56 copies of the Software.
57
58 The above copyright notice and this permission notice shall be included in
59 all copies or substantial portions of the Software.
60
61 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
64 DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
65 BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
66 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
67 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68
69 Except as contained in this notice, the name of Digital Equipment Corporation
70 shall not be used in advertising or otherwise to promote the sale, use or other
71 dealings in this Software without prior written authorization from Digital
72 Equipment Corporation.
73
74 ******************************************************************/
75
76 #ifdef HAVE_DIX_CONFIG_H
77 #include <dix-config.h>
78 #include <version-config.h>
79 #endif
80
81 #include <X11/X.h>
82 #include <X11/Xos.h> /* for unistd.h */
83 #include <X11/Xproto.h>
84 #include <pixman.h>
85 #include "scrnintstr.h"
86 #include "misc.h"
87 #include "os.h"
88 #include "windowstr.h"
89 #include "resource.h"
90 #include "dixstruct.h"
91 #include "gcstruct.h"
92 #include "extension.h"
93 #include "colormap.h"
94 #include "colormapst.h"
95 #include "cursorstr.h"
96 #include "selection.h"
97 #include <X11/fonts/font.h>
98 #include <X11/fonts/fontstruct.h>
99 #include <X11/fonts/libxfont2.h>
100 #include "opaque.h"
101 #include "servermd.h"
102 #include "hotplug.h"
103 #include "dixfont.h"
104 #include "extnsionst.h"
105 #include "privates.h"
106 #include "registry.h"
107 #include "client.h"
108 #include "exevents.h"
109 #ifdef PANORAMIX
110 #include "panoramiXsrv.h"
111 #else
112 #include "dixevents.h" /* InitEvents() */
113 #endif
114
115 #ifdef DPMSExtension
116 #include <X11/extensions/dpmsconst.h>
117 #include "dpmsproc.h"
118 #endif
119
120 extern void Dispatch(void);
121
122 CallbackListPtr RootWindowFinalizeCallback = NULL;
123
124 int
dix_main(int argc,char * argv[],char * envp[])125 dix_main(int argc, char *argv[], char *envp[])
126 {
127 int i;
128 HWEventQueueType alwaysCheckForInput[2];
129
130 display = "0";
131
132 InitRegions();
133
134 CheckUserParameters(argc, argv, envp);
135
136 CheckUserAuthorization();
137
138 ProcessCommandLine(argc, argv);
139
140 alwaysCheckForInput[0] = 0;
141 alwaysCheckForInput[1] = 1;
142 while (1) {
143 serverGeneration++;
144 ScreenSaverTime = defaultScreenSaverTime;
145 ScreenSaverInterval = defaultScreenSaverInterval;
146 ScreenSaverBlanking = defaultScreenSaverBlanking;
147 ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
148
149 InitBlockAndWakeupHandlers();
150 /* Perform any operating system dependent initializations you'd like */
151 OsInit();
152 if (serverGeneration == 1) {
153 CreateWellKnownSockets();
154 for (i = 1; i < LimitClients; i++)
155 clients[i] = NullClient;
156 serverClient = calloc(sizeof(ClientRec), 1);
157 if (!serverClient)
158 FatalError("couldn't create server client");
159 InitClient(serverClient, 0, (void *) NULL);
160 }
161 else
162 ResetWellKnownSockets();
163 clients[0] = serverClient;
164 currentMaxClients = 1;
165
166 /* clear any existing selections */
167 InitSelections();
168
169 /* Initialize privates before first allocation */
170 dixResetPrivates();
171
172 /* Initialize server client devPrivates, to be reallocated as
173 * more client privates are registered
174 */
175 if (!dixAllocatePrivates(&serverClient->devPrivates, PRIVATE_CLIENT))
176 FatalError("failed to create server client privates");
177
178 if (!InitClientResources(serverClient)) /* for root resources */
179 FatalError("couldn't init server resources");
180
181 SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]);
182 screenInfo.numScreens = 0;
183
184 InitAtoms();
185 InitEvents();
186 xfont2_init_glyph_caching();
187 dixResetRegistry();
188 InitFonts();
189 InitCallbackManager();
190 InitOutput(&screenInfo, argc, argv);
191
192 if (screenInfo.numScreens < 1)
193 FatalError("no screens found");
194 InitExtensions(argc, argv);
195
196 for (i = 0; i < screenInfo.numGPUScreens; i++) {
197 ScreenPtr pScreen = screenInfo.gpuscreens[i];
198 if (!CreateScratchPixmapsForScreen(pScreen))
199 FatalError("failed to create scratch pixmaps");
200 if (pScreen->CreateScreenResources &&
201 !(*pScreen->CreateScreenResources) (pScreen))
202 FatalError("failed to create screen resources");
203 }
204
205 for (i = 0; i < screenInfo.numScreens; i++) {
206 ScreenPtr pScreen = screenInfo.screens[i];
207
208 if (!CreateScratchPixmapsForScreen(pScreen))
209 FatalError("failed to create scratch pixmaps");
210 if (pScreen->CreateScreenResources &&
211 !(*pScreen->CreateScreenResources) (pScreen))
212 FatalError("failed to create screen resources");
213 if (!CreateGCperDepth(i))
214 FatalError("failed to create scratch GCs");
215 if (!CreateDefaultStipple(i))
216 FatalError("failed to create default stipple");
217 if (!CreateRootWindow(pScreen))
218 FatalError("failed to create root window");
219 CallCallbacks(&RootWindowFinalizeCallback, pScreen);
220 }
221
222 if (SetDefaultFontPath(defaultFontPath) != Success) {
223 ErrorF("[dix] failed to set default font path '%s'",
224 defaultFontPath);
225 }
226 if (!SetDefaultFont("fixed")) {
227 FatalError("could not open default font");
228 }
229
230 if (!(rootCursor = CreateRootCursor(NULL, 0))) {
231 FatalError("could not open default cursor font");
232 }
233
234 #ifdef PANORAMIX
235 /*
236 * Consolidate window and colourmap information for each screen
237 */
238 if (!noPanoramiXExtension)
239 PanoramiXConsolidate();
240 #endif
241
242 for (i = 0; i < screenInfo.numScreens; i++)
243 InitRootWindow(screenInfo.screens[i]->root);
244
245 InitCoreDevices();
246 InitInput(argc, argv);
247 InitAndStartDevices();
248 ReserveClientIds(serverClient);
249
250 dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
251
252 dixCloseRegistry();
253
254 #ifdef PANORAMIX
255 if (!noPanoramiXExtension) {
256 if (!PanoramiXCreateConnectionBlock()) {
257 FatalError("could not create connection block info");
258 }
259 }
260 else
261 #endif
262 {
263 if (!CreateConnectionBlock()) {
264 FatalError("could not create connection block info");
265 }
266 }
267
268 NotifyParentProcess();
269
270 InputThreadInit();
271
272 Dispatch();
273
274 UndisplayDevices();
275 DisableAllDevices();
276
277 /* Now free up whatever must be freed */
278 if (screenIsSaved == SCREEN_SAVER_ON)
279 dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
280 FreeScreenSaverTimer();
281 CloseDownExtensions();
282
283 #ifdef PANORAMIX
284 {
285 Bool remember_it = noPanoramiXExtension;
286
287 noPanoramiXExtension = TRUE;
288 FreeAllResources();
289 noPanoramiXExtension = remember_it;
290 }
291 #else
292 FreeAllResources();
293 #endif
294
295 CloseInput();
296
297 InputThreadFini();
298
299 for (i = 0; i < screenInfo.numScreens; i++)
300 screenInfo.screens[i]->root = NullWindow;
301
302 CloseDownDevices();
303
304 CloseDownEvents();
305
306 for (i = screenInfo.numGPUScreens - 1; i >= 0; i--) {
307 ScreenPtr pScreen = screenInfo.gpuscreens[i];
308 FreeScratchPixmapsForScreen(pScreen);
309 dixFreeScreenSpecificPrivates(pScreen);
310 (*pScreen->CloseScreen) (pScreen);
311 dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
312 free(pScreen);
313 screenInfo.numGPUScreens = i;
314 }
315
316 for (i = screenInfo.numScreens - 1; i >= 0; i--) {
317 FreeScratchPixmapsForScreen(screenInfo.screens[i]);
318 FreeGCperDepth(i);
319 FreeDefaultStipple(i);
320 dixFreeScreenSpecificPrivates(screenInfo.screens[i]);
321 (*screenInfo.screens[i]->CloseScreen) (screenInfo.screens[i]);
322 dixFreePrivates(screenInfo.screens[i]->devPrivates, PRIVATE_SCREEN);
323 free(screenInfo.screens[i]);
324 screenInfo.numScreens = i;
325 }
326
327 ReleaseClientIds(serverClient);
328 dixFreePrivates(serverClient->devPrivates, PRIVATE_CLIENT);
329 serverClient->devPrivates = NULL;
330
331 dixFreeRegistry();
332
333 FreeFonts();
334
335 FreeAllAtoms();
336
337 FreeAuditTimer();
338
339 DeleteCallbackManager();
340
341 ClearWorkQueue();
342
343 if (dispatchException & DE_TERMINATE) {
344 CloseWellKnownConnections();
345 }
346
347 OsCleanup((dispatchException & DE_TERMINATE) != 0);
348
349 if (dispatchException & DE_TERMINATE) {
350 ddxGiveUp(EXIT_NO_ERROR);
351 break;
352 }
353
354 free(ConnectionInfo);
355 ConnectionInfo = NULL;
356 }
357 return 0;
358 }
359