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"
108 #include "panoramiXsrv.h"
110 #include "dixevents.h" /* InitEvents() */
114 #include <X11/extensions/dpmsconst.h>
115 #include "dpmsproc.h"
118 extern void Dispatch(void);
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
[])
133 main(int argc
, char *argv
[], char *envp
[])
137 HWEventQueueType alwaysCheckForInput
[2];
143 CheckUserParameters(argc
, argv
, envp
);
145 CheckUserAuthorization();
147 InitConnectionLimits();
149 ProcessCommandLine(argc
, argv
);
151 alwaysCheckForInput
[0] = 0;
152 alwaysCheckForInput
[1] = 1;
155 ScreenSaverTime
= defaultScreenSaverTime
;
156 ScreenSaverInterval
= defaultScreenSaverInterval
;
157 ScreenSaverBlanking
= defaultScreenSaverBlanking
;
158 ScreenSaverAllowExposures
= defaultScreenSaverAllowExposures
;
160 DPMSStandbyTime
= DPMSSuspendTime
= DPMSOffTime
= ScreenSaverTime
;
164 InitBlockAndWakeupHandlers();
165 /* Perform any operating system dependent initializations you'd like */
167 if (serverGeneration
== 1) {
168 CreateWellKnownSockets();
169 for (i
= 1; i
< MAXCLIENTS
; i
++)
170 clients
[i
] = NullClient
;
171 serverClient
= calloc(sizeof(ClientRec
), 1);
173 FatalError("couldn't create server client");
174 InitClient(serverClient
, 0, (pointer
) NULL
);
177 ResetWellKnownSockets();
178 clients
[0] = serverClient
;
179 currentMaxClients
= 1;
181 /* Initialize privates before first allocation */
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;
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");
226 if (SetDefaultFontPath(defaultFontPath
) != Success
) {
227 ErrorF("[dix] failed to set default font path '%s'",
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'",
240 /* check all screens, looking for DPMS Capabilities */
241 DPMSCapableFlag
= DPMSSupported();
242 if (!DPMSCapableFlag
)
248 * Consolidate window and colourmap information for each screen
250 if (!noPanoramiXExtension
)
251 PanoramiXConsolidate();
254 for (i
= 0; i
< screenInfo
.numScreens
; i
++)
255 InitRootWindow(screenInfo
.screens
[i
]->root
);
258 InitInput(argc
, argv
);
259 InitAndStartDevices();
260 ReserveClientIds(serverClient
);
262 dixSaveScreens(serverClient
, SCREEN_SAVER_FORCER
, ScreenSaverReset
);
265 if (!noPanoramiXExtension
) {
266 if (!PanoramiXCreateConnectionBlock()) {
267 FatalError("could not create connection block info");
273 if (!CreateConnectionBlock()) {
274 FatalError("could not create connection block info");
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
);
286 NotifyParentProcess();
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
);
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();
307 Bool remember_it
= noPanoramiXExtension
;
309 noPanoramiXExtension
= TRUE
;
311 noPanoramiXExtension
= remember_it
;
319 for (i
= 0; i
< screenInfo
.numScreens
; i
++)
320 screenInfo
.screens
[i
]->root
= NullWindow
;
324 for (i
= screenInfo
.numScreens
- 1; i
>= 0; i
--) {
325 FreeScratchPixmapsForScreen(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
;
342 if (dispatchException
& DE_TERMINATE
) {
343 CloseWellKnownConnections();
346 OsCleanup((dispatchException
& DE_TERMINATE
) != 0);
348 if (dispatchException
& DE_TERMINATE
) {
349 ddxGiveUp(EXIT_NO_ERROR
);
353 free(ConnectionInfo
);
354 ConnectionInfo
= NULL
;