1
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4
This file is part of systemd.
6
Copyright 2011 Lennart Poettering
8
systemd is free software; you can redistribute it and/or modify it
9
under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
systemd is distributed in the hope that it will be useful, but
14
WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with systemd; If not, see <http://www.gnu.org/licenses/>.
29
int main(int argc, char *argv[]) {
31
struct udev *udev = NULL;
32
struct udev_enumerate *enumerator = NULL;
33
struct udev_list_entry *first, *item;
35
const char *seat = NULL;
37
char *path = NULL, *device_node = NULL;
41
/* This binary will go away as soon as X natively supports
42
* display enumeration with udev in a way that covers both PCI
45
/* This will simply determine the fb device id of the graphics
46
* device assigned to a seat and write a configuration file
47
* from it and then spawn the real X server. */
49
/* If this file is removed, don't forget to remove the code
50
* that invokes this in gdm and other display managers. */
52
for (i = 1; i < argc; i++)
53
if (streq(argv[i], "-seat"))
56
if (isempty(seat) || streq(seat, "seat0")) {
57
argv[0] = (char*) X_SERVER;
58
execv(X_SERVER, argv);
59
log_error("Failed to execute real X server: %m");
65
log_error("Failed to allocate udev environment.");
69
enumerator = udev_enumerate_new(udev);
71
log_error("Failed to allocate udev enumerator.");
75
udev_enumerate_add_match_subsystem(enumerator, "graphics");
76
udev_enumerate_add_match_tag(enumerator, seat);
78
r = udev_enumerate_scan_devices(enumerator);
80
log_error("Failed to enumerate devices.");
84
first = udev_enumerate_get_list_entry(enumerator);
85
udev_list_entry_foreach(item, first) {
86
struct udev_device *d;
89
d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
93
dn = udev_device_get_devnode(d);
96
device_node = strdup(dn);
99
log_error("Out of memory.");
104
udev_device_unref(d);
111
log_error("Failed to find device node for seat %s.", seat);
115
r = safe_mkdir("/run/systemd/multi-session-x", 0755, 0, 0);
117
log_error("Failed to create directory: %s", strerror(-r));
121
path = strappend("/run/systemd/multi-session-x/", seat);
123
log_error("Out of memory");
127
f = fopen(path, "we");
129
log_error("Failed to write configuration file: %m");
134
"Section \"Device\"\n"
135
" Identifier \"udev\"\n"
136
" Driver \"fbdev\"\n"
137
" Option \"fbdev\" \"%s\"\n"
139
"Section \"ServerFlags\"\n"
140
" Option \"AutoAddDevices\" \"True\"\n"
141
" Option \"AllowEmptyInput\" \"True\"\n"
142
" Option \"DontVTSwitch\" \"True\"\n"
144
"Section \"InputClass\"\n"
145
" Identifier \"Force Input Devices to Seat\"\n"
146
" Option \"GrabDevice\" \"True\"\n"
153
log_error("Failed to write configuration file: %m");
160
new_argv = alloca(sizeof(char*) * (argc + 3 + 1));
161
memcpy(new_argv, argv, sizeof(char*) * (argc + 2 + 1));
163
new_argv[0] = (char*) X_SERVER;
164
new_argv[argc+0] = (char*) "-config";
165
new_argv[argc+1] = path;
166
new_argv[argc+2] = (char*) "-sharevts";
167
new_argv[argc+3] = NULL;
169
udev_enumerate_unref(enumerator);
178
execv(X_SERVER, new_argv);
179
log_error("Failed to execute real X server: %m");
183
udev_enumerate_unref(enumerator);