~darkxst/ubuntu/saucy/gdm/lp1212408

« back to all changes in this revision

Viewing changes to daemon/getvt.c

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2008-09-02 10:37:20 UTC
  • mfrom: (1.4.27 upstream)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: james.westby@ubuntu.com-20080902103720-p810vv530hqj45wg
Tags: 2.20.7-3
* Install the debian-moreblue-orbit theme, thanks Andre Luiz Rodrigues 
  Ferreira. Closes: #497440.
* 35_gdm.conf.patch: make it the default.
* copyright: fix encoding.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <sys/stat.h>
30
30
#include <sys/types.h>
31
31
 
 
32
#include <X11/Xlib.h>
 
33
#include <X11/Xatom.h>
 
34
 
32
35
#include "gdm.h"
33
36
#include "misc.h"
34
37
#include "getvt.h"
35
 
#include "gdmconfig.h"
36
 
 
37
 
/* Virtual terminals only supported on Linux, FreeBSD, or DragonFly */
38
 
 
39
 
#if defined (__linux__) || defined (__FreeBSD__) || defined (__DragonFly__)
40
 
 
41
 
#if defined (__linux__)
 
38
#include "display.h"
 
39
 
 
40
#include "gdm-common.h"
 
41
#include "gdm-daemon-config.h"
 
42
#include "gdm-log.h"
 
43
 
 
44
/*
 
45
 * Get the VT number associated with the display via the XFree86_VT
 
46
 * Atom.
 
47
 */
 
48
long
 
49
gdm_get_current_vtnum (Display *display)
 
50
{
 
51
        Atom prop;
 
52
        Atom actualtype;
 
53
        int actualformat;
 
54
        unsigned long nitems;
 
55
        unsigned long bytes_after;
 
56
        unsigned char *buf;
 
57
        unsigned long num;
 
58
 
 
59
        if (display == NULL)
 
60
                return -1;
 
61
 
 
62
        prop = XInternAtom (display, "XFree86_VT", True);
 
63
        if (prop == None) {
 
64
                gdm_debug ("no XFree86_VT atom\n");
 
65
                return -1;
 
66
        }
 
67
        if (XGetWindowProperty (display, DefaultRootWindow (display), prop, 0, 1,
 
68
                False, AnyPropertyType, &actualtype, &actualformat,
 
69
                &nitems, &bytes_after, &buf)) {
 
70
                gdm_debug ("no XFree86_VT property\n");
 
71
                return -1;
 
72
        }
 
73
        if (nitems != 1) {
 
74
                gdm_debug ("%lu items in XFree86_VT property!\n", nitems);
 
75
                XFree (buf);
 
76
                return -1;
 
77
        }
 
78
 
 
79
        switch (actualtype) {
 
80
        case XA_CARDINAL:
 
81
        case XA_INTEGER:
 
82
        case XA_WINDOW:
 
83
                switch (actualformat) {
 
84
                case  8:
 
85
                        num = (*(uint8_t  *)(void *)buf);
 
86
                        break;
 
87
                case 16:
 
88
                        num = (*(uint16_t *)(void *)buf);
 
89
                        break;
 
90
                case 32:
 
91
                        num = (*(uint32_t *)(void *)buf);
 
92
                        break;
 
93
                default:
 
94
                        gdm_debug ("format %d in XFree86_VT property!\n", actualformat);
 
95
                        XFree (buf);
 
96
                        return -1;
 
97
                }
 
98
                break;
 
99
        default:
 
100
                gdm_debug ("type %lx in XFree86_VT property!\n", actualtype);
 
101
                XFree (buf);
 
102
                return -1;
 
103
        }
 
104
        XFree (buf);
 
105
        return num;
 
106
}
 
107
 
 
108
#if defined (GDM_USE_SYS_VT)
42
109
#include <sys/vt.h>
43
 
#elif defined (__FreeBSD__) || defined (__DragonFly__)
 
110
#elif defined (GDM_USE_CONSIO_VT)
44
111
#include <sys/consio.h>
45
112
 
46
113
static const char*
58
125
}
59
126
#endif
60
127
 
 
128
 
 
129
gchar *
 
130
gdm_get_vt_device (int vtno)
 
