3 Copyright 1988, 1998 The Open Group
4 Copyright 2000-2005 Oswald Buddenhagen <ossi@kde.org>
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included
13 in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of a copyright holder shall
24 not be used in advertising or otherwise to promote the sale, use or
25 other dealings in this Software without prior written authorization
26 from the copyright holder.
31 * xdm - display manager daemon
32 * Author: Keith Packard, MIT X Consortium
34 * a simple linked list of known displays
40 struct display
*displays
;
41 static struct disphist
*disphist
;
44 anyDisplaysLeft( void )
46 return displays
!= (struct display
*)0;
50 anyRunningDisplays( void )
54 for (d
= displays
; d
; d
= d
->next
)
67 anyReserveDisplays( void )
71 for (d
= displays
; d
; d
= d
->next
)
72 if ((d
->displayType
& d_lifetime
) == dReserve
)
78 idleReserveDisplays( void )
83 for (d
= displays
; d
; d
= d
->next
)
84 if (d
->status
== reserve
)
90 startReserveDisplay( int lt
)
92 struct display
*d
, *rd
;
94 for (rd
= 0, d
= displays
; d
; d
= d
->next
)
95 if (d
->status
== reserve
)
99 rd
->status
= notRunning
;
106 forEachDisplay( void (*f
)( struct display
* ) )
108 struct display
*d
, *next
;
110 for (d
= displays
; d
; d
= next
) {
118 _forEachDisplayRev( struct display
*d
, void (*f
)( struct display
* ) )
122 _forEachDisplayRev( d
->next
, f
);
128 forEachDisplayRev( void (*f
)( struct display
* ) )
130 _forEachDisplayRev( displays
, f
);
135 findDisplayByName( const char *name
)
139 for (d
= displays
; d
; d
= d
->next
)
140 if (!strcmp( name
, d
->name
))
146 findDisplayByPid( int pid
)
150 for (d
= displays
; d
; d
= d
->next
)
157 findDisplayByServerPid( int serverPid
)
161 for (d
= displays
; d
; d
= d
->next
)
162 if (serverPid
== d
->serverPid
)
170 findDisplayBySessionID( CARD32 sessionID
)
174 for (d
= displays
; d
; d
= d
->next
)
175 if (sessionID
== d
->sessionID
)
181 findDisplayByAddress( XdmcpNetaddr addr
, int addrlen
, CARD16 displayNumber
)
185 for (d
= displays
; d
; d
= d
->next
)
186 if ((d
->displayType
& d_origin
) == dFromXDMCP
&&
187 d
->displayNumber
== displayNumber
&&
188 addressEqual( (XdmcpNetaddr
)d
->from
.data
, d
->from
.length
,
196 #define IfFree(x) if (x) free( (char *)x )
199 removeDisplay( struct display
*old
)
201 struct display
*d
, **dp
;
204 for (dp
= &displays
; (d
= *dp
); dp
= &(*dp
)->next
) {
206 debug( "Removing display %s\n", d
->name
);
209 IfFree( d
->cfg
.data
);
210 delStr( d
->cfg
.dep
.name
);
212 IfFree( d
->remoteHost
);
214 if (d
->authorizations
) {
215 for (i
= 0; i
< d
->authNum
; i
++)
216 XauDisposeAuth( d
->authorizations
[i
] );
217 free( (char *)d
->authorizations
);
220 (void)unlink( d
->authFile
);
223 IfFree( d
->authNameLens
);
225 XdmcpDisposeARRAY8( &d
->peer
);
226 XdmcpDisposeARRAY8( &d
->from
);
227 XdmcpDisposeARRAY8( &d
->clientAddr
);
235 static struct disphist
*
236 findHist( const char *name
)
238 struct disphist
*hstent
;
240 for (hstent
= disphist
; hstent
; hstent
= hstent
->next
)
241 if (!strcmp( hstent
->name
, name
))
247 newDisplay( const char *name
)
250 struct disphist
*hstent
;
252 if (!(hstent
= findHist( name
))) {
253 if (!(hstent
= Calloc( 1, sizeof(*hstent
) )))
255 if (!strDup( &hstent
->name
, name
)) {
259 hstent
->next
= disphist
; disphist
= hstent
;
262 if (!(d
= (struct display
*)Calloc( 1, sizeof(*d
) )))
266 d
->name
= hstent
->name
;
267 /* initialize fields (others are 0) */
282 debug( "created new display %s\n", d
->name
);
287 displayName( struct display
*d
)
289 return memcmp( d
->name
, "localhost:", 10 ) ? d
->name
: d
->name
+ 9;