~ubuntu-branches/ubuntu/raring/kdebase-workspace/raring

« back to all changes in this revision

Viewing changes to .pc/kdm_X_path.diff/kdm/backend/server.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas, Jonathan Thomas, Tarun Kumar Mall, Philip Muškovac, Stéphane Graber, James Hunt
  • Date: 2011-06-01 02:09:54 UTC
  • mfrom: (0.1.21 sid)
  • Revision ID: james.westby@ubuntu.com-20110601020954-id2t0x9rwxwrmjn2
Tags: 4:4.6.3-1ubuntu1
[ Jonathan Thomas ]
* Merge with Debian Unstable, remaining changes:
  - Add kdebase-workspace-wallpapers.{links, install}
  - Add kdebase-workspace-data.links
  - kdebase-workspace-data.install: don't add wallpapers that are in
    kdebase-workspace-wallpapers.install
  - Add kdm.{links, upstart}
  - kdm.logrotate: rotate 2 -> rotate 7
  - Make kdm work with upstart in kdm.prerm, kdm.postrm, kdm.postinst
  - debian/control:
    - don't build against libggadget-1.0-dev, libggadget-qt-1.0-dev
      (they are in Universe)
    - Build against libbost1.46-dev instead of libboost-dev
    - Add libxml2-dev, libpolkit-qt-1-dev to build-deps
    - Add python-kde4, python-sip, python-qt4 to build-dependencies
    - Keep bumped our replaces/breaks
    - plasma-netbook replaces plasma-widgets-workspace (<= 4:4.5.2-1ubuntu1)
    - kdebase-workspace-bin suggests plasma-scriptengines instead of
      recommend
    - kdebase-workspace-data depends on oxygen-cursor-theme instead of oxygencursors
    - Keep kdebase-workspace-wallpapers
    - plasma-dataengines-workspace replaces plasma-widget-workspace (<= 4:4.5.2-1ubuntu1)
    - plasma-widgets-workspace depends on akonadi-server and kdepim-runtime
    - plasma-scriptengines not depends on plasma-scriptengine-googlegadgets
    - plasma-scriptengine-ruby depends on libkde4-ruby
    - Don't build plasma-scriptengine-googlegadgets
    - freespacenotifier replaces kdebase-workspace-data (<= 4:4.5.2-1ubuntu1)
      and kdebase-workspace-bin (<= 4:4.5.2-1ubuntu1)
    - kinfocenter replaces kdebase-workspace-bin and systemsettings
    - libplasmagenericshell4 replaces plasma-widgets-workspace (<= 4:4.5.2-1ubuntu1)
  - debian/patches:
    - Use 07_kdmrc_defaults_kubuntu.diff instead of 07_kdmrc_defaults.diff
    - Don't add be_better_at_honouring_user_kdm_theming
    - Don't add use_dejavu_as_default_font
    - Don't add fix_target_link_libraries
    - Keep our patches
* Try a polkit-kde-1 | policykit-gnome-1 or-dependency again to see if policykit-1-gnome
  is a suitable policykit solution a year later.

[ Tarun Kumar Mall ]
* New uptream release
* Bumped kde-sc-dev-latest version to 4.6.3
* Removed patches kubuntu_120_ksysguard_sensors.diff and
  kubuntu_121_kdm_halt_cmd.diff, applied upstream
* Refreshed kubuntu_122_akonadi_calendar_dataengine.diff 

[ Philip Muškovac ]
* drop kubuntu_123_effectframe_glflush.diff, applied upstream
* Refresh symbol files 

[ Stéphane Graber ]
* Updated Vcs fields to point to kubuntu-uploaders instead of
  kubuntu-members