131
{
 
132
   gchar *vtname = NULL;
 
133
 
 
134
#if defined (GDM_USE_SYS_VT)
 
135
#ifdef __sun
 
136
     vtname = g_strdup_printf ("/dev/vt/%d", vtno);
 
137
#else
 
138
     vtname = g_strdup_printf ("/dev/tty%d", vtno);
 
139
#endif
 
140
#elif defined (GDM_USE_CONSIO_VT)
 
141
     vtname = g_strdup_printf ("/dev/ttyv%s", __itovty (vtno - 1));
 
142
#endif
 
143
 
 
144
   return vtname;
 
145
}
 
146
 
 
147
#if defined (GDM_USE_SYS_VT) || defined (GDM_USE_CONSIO_VT)
 
148
 
 
149
#ifdef __sun
 
150
#define GDMCONSOLEDEVICE "/dev/vt/0"
 
151
#else
 
152
#define GDMCONSOLEDEVICE "/dev/console"
 
153
#endif
 
154
 
 
155
 
61
156
static int
62
157
open_vt (int vtno)
63
158
{
64
 
        char *vtname;
65
 
        int fd;
66
 
 
67
 
#if defined (__linux__)
68
 
        vtname = g_strdup_printf ("/dev/tty%d", vtno);
69
 
#elif defined (__FreeBSD__) || defined (__DragonFly__)
70
 
        vtname = g_strdup_printf ("/dev/ttyv%s", __itovty (vtno - 1));
71
 
#endif
 
159
        char *vtname = NULL;
 
160
        int fd = -1;
 
161
 
 
162
        vtname = gdm_get_vt_device (vtno);
 
163
 
72
164
        do {
73
165
                errno = 0;
74
166
                fd = open (vtname, O_RDWR
77
169
#endif
78
170
                           , 0);
79
171
        } while G_UNLIKELY (errno == EINTR);
 
172
 
80
173
        g_free (vtname);
 
174
 
81
175
        return fd;
82
176
}
83
177
 
84
 
#if defined (__linux__)
 
178
#if defined (GDM_USE_SYS_VT)
85
179
 
86
180
static int 
87
 
get_free_vt_linux (int *vtfd)
 
