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
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.
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
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>
82 #include <X11/Xos.h> /* for unistd.h */
83 #include <X11/Xproto.h>
85 #include "scrnintstr.h"
88 #include "windowstr.h"
90 #include "dixstruct.h"
92 #include "extension.h"
94 #include "colormapst.h"
95 #include "cursorstr.h"
96 #include "selection.h"
97 #include <X11/fonts/font.h>
103 #include "extnsionst.h"
104 #include "privates.h"
105 #include "registry.h"
107 #include "exevents.h"
109 #include "panoramiXsrv.h"
111 #include "dixevents.h" /* InitEvents() */
115 #include <X11/extensions/dpmsconst.h>
116 #include "dpmsproc.h"
119 extern void Dispatch(void);
124 BOOL serverRunning
= FALSE
;
125 pthread_mutex_t serverRunningMutex
= PTHREAD_MUTEX_INITIALIZER
;
126 pthread_cond_t serverRunningCond
= PTHREAD_COND_INITIALIZER
;
131 dix_main(int argc
, char *argv
[], char *envp
[])
134 HWEventQueueType alwaysCheckForInput
[2];
140 CheckUserParameters(argc
, argv
, envp
);
142 CheckUserAuthorization();
144 InitConnectionLimits();
146 ProcessCommandLine(argc
, argv
);
148 alwaysCheckForInput
[0] = 0;
149 alwaysCheckForInput
[1] = 1;
152 ScreenSaverTime
= defaultScreenSaverTime
;
153 ScreenSaverInterval
= defaultScreenSaverInterval
;
154 ScreenSaverBlanking
= defaultScreenSaverBlanking
;
155 ScreenSaverAllowExposures
= defaultScreenSaverAllowExposures
;
157 DPMSStandbyTime
= DPMSSuspendTime
= DPMSOffTime
= ScreenSaverTime
;
161 InitBlockAndWakeupHandlers();
162 /* Perform any operating system dependent initializations you'd like */
164 if (serverGeneration
== 1) {
165 CreateWellKnownSockets();
166 for (i
= 1; i
< MAXCLIENTS
; i
++)
167 clients
[i
] = NullClient
;
168 serverClient
= calloc(sizeof(ClientRec
), 1);
170 FatalError("couldn't create server client");
171 InitClient(serverClient
, 0, (pointer
) NULL
);
174 ResetWellKnownSockets();
175 clients
[0] = serverClient
;
176 currentMaxClients
= 1;
178 /* Initialize privates before first allocation */
181 /* Initialize server client devPrivates, to be reallocated as
182 * more client privates are registered
184 if (!dixAllocatePrivates(&serverClient
->devPrivates
, PRIVATE_CLIENT
))
185 FatalError("failed to create server client privates");
187 if (!InitClientResources(serverClient
)) /* for root resources */
188 FatalError("couldn't init server resources");
190 SetInputCheck(&alwaysCheckForInput
[0], &alwaysCheckForInput
[1]);
191 screenInfo
.numScreens
= 0;
198 ResetFontPrivateIndex();
199 InitCallbackManager();
200 InitOutput(&screenInfo
, argc
, argv
);
202 if (screenInfo
.numScreens
< 1)
203 FatalError("no screens found");
204 InitExtensions(argc
, argv
);
206 for (i
= 0; i
< screenInfo
.numGPUScreens
; i
++) {
207 ScreenPtr pScreen
= screenInfo
.gpuscreens
[i
];
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");
215 for (i
= 0; i
< screenInfo
.numScreens
; i
++) {
216 ScreenPtr pScreen
= screenInfo
.screens
[i
];
218 if (!CreateScratchPixmapsForScreen(pScreen
))
219 FatalError("failed to create scratch pixmaps");
220 if (pScreen
->CreateScreenResources
&&
221 !(*pScreen
->CreateScreenResources
) (pScreen
))
222 FatalError("failed to create screen resources");
223 if (!CreateGCperDepth(i
))
224 FatalError("failed to create scratch GCs");
225 if (!CreateDefaultStipple(i
))
226 FatalError("failed to create default stipple");
227 if (!CreateRootWindow(pScreen
))
228 FatalError("failed to create root window");
232 if (SetDefaultFontPath(defaultFontPath
) != Success
) {
233 ErrorF("[dix] failed to set default font path '%s'",
236 if (!SetDefaultFont(defaultTextFont
)) {
237 FatalError("could not open default font '%s'", defaultTextFont
);
240 if (!(rootCursor
= CreateRootCursor(NULL
, 0))) {
241 FatalError("could not open default cursor font '%s'",
246 /* check all screens, looking for DPMS Capabilities */
247 DPMSCapableFlag
= DPMSSupported();
248 if (!DPMSCapableFlag
)
254 * Consolidate window and colourmap information for each screen
256 if (!noPanoramiXExtension
)
257 PanoramiXConsolidate();
260 for (i
= 0; i
< screenInfo
.numScreens
; i
++)
261 InitRootWindow(screenInfo
.screens
[i
]->root
);
264 InitInput(argc
, argv
);
265 InitAndStartDevices();
266 ReserveClientIds(serverClient
);
268 dixSaveScreens(serverClient
, SCREEN_SAVER_FORCER
, ScreenSaverReset
);
271 if (!noPanoramiXExtension
) {
272 if (!PanoramiXCreateConnectionBlock()) {
273 FatalError("could not create connection block info");
279 if (!CreateConnectionBlock()) {
280 FatalError("could not create connection block info");
285 /* Let the other threads know the server is done with its init */
286 pthread_mutex_lock(&serverRunningMutex
);
287 serverRunning
= TRUE
;
288 pthread_cond_broadcast(&serverRunningCond
);
289 pthread_mutex_unlock(&serverRunningMutex
);
292 NotifyParentProcess();
297 /* Let the other threads know the server is no longer running */
298 pthread_mutex_lock(&serverRunningMutex
);
299 serverRunning
= FALSE
;
300 pthread_mutex_unlock(&serverRunningMutex
);
306 /* Now free up whatever must be freed */
307 if (screenIsSaved
== SCREEN_SAVER_ON
)
308 dixSaveScreens(serverClient
, SCREEN_SAVER_OFF
, ScreenSaverReset
);
309 FreeScreenSaverTimer();
310 CloseDownExtensions();
314 Bool remember_it
= noPanoramiXExtension
;
316 noPanoramiXExtension
= TRUE
;
318 noPanoramiXExtension
= remember_it
;
326 for (i
= 0; i
< screenInfo
.numScreens
; i
++)
327 screenInfo
.screens
[i
]->root
= NullWindow
;
333 for (i
= screenInfo
.numGPUScreens
- 1; i
>= 0; i
--) {
334 ScreenPtr pScreen
= screenInfo
.gpuscreens
[i
];
335 FreeScratchPixmapsForScreen(pScreen
);
336 (*pScreen
->CloseScreen
) (pScreen
);
337 dixFreePrivates(pScreen
->devPrivates
, PRIVATE_SCREEN
);
339 screenInfo
.numGPUScreens
= i
;
342 for (i
= screenInfo
.numScreens
- 1; i
>= 0; i
--) {
343 FreeScratchPixmapsForScreen(screenInfo
.screens
[i
]);
345 FreeDefaultStipple(i
);
346 dixFreeScreenSpecificPrivates(screenInfo
.screens
[i
]);
347 (*screenInfo
.screens
[i
]->CloseScreen
) (screenInfo
.screens
[i
]);
348 dixFreePrivates(screenInfo
.screens
[i
]->devPrivates
, PRIVATE_SCREEN
);
349 free(screenInfo
.screens
[i
]);
350 screenInfo
.numScreens
= i
;
353 ReleaseClientIds(serverClient
);
354 dixFreePrivates(serverClient
->devPrivates
, PRIVATE_CLIENT
);
355 serverClient
->devPrivates
= NULL
;
365 DeleteCallbackManager();
367 if (dispatchException
& DE_TERMINATE
) {
368 CloseWellKnownConnections();
371 OsCleanup((dispatchException
& DE_TERMINATE
) != 0);
373 if (dispatchException
& DE_TERMINATE
) {
374 ddxGiveUp(EXIT_NO_ERROR
);
378 free(ConnectionInfo
);
379 ConnectionInfo
= NULL
;