not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kdm / backend / streams.c
blob0b1e5a3032b86e64b3592d562706da82752068d4
1 /*
3 Copyright 1988, 1998 The Open Group
4 Copyright 2002,2004 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
10 documentation.
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 * streams.c - Support for STREAMS
37 #include "dm.h"
39 #if defined(XDMCP) && defined(STREAMSCONN)
41 #include "dm_error.h"
43 #include <fcntl.h>
44 #include <tiuser.h>
45 #include <netconfig.h>
46 #include <netdir.h>
48 static int xdmcpFd = -1, currentRequestPort;
50 void
51 updateListenSockets( void )
53 struct t_bind bind_addr;
54 struct netconfig *nconf;
55 struct nd_hostserv service;
56 struct nd_addrlist *servaddrs;
57 char bindbuf[15];
58 int it;
60 if (currentRequestPort == requestPort)
61 return;
62 currentRequestPort = requestPort;
64 if (xdmcpFd != -1) {
65 closeNclearCloseOnFork( xdmcpFd );
66 unregisterInput( xdmcpFd );
67 xdmcpFd = -1;
70 if (!requestPort)
71 return;
73 debug( "creating UDP stream %d\n", requestPort );
75 nconf = getnetconfigent( "udp" );
76 if (!nconf) {
77 t_error( "getnetconfigent udp" );
78 return;
81 xdmcpFd = t_open( nconf->nc_device, O_RDWR, NULL );
82 if (xdmcpFd == -1) {
83 logError( "XDMCP stream creation failed\n" );
84 t_error( "CreateWellKnownSockets(xdmcpFd): t_open failed" );
85 return;
88 service.h_host = HOST_SELF;
89 sprintf( bindbuf, "%d", requestPort );
90 service.h_serv = bindbuf;
91 netdir_getbyname( nconf, &service, &servaddrs );
92 freenetconfigent( nconf );
94 bind_addr.qlen = 5;
95 bind_addr.addr.buf = servaddrs->n_addrs[0].buf;
96 bind_addr.addr.len = servaddrs->n_addrs[0].len;
97 bind_addr.addr.maxlen = servaddrs->n_addrs[0].len;
98 it = t_bind( xdmcpFd, &bind_addr, &bind_addr );
99 netdir_free( (char *)servaddrs, ND_ADDRLIST );
100 if (it < 0) {
101 logError( "Error binding UDP port %d\n", requestPort );
102 t_error( "CreateWellKnownSockets(xdmcpFd): t_bind failed" );
103 t_close( xdmcpFd );
104 xdmcpFd = -1;
105 return;
107 registerCloseOnFork( xdmcpFd );
108 registerInput( xdmcpFd );
112 anyListenSockets( void )
114 return xdmcpFd != -1;
118 processListenSockets( fd_set *reads )
120 if (xdmcpFd >= 0 && FD_ISSET( xdmcpFd, reads )) {
121 processRequestSocket( xdmcpFd );
122 return True;
124 return False;
127 #endif /* STREAMSCONN && XDMCP */