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 for (i = 1; i < argc; i++)
50 if (streq(argv[i], "-seat"))
53 if (isempty(seat) || streq(seat, "seat0")) {
54 argv[0] = (char*) X_SERVER;
55 execv(X_SERVER, argv);
56 log_error("Failed to execute real X server: %m");
62 log_error("Failed to allocate udev environment.");
66 enumerator = udev_enumerate_new(udev);
68 log_error("Failed to allocate udev enumerator.");
72 udev_enumerate_add_match_subsystem(enumerator, "graphics");
73 udev_enumerate_add_match_tag(enumerator, seat);
75 r = udev_enumerate_scan_devices(enumerator);
77 log_error("Failed to enumerate devices.");
81 first = udev_enumerate_get_list_entry(enumerator);
82 udev_list_entry_foreach(item, first) {
83 struct udev_device *d;
86 d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
90 dn = udev_device_get_devnode(d);
93 device_node = strdup(dn);
96 log_error("Out of memory.");
101 udev_device_unref(d);
108 log_error("Failed to find device node for seat %s.", seat);
112 r = safe_mkdir("/run/systemd/multi-session-x", 0755, 0, 0);
114 log_error("Failed to create directory: %s", strerror(-r));
118 path = strappend("/run/systemd/multi-session-x/", seat);
120 log_error("Out of memory");
124 f = fopen(path, "we");
126 log_error("Failed to write configuration file: %m");
131 "Section \"Device\"\n"
132 " Identifier \"udev\"\n"
133 " Driver \"fbdev\"\n"
134 " Option \"fbdev\" \"%s\"\n"
136 "Section \"ServerFlags\"\n"
137 " Option \"AutoAddDevices\" \"True\"\n"
138 " Option \"AllowEmptyInput\" \"True\"\n"
145 log_error("Failed to write configuration file: %m");
152 new_argv = alloca(sizeof(char*) * (argc + 3 + 1));
153 memcpy(new_argv, argv, sizeof(char*) * (argc + 2 + 1));
155 new_argv[0] = (char*) X_SERVER;
156 new_argv[argc+0] = (char*) "-config";
157 new_argv[argc+1] = path;
158 new_argv[argc+2] = (char*) "-sharevts";
159 new_argv[argc+3] = NULL;
161 udev_enumerate_unref(enumerator);
170 execv(X_SERVER, new_argv);
171 log_error("Failed to execute real X server: %m");
175 udev_enumerate_unref(enumerator);