181
get_free_vt_sys (int *vtfd)
88
182
{
89
183
        int fd, fdv;
90
184
        int vtno;
95
189
 
96
190
        do {
97
191
                errno = 0;
98
 
                fd = open ("/dev/console", O_WRONLY
 
192
                fd = open (GDMCONSOLEDEVICE,
 
193
                           O_WRONLY
99
194
#ifdef O_NOCTTY
100
195
                           |O_NOCTTY
101
196
#endif
109
204
                return -1;
110
205
        }
111
206
 
112
 
        for (vtno = gdm_get_value_int (GDM_KEY_FIRST_VT), vtmask = 1 << vtno;
 
207
        for (vtno = gdm_daemon_config_get_value_int (GDM_KEY_FIRST_VT), vtmask = 1 << vtno;
113
208
                        vtstat.v_state & vtmask; vtno++, vtmask <<= 1);
114
209
        if (!vtmask) {
115
210
                VE_IGNORE_EINTR (close (fd));
125
220
        return vtno;
126
221
}
127
222
 
128
 
#elif defined (__FreeBSD__) || defined (__DragonFly__)
 
223
#elif defined (GDM_USE_CONSIO_VT)
129
224
 
130
225
static int
131
 
get_free_vt_freebsd_dragonfly (int *vtfd)
 
226
get_free_vt_consio (int *vtfd)
132
227
{
133
228
        int fd, fdv;
134
229
        int vtno;
138
233
 
139
234
        do {
140
235
                errno = 0;
141
 
                fd = open ("/dev/console", O_WRONLY
 
236
                fd = open (GDMCONSOLEDEVICE,
 
237
                           O_WRONLY
142
238
#ifdef O_NOCTTY
143
239
                           |O_NOCTTY
144
240
#endif
158
254
                return -1;
159
255
        }
160
256
 
161
 
        while (vtno < gdm_get_value_int (GDM_KEY_FIRST_VT)) {
 
257
        while (vtno < gdm_daemon_config_get_value_int (GDM_KEY_FIRST_VT)) {
162
258
                int oldvt = vtno;
163
259
                to_close_vts = g_list_prepend (to_close_vts,
164
260
                                               GINT_TO_POINTER (fdv));
194
290
char *
195
291
gdm_get_empty_vt_argument (int *fd, int *vt)
196
292
{
197
 
        if ( ! gdm_get_value_bool (GDM_KEY_VT_ALLOCATION)) {
 
293
        if ( ! gdm_daemon_config_get_value_bool (GDM_KEY_VT_ALLOCATION)) {
198
294
                *fd = -1;
199
295
                return NULL;
200
296
        }
201
297
 
202
 
#if defined (__linux__)
203
 
        *vt = get_free_vt_linux (fd);
204
 
#elif defined (__FreeBSD__) || defined (__DragonFly__)
205
 
        *vt = get_free_vt_freebsd_dragonfly (fd);
 
298
#if defined (GDM_USE_SYS_VT)
 
299
        *vt = get_free_vt_sys (fd);
 
300
#elif defined (GDM_USE_CONSIO_VT)
 
301
        *vt = get_free_vt_consio (fd);
206
302
#endif
207
303
 
208
304
        if (*vt < 0)
216
312
gdm_change_vt (int vt)
217
313
{
218
314
        int fd;
 
315
        int rc;
219
316
        if (vt < 0)
220
317
                return;
221
318
 
222
319
        do {
223
320
                errno = 0;
224
 
                fd = open ("/dev/console", O_WRONLY
 
321
                fd = open (GDMCONSOLEDEVICE,
 
322
                           O_WRONLY
225
323
#ifdef O_NOCTTY
226
324
                           |O_NOCTTY
227
325
#endif
230
328
        if (fd < 0)
231
329
                return;
232
330
 
233
 
        ioctl (fd, VT_ACTIVATE, vt);
234
 
        ioctl (fd, VT_WAITACTIVE, vt);
 
331
        rc = ioctl (fd, VT_ACTIVATE, vt);
 
332
        rc = ioctl (fd, VT_WAITACTIVE, vt);
235
333
 
236
334
        VE_IGNORE_EINTR (close (fd));
237
335
}
238
336
 
239
337
int
240
 
gdm_get_cur_vt (void)
 
338
gdm_get_current_vt (void)
241
339
{
242
 
#if defined (__linux__)
 
340
#if defined (GDM_USE_SYS_VT)
243
341
        struct vt_stat s;
244
 
#elif defined (__FreeBSD__) || defined (__DragonFly__)
 
342
#elif defined (GDM_USE_CONSIO_VT)
245
343
        int vtno;
246
344
#endif
247
345
        int fd;
248
346
 
249
347
        do {
250
348
                errno = 0;
251
 
                fd = open ("/dev/console", O_WRONLY
 
349
                fd = open (GDMCONSOLEDEVICE,
 
350
                           O_WRONLY
252
351
#ifdef O_NOCTTY
253
352
                           |O_NOCTTY
254
353
#endif
256
355
        } while G_UNLIKELY (errno == EINTR);
257
356
        if (fd < 0)
258
357
                return -1;
259
 
#if defined (__linux__)
 
358
#if defined (GDM_USE_SYS_VT)
260
359
        ioctl (fd, VT_GETSTATE, &s);
261
360
 
262
361
        VE_IGNORE_EINTR (close (fd));
267
366
        */
268
367
 
269
368
        return s.v_active;
270
 
#elif defined (__FreeBSD__) || defined (__DragonFly__)
 
369
#elif defined (GDM_USE_CONSIO_VT)
271
370
        if (ioctl (fd, VT_GETACTIVE, &vtno) == -1) {
272
371
                VE_IGNORE_EINTR (close (fd));
273
372
                return -1;
274
373
        }
275
374
 
276
 
        VE_IGNORE_EINTR (close (fd));
 
375
VE_IGNORE_EINTR (close (fd));
277
376
 
278
377
        /* debug */
279
378
        /*
284
383
#endif
285
384
}
286
385
 
287
 
#else /* here this is just a stub, we don't know how to do this outside
288
 
         of linux really */
 
386
#else /* GDM_USE_SYS_VT || GDM_USE_CONSIO_VT - Here this is just
 
387
       * a stub, we do not know how to support this on other
 
388
       * platforms
 
389
       */
289
390
 
290
391
char *
291
392
gdm_get_empty_vt_argument (int *fd, int *vt)
302
403
}
303
404
 
304
405
int
305
 
gdm_get_cur_vt (void)
 
406
gdm_get_current_vt (void)
306
407
{
307
408
        return -1;
308
409
}