os: Add CryptoAPI as a choice of SHA1 implementation
[xserver/hramrach.git] / dix / main.c
blob70dcc946e1f6122344da021c82ebc1d9e88c5daa
1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
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.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
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.
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.
25 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
27 All Rights Reserved
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.
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.
45 ******************************************************************/
47 /* The panoramix components contained the following notice */
48 /*****************************************************************
50 Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
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.
58 The above copyright notice and this permission notice shall be included in
59 all copies or substantial portions of the Software.
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.
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.
74 ******************************************************************/
76 #ifdef HAVE_DIX_CONFIG_H
77 #include <dix-config.h>
78 #include <version-config.h>
79 #endif
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 "opaque.h"
99 #include "servermd.h"
100 #include "hotplug.h"
101 #include "site.h"
102 #include "dixfont.h"
103 #include "extnsionst.h"
104 #include "privates.h"
105 #include "registry.h"
106 #include "client.h"
107 #ifdef PANORAMIX
108 #include "panoramiXsrv.h"
109 #else
110 #include "dixevents.h" /* InitEvents() */
111 #endif
113 #ifdef DPMSExtension
114 #include <X11/extensions/dpmsconst.h>
115 #include "dpmsproc.h"
116 #endif
118 extern void Dispatch(void);
120 #ifdef XQUARTZ
121 #include <pthread.h>
123 BOOL serverRunning = FALSE;
124 pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER;
125 pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER;
127 int dix_main(int argc, char *argv[], char *envp[]);
130 dix_main(int argc, char *argv[], char *envp[])
131 #else
133 main(int argc, char *argv[], char *envp[])
134 #endif
136 int i;
137 HWEventQueueType alwaysCheckForInput[2];
139 display = "0";
141 InitRegions();
143 CheckUserParameters(argc, argv, envp);
145 CheckUserAuthorization();
147 InitConnectionLimits();
149 ProcessCommandLine(argc, argv);
151 alwaysCheckForInput[0] = 0;
152 alwaysCheckForInput[1] = 1;
153 while (1) {
154 serverGeneration++;
155 ScreenSaverTime = defaultScreenSaverTime;
156 ScreenSaverInterval = defaultScreenSaverInterval;
157 ScreenSaverBlanking = defaultScreenSaverBlanking;
158 ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
159 #ifdef DPMSExtension
160 DPMSStandbyTime = DPMSSuspendTime = DPMSOffTime = ScreenSaverTime;
161 DPMSEnabled = TRUE;
162 DPMSPowerLevel = 0;
163 #endif
164 InitBlockAndWakeupHandlers();
165 /* Perform any operating system dependent initializations you'd like */
166 OsInit();
167 if (serverGeneration == 1) {
168 CreateWellKnownSockets();
169 for (i = 1; i < MAXCLIENTS; i++)
170 clients[i] = NullClient;
171 serverClient = calloc(sizeof(ClientRec), 1);
172 if (!serverClient)
173 FatalError("couldn't create server client");
174 InitClient(serverClient, 0, (pointer) NULL);
176 else
177 ResetWellKnownSockets();
178 clients[0] = serverClient;
179 currentMaxClients = 1;
181 /* Initialize privates before first allocation */
182 dixResetPrivates();
184 /* Initialize server client devPrivates, to be reallocated as
185 * more client privates are registered
187 if (!dixAllocatePrivates(&serverClient->devPrivates, PRIVATE_CLIENT))
188 FatalError("failed to create server client privates");
190 if (!InitClientResources(serverClient)) /* for root resources */
191 FatalError("couldn't init server resources");
193 SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]);
194 screenInfo.numScreens = 0;
196 InitAtoms();
197 InitEvents();
198 InitSelections();
199 InitGlyphCaching();
200 dixResetRegistry();
201 ResetFontPrivateIndex();
202 InitCallbackManager();
203 InitOutput(&screenInfo, argc, argv);
205 if (screenInfo.numScreens < 1)
206 FatalError("no screens found");
207 InitExtensions(argc, argv);
209 for (i = 0; i < screenInfo.numScreens; i++) {
210 ScreenPtr pScreen = screenInfo.screens[i];
212 if (!CreateScratchPixmapsForScreen(i))
213 FatalError("failed to create scratch pixmaps");
214 if (pScreen->CreateScreenResources &&
215 !(*pScreen->CreateScreenResources) (pScreen))
216 FatalError("failed to create screen resources");
217 if (!CreateGCperDepth(i))
218 FatalError("failed to create scratch GCs");
219 if (!CreateDefaultStipple(i))
220 FatalError("failed to create default stipple");
221 if (!CreateRootWindow(pScreen))
222 FatalError("failed to create root window");
225 InitFonts();
226 if (SetDefaultFontPath(defaultFontPath) != Success) {
227 ErrorF("[dix] failed to set default font path '%s'",
228 defaultFontPath);
230 if (!SetDefaultFont(defaultTextFont)) {
231 FatalError("could not open default font '%s'", defaultTextFont);
234 if (!(rootCursor = CreateRootCursor(NULL, 0))) {
235 FatalError("could not open default cursor font '%s'",
236 defaultCursorFont);
239 #ifdef DPMSExtension
240 /* check all screens, looking for DPMS Capabilities */
241 DPMSCapableFlag = DPMSSupported();
242 if (!DPMSCapableFlag)
243 DPMSEnabled = FALSE;
244 #endif
246 #ifdef PANORAMIX
248 * Consolidate window and colourmap information for each screen
250 if (!noPanoramiXExtension)
251 PanoramiXConsolidate();
252 #endif
254 for (i = 0; i < screenInfo.numScreens; i++)
255 InitRootWindow(screenInfo.screens[i]->root);
257 InitCoreDevices();
258 InitInput(argc, argv);
259 InitAndStartDevices();
260 ReserveClientIds(serverClient);
262 dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
264 #ifdef PANORAMIX
265 if (!noPanoramiXExtension) {
266 if (!PanoramiXCreateConnectionBlock()) {
267 FatalError("could not create connection block info");
270 else
271 #endif
273 if (!CreateConnectionBlock()) {
274 FatalError("could not create connection block info");
278 #ifdef XQUARTZ
279 /* Let the other threads know the server is done with its init */
280 pthread_mutex_lock(&serverRunningMutex);
281 serverRunning = TRUE;
282 pthread_cond_broadcast(&serverRunningCond);
283 pthread_mutex_unlock(&serverRunningMutex);
284 #endif
286 NotifyParentProcess();
288 Dispatch();
290 #ifdef XQUARTZ
291 /* Let the other threads know the server is no longer running */
292 pthread_mutex_lock(&serverRunningMutex);
293 serverRunning = FALSE;
294 pthread_mutex_unlock(&serverRunningMutex);
295 #endif
297 UndisplayDevices();
299 /* Now free up whatever must be freed */
300 if (screenIsSaved == SCREEN_SAVER_ON)
301 dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
302 FreeScreenSaverTimer();
303 CloseDownExtensions();
305 #ifdef PANORAMIX
307 Bool remember_it = noPanoramiXExtension;
309 noPanoramiXExtension = TRUE;
310 FreeAllResources();
311 noPanoramiXExtension = remember_it;
313 #else
314 FreeAllResources();
315 #endif
317 CloseInput();
319 for (i = 0; i < screenInfo.numScreens; i++)
320 screenInfo.screens[i]->root = NullWindow;
321 CloseDownDevices();
322 CloseDownEvents();
324 for (i = screenInfo.numScreens - 1; i >= 0; i--) {
325 FreeScratchPixmapsForScreen(i);
326 FreeGCperDepth(i);
327 FreeDefaultStipple(i);
328 (*screenInfo.screens[i]->CloseScreen) (i, screenInfo.screens[i]);
329 dixFreePrivates(screenInfo.screens[i]->devPrivates, PRIVATE_SCREEN);
330 free(screenInfo.screens[i]);
331 screenInfo.numScreens = i;
334 ReleaseClientIds(serverClient);
335 dixFreePrivates(serverClient->devPrivates, PRIVATE_CLIENT);
336 serverClient->devPrivates = NULL;
338 FreeFonts();
340 FreeAuditTimer();
342 if (dispatchException & DE_TERMINATE) {
343 CloseWellKnownConnections();
346 OsCleanup((dispatchException & DE_TERMINATE) != 0);
348 if (dispatchException & DE_TERMINATE) {
349 ddxGiveUp(EXIT_NO_ERROR);
350 break;
353 free(ConnectionInfo);
354 ConnectionInfo = NULL;
356 return 0;