[ James Hunt ]
* Updated kdm.conf to fix kdm in single user mode (LP: #436936)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright 1988, 1998  The Open Group
 
4
Copyright 2001,2003,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
 * server.c - manage the X server
 
35
 */
 
36
 
 
37
#include "dm.h"
 
38
#include "dm_error.h"
 
39
#include "dm_socket.h"
 
40
 
 
41
#include <X11/Xlib.h>
 
42
 
 
43
#include <stdio.h>
 
44
#include <signal.h>
 
45
 
 
46
 
 
47
struct display *startingServer;
 
48
time_t serverTimeout = TO_INF;
 
49
 
 
50
char **
 
51
prepareServerArgv(struct display *d, const char *args)
 
52
{
 
53
    char **argv;
 
54
#ifdef HAVE_VTS
 
55
    char vtstr[8];
 
56
#endif
 
57
 
 
58
    if (!(argv = parseArgs(0, d->serverCmd)) ||
 
59
        !(argv = addStrArr(argv, d->name, -1)))
 
60
        exit(47);
 
61
#ifdef HAVE_VTS
 
62
    if (d->serverVT &&
 
63
        !(argv = addStrArr(argv, vtstr,
 
64
                           sprintf(vtstr, "vt%d", d->serverVT))))
 
65
        exit(47);
 
66
#endif
 
67
    if (!(argv = parseArgs(argv, args)))
 
68
        exit(47);
 
69
 
 
70
    if (!changeUser(d->serverUID, d->authFile))
 
71
        exit(47);
 
72
 
 
73
    return argv;
 
74
}
 
75
 
 
76
static void
 
77
startServerOnce(void)
 
78
{
 
79
    struct display *d = startingServer;
 
80
    char **argv;
 
81
 
 
82
    debug("startServerOnce for %s, try %d\n", d->name, ++d->startTries);
 
83
    d->serverStatus = starting;
 
84
    switch (Fork(&d->serverPid)) {
 
85
    case 0:
 
86
        argv = prepareServerArgv(d, d->serverArgsLocal);
 
87
        if (d->authFile) {
 
88
            if (!(argv = addStrArr(argv, "-auth", 5)) ||
 
89
                !(argv = addStrArr(argv, d->authFile, -1)))
 
90
                exit(47);
 
91
        }
 
92
        debug("exec %\"[s\n", argv);
 
93
        /*
 
94
         * give the server SIGUSR1 ignored,
 
95
         * it will notice that and send SIGUSR1
 
96
         * when ready
 
97
         */
 
98
        (void)Signal(SIGUSR1, SIG_IGN);
 
99
        (void)execv(argv[0], argv);
 
100
        logError("X server %\"s cannot be executed\n", argv[0]);
 
101
        exit(47);
 
102
    case -1:
 
103
        logError("X server fork failed\n");
 
104
        startServerFailed();
 
105
        break;
 
106
    default:
 
107
        debug("X server forked, pid %d\n", d->serverPid);
 
108
        serverTimeout = d->serverTimeout + now;
 
109
        break;
 
110
    }
 
111
}
 
112
 
 
113
void
 
114
startServer(struct display *d)
 
115
{
 
116
    startingServer = d;
 
117
    d->startTries = 0;
 
118
    startServerOnce();
 
119
}
 
120
 
 
121
void
 
122
abortStartServer(struct display *d)
 
123
{
 
124
    if (startingServer == d) {
 
125
        if (d->serverStatus != ignore) {
 
126
            d->serverStatus = ignore;
 
127
            serverTimeout = TO_INF;
 
128
            debug("aborting X server start\n");
 
129
        }
 
130
        startingServer = 0;
 
131
    }
 
132
}
 
133
 
 
134
void
 
135
startServerSuccess()
 
136
{
 
137
    struct display *d = startingServer;
 
138
    d->serverStatus = ignore;
 
139
    serverTimeout = TO_INF;
 
140
    debug("X server ready, starting session\n");
 
141
    startDisplayP2(d);
 
142
}
 
143
 
 
144
void
 
145
startServerFailed()
 
146
{
 
147
    struct display *d = startingServer;
 
148
    if (!d->serverAttempts || d->startTries < d->serverAttempts) {
 
149
        d->serverStatus = pausing;
 
150
        serverTimeout = d->openDelay + now;
 
151
    } else {
 
152
        d->serverStatus = ignore;
 
153
        serverTimeout = TO_INF;
 
154
        startingServer = 0;
 
155
        logError("X server for display %s cannot be started,"
 
156
                 " session disabled\n", d->name);
 
157
        stopDisplay(d);
 
158
    }
 
159
}
 
160
 
 
161
void
 
162
startServerTimeout()
 
163
{
 
164
    struct display *d = startingServer;
 
165
    switch (d->serverStatus) {
 
166
    case ignore:
 
167
    case awaiting:
 
168
        break; /* cannot happen */
 
169
    case starting:
 
170
        logError("X server startup timeout, terminating\n");
 
171
        kill(d->serverPid, SIGTERM);
 
172
        d->serverStatus = terminated;
 
173
        serverTimeout = d->serverTimeout + now;
 
174
        break;
 
175
    case terminated:
 
176
        logInfo("X server termination timeout, killing\n");
 
177
        kill(d->serverPid, SIGKILL);
 
178
        d->serverStatus = killed;
 
179
        serverTimeout = 10 + now;
 
180
        break;
 
181
    case killed:
 
182
        logInfo("X server is stuck in D state; leaving it alone\n");
 
183
        startServerFailed();
 
184
        break;
 
185
    case pausing:
 
186
        startServerOnce();
 
187
        break;
 
188
    }
 
189
}
 
190
 
 
191
 
 
192
Display *dpy;
 
193
 
 
194
/*
 
195
 * this code is complicated by some TCP failings.  On
 
196
 * many systems, the connect will occasionally hang forever,
 
197
 * this trouble is avoided by setting up a timeout to Longjmp
 
198
 * out of the connect (possibly leaving piles of garbage around
 
199
 * inside Xlib) and give up, terminating the server.
 
200
 */
 
201
 
 
202
static Jmp_buf openAbort;
 
203
 
 
204
/* ARGSUSED */
 
205
static void
 
206
abortOpen(int n ATTR_UNUSED)
 
207
{
 
208
    Longjmp(openAbort, 1);
 
209
}
 
210
 
 
211
#ifdef XDMCP
 
212
 
 
213
#ifdef STREAMSCONN
 
214
# include <tiuser.h>
 
215
#endif
 
216
 
 
217
static void
 
218
getRemoteAddress(struct display *d, int fd)
 
219
{
 
220
    char buf[512];
 
221
    int len = sizeof(buf);
 
222
#ifdef STREAMSCONN
 
223
    struct netbuf netb;
 
224
#endif
 
225
 
 
226
    XdmcpDisposeARRAY8(&d->peer);
 
227
#ifdef STREAMSCONN
 
228
    netb.maxlen = sizeof(buf);
 
229
    netb.buf = buf;
 
230
    t_getname(fd, &netb, REMOTENAME);
 
231
    len = 8;
 
232
    /* lucky for us, t_getname returns something that looks like a sockaddr */
 
233
#else
 
234
    getpeername(fd, (struct sockaddr *)buf, (void *)&len);
 
235
#endif
 
236
    if (len && XdmcpAllocARRAY8(&d->peer, len))
 
237
        memmove(d->peer.data, buf, len);
 
238
    debug("got remote address %s %d\n", d->name, d->peer.length);
 
239
}
 
240
 
 
241
#endif /* XDMCP */
 
242
 
 
243
static int
 
244
openErrorHandler(Display *dspl)
 
245
{
 
246
    logError("IO Error in XOpenDisplay(%s)\n", DisplayString(dspl));
 
247
    exit(EX_OPENFAILED_DPY);
 
248
    /*NOTREACHED*/
 
249
    return (0);
 
250
}
 
251
 
 
252
void
 
253
waitForServer(struct display *d)
 
254
{
 
255
    volatile int i;
 
256
    /* static int i; */
 
257
 
 
258
    i = 0;
 
259
    do {
 
260
        (void)Signal(SIGALRM, abortOpen);
 
261
        (void)alarm((unsigned)d->openTimeout);
 
262
        if (!Setjmp(openAbort)) {
 
263
            debug("before XOpenDisplay(%s)\n", d->name);
 
264
            errno = 0;
 
265
            (void)XSetIOErrorHandler(openErrorHandler);
 
266
            dpy = XOpenDisplay(d->name);
 
267
#ifdef STREAMSCONN
 
268
            {
 
269
                /* For some reason, the next XOpenDisplay we do is
 
270
                   going to fail, so we might as well get that out
 
271
                   of the way.  There is something broken here. */
 
272
                Display *bogusDpy = XOpenDisplay(d->name);
 
273
                debug("bogus XOpenDisplay %s\n",
 
274
                      bogusDpy ? "succeeded" : "failed");
 
275
                if (bogusDpy)
 
276
                    XCloseDisplay(bogusDpy);    /* just in case */
 
277
            }
 
278
#endif
 
279
            (void)alarm((unsigned)0);
 
280
            (void)Signal(SIGALRM, SIG_DFL);
 
281
            (void)XSetIOErrorHandler((int (*)(Display *)) 0);
 
282
            debug("after XOpenDisplay(%s)\n", d->name);
 
283
            if (dpy) {
 
284
#ifdef XDMCP
 
285
                if ((d->displayType & d_location) == dForeign)
 
286
                    getRemoteAddress(d, ConnectionNumber(dpy));
 
287
#endif
 
288
                registerCloseOnFork(ConnectionNumber(dpy));
 
289
                return;
 
290
            }
 
291
            debug("OpenDisplay(%s) attempt %d failed: %m\n", d->name, i + 1);
 
292
            sleep((unsigned)d->openDelay);
 
293
        } else {
 
294
            logError("Hung in XOpenDisplay(%s), aborting\n", d->name);
 
295
            (void)Signal(SIGALRM, SIG_DFL);
 
296
            break;
 
297
        }
 
298
    } while (++i < d->openRepeat);
 
299
    logError("Cannot connect to %s, giving up\n", d->name);
 
300
    exit(EX_OPENFAILED_DPY);
 
301
}
 
302
 
 
303
 
 
304
void
 
305
resetServer(struct display *d)
 
306
{
 
307
    if (dpy && (d->displayType & d_origin) != dFromXDMCP)
 
308
        pseudoReset();
 
309
}
 
310
 
 
311
 
 
312
static Jmp_buf pingTime;
 
313
 
 
314
static void
 
315
pingLost(void)
 
316
{
 
317
    Longjmp(pingTime, 1);
 
318
}
 
319
 
 
320
/* ARGSUSED */
 
321
static int
 
322
pingLostIOErr(Display *dspl ATTR_UNUSED)
 
323
{
 
324
    pingLost();
 
325
    return 0;
 
326
}
 
327
 
 
328
/* ARGSUSED */
 
329
static void
 
330
pingLostSig(int n ATTR_UNUSED)
 
331
{
 
332
    pingLost();
 
333
}
 
334
 
 
335
int
 
336
pingServer(struct display *d)
 
337
{
 
338
    int (*oldError)(Display *);
 
339
    void (*oldSig)(int);
 
340
    int oldAlarm;
 
341
 
 
342
    oldError = XSetIOErrorHandler(pingLostIOErr);
 
343
    oldAlarm = alarm(0);
 
344
    oldSig = Signal(SIGALRM, pingLostSig);
 
345
    (void)alarm(d->pingTimeout * 60);
 
346
    if (!Setjmp(pingTime)) {
 
347
        debug("ping X server\n");
 
348
        XSync(dpy, 0);
 
349
    } else {
 
350
        debug("X server dead\n");
 
351
        (void)alarm(0);
 
352
        (void)Signal(SIGALRM, SIG_DFL);
 
353
        XSetIOErrorHandler(oldError);
 
354
        return False;
 
355
    }
 
356
    (void)alarm(0);
 
357
    (void)Signal(SIGALRM, oldSig);
 
358
    (void)alarm(oldAlarm);
 
359
    debug("X server alive\n");
 
360
    XSetIOErrorHandler(oldError);
 
361
    return True;
 
362
}