~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kdm/backend/dpylist.c

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright 1988, 1998  The Open Group
 
4
Copyright 2000-2005 Oswald Buddenhagen <ossi@kde.org>
 
5
 
 
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.
 
11
 
 
12
The above copyright notice and this permission notice shall be included
 
13
in all copies or substantial portions of the Software.
 
14
 
 
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.
 
22
 
 
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.
 
27
 
 
28
*/
 
29
 
 
30
/*
 
31
 * xdm - display manager daemon
 
32
 * Author: Keith Packard, MIT X Consortium
 
33
 *
 
34
 * a simple linked list of known displays
 
35
 */
 
36
 
 
37
#include "dm.h"
 
38
#include "dm_error.h"
 
39
 
 
40
struct display *displays;
 
41
static struct disphist *disphist;
 
42
 
 
43
int
 
44
anyDisplaysLeft(void)
 
45
{
 
46
    return displays != 0;
 
47
}
 
48
 
 
49
int
 
50
anyRunningDisplays(void)
 
51
{
 
52
    struct display *d;
 
53
 
 
54
    for (d = displays; d; d = d->next)
 
55
        switch (d->status) {
 
56
        case notRunning:
 
57
        case textMode:
 
58
        case reserve:
 
59
            break;
 
60
        default:
 
61
            return True;
 
62
        }
 
63
    return False;
 
64
}
 
65
 
 
66
int
 
67
anyReserveDisplays(void)
 
68
{
 
69
    struct display *d;
 
70
 
 
71
    for (d = displays; d; d = d->next)
 
72
        if ((d->displayType & d_lifetime) == dReserve)
 
73
            return True;
 
74
    return False;
 
75
}
 
76
 
 
77
int
 
78
idleReserveDisplays(void)
 
79
{
 
80
    struct display *d;
 
81
    int cnt = 0;
 
82
 
 
83
    for (d = displays; d; d = d->next)
 
84
        if (d->status == reserve)
 
85
            cnt++;
 
86
    return cnt;
 
87
}
 
88
 
 
89
int
 
90
startReserveDisplay(void)
 
91
{
 
92
    struct display *d, *rd;
 
93
 
 
94
    for (rd = 0, d = displays; d; d = d->next)
 
95
        if (d->status == reserve)
 
96
            rd = d;
 
97
    if (rd) {
 
98
        rd->status = notRunning;
 
99
        return True;
 
100
    }
 
101
    return False;
 
102
}
 
103
 
 
104
void
 
105
forEachDisplay(void (*f)(struct display *))
 
106
{
 
107
    struct display *d, *next;
 
108
 
 
109
    for (d = displays; d; d = next) {
 
110
        next = d->next;
 
111
        (*f)(d);
 
112
    }
 
113
}
 
114
 
 
115
#ifdef HAVE_VTS
 
116
static void
 
117
_forEachDisplayRev(struct display *d, void (*f)(struct display *))
 
118
{
 
119
    if (d) {
 
120
        if (d->next)
 
121
            _forEachDisplayRev(d->next, f);
 
122
        (*f)(d);
 
123
    }
 
124
}
 
125
 
 
126
void
 
127
forEachDisplayRev(void (*f)(struct display *))
 
128
{
 
129
    _forEachDisplayRev(displays, f);
 
130
}
 
131
#endif
 
132
 
 
133
struct display *
 
134
findDisplayByName(const char *name)
 
135
{
 
136
    struct display *d;
 
137
 
 
138
    for (d = displays; d; d = d->next)
 
139
        if (!strcmp(name, d->name))
 
140
            return d;
 
141
    return 0;
 
142
}
 
143
 
 
144
struct display *
 
145
findDisplayByPid(int pid)
 
146
{
 
147
    struct display *d;
 
148
 
 
149
    for (d = displays; d; d = d->next)
 
150
        if (pid == d->pid)
 
151
            return d;
 
152
    return 0;
 
153
}
 
154
 
 
155
struct display *
 
156
findDisplayByServerPid(int serverPid)
 
157
{
 
158
    struct display *d;
 
159
 
 
160
    for (d = displays; d; d = d->next)
 
161
        if (serverPid == d->serverPid)
 
162
            return d;
 
163
    return 0;
 
164
}
 
165
 
 
166
#ifdef XDMCP
 
167
 
 
168
struct display *
 
169
findDisplayBySessionID(CARD32 sessionID)
 
170
{
 
171
    struct display *d;
 
172
 
 
173
    for (d = displays; d; d = d->next)
 
174
        if (sessionID == d->sessionID)
 
175
            return d;
 
176
    return 0;
 
177
}
 
178
 
 
179
struct display *
 
180
findDisplayByAddress(XdmcpNetaddr addr, int addrlen, CARD16 displayNumber)
 
181
{
 
182
    struct display *d;
 
183
 
 
184
    for (d = displays; d; d = d->next)
 
185
        if ((d->displayType & d_origin) == dFromXDMCP &&
 
186
            d->displayNumber == displayNumber &&
 
187
            addressEqual((XdmcpNetaddr)d->from.data, d->from.length,
 
188
                         addr, addrlen))
 
189
            return d;
 
190
    return 0;
 
191
}
 
192
 
 
193
#endif /* XDMCP */
 
194
 
 
195
void
 
196
removeDisplay(struct display *old)
 
197
{
 
198
    struct display *d, **dp;
 
199
    int i;
 
200
 
 
201
    for (dp = &displays; (d = *dp); dp = &(*dp)->next) {
 
202
        if (d == old) {
 
203
            debug("Removing display %s\n", d->name);
 
204
            *dp = d->next;
 
205
            free(d->class2);
 
206
            free(d->cfg.data);
 
207
            delStr(d->cfg.dep.name);
 
208
#ifdef XDMCP
 
209
            free(d->remoteHost);
 
210
#endif
 
211
            if (d->authorizations) {
 
212
                for (i = 0; i < d->authNum; i++)
 
213
                    XauDisposeAuth(d->authorizations[i]);
 
214
                free(d->authorizations);
 
215
            }
 
216
            if (d->authFile) {
 
217
                (void)unlink(d->authFile);
 
218
                free(d->authFile);
 
219
            }
 
220
            if (d->greeterAuthFile) {
 
221
                (void)unlink(d->greeterAuthFile);
 
222
                free(d->greeterAuthFile);
 
223
            }
 
224
#ifdef XDMCP
 
225
            XdmcpDisposeARRAY8(&d->peer);
 
226
            XdmcpDisposeARRAY8(&d->from);
 
227
            XdmcpDisposeARRAY8(&d->clientAddr);
 
228
#endif
 
229
            free(d);
 
230
            break;
 
231
        }
 
232
    }
 
233
}
 
234
 
 
235
static struct disphist *
 
236
findHist(const char *name)
 
237
{
 
238
    struct disphist *hstent;
 
239
 
 
240
    for (hstent = disphist; hstent; hstent = hstent->next)
 
241
        if (!strcmp(hstent->name, name))
 
242
            return hstent;
 
243
    return 0;
 
244
}
 
245
 
 
246
struct display *
 
247
newDisplay(const char *name)
 
248
{
 
249
    struct display *d;
 
250
    struct disphist *hstent;
 
251
 
 
252
    if (!(hstent = findHist(name))) {
 
253
        if (!(hstent = Calloc(1, sizeof(*hstent))))
 
254
            return 0;
 
255
        if (!strDup(&hstent->name, name)) {
 
256
            free(hstent);
 
257
            return 0;
 
258
        }
 
259
        hstent->next = disphist;
 
260
        disphist = hstent;
 
261
    }
 
262
 
 
263
    if (!(d = Calloc(1, sizeof(*d))))
 
264
        return 0;
 
265
    d->next = displays;
 
266
    d->hstent = hstent;
 
267
    d->name = hstent->name;
 
268
    /* initialize fields (others are 0) */
 
269
    d->pid = -1;
 
270
    d->serverPid = -1;
 
271
    d->ctrl.fd = -1;
 
272
    d->pipe.fd.r = -1;
 
273
    d->gpipe.fd.r = -1;
 
274
#ifndef SINGLE_PIPE
 
275
    d->pipe.fd.w = -1;
 
276
    d->gpipe.fd.w = -1;
 
277
#endif
 
278
    d->userSess = -1;
 
279
#ifdef XDMCP
 
280
    d->xdmcpFd = -1;
 
281
#endif
 
282
    displays = d;
 
283
    debug("created new display %s\n", d->name);
 
284
    return d;
 
285
}
 
286
 
 
287
const char *
 
288
displayName(struct display *d)
 
289
{
 
290
    return memcmp(d->name, "localhost:", 10) ? d->name : d->name + 9;
 
291
}