Commit | Line | Data |
---|---|---|
f63861b5 LC |
1 | Normally localed would do an approximate parsing of the Xorg config file |
2 | to determine the XKB keyboard layout. This doesn't make sense on Guix | |
3 | where there's no such file in /etc, and where the keyboard layout is | |
4 | known statically at configuration time. | |
5 | ||
6 | This patch removes the XOrg configuration parsing and expects to read the | |
7 | configuration from environment variables instead. It also removes the | |
8 | stateful bits that would write configuration to /etc/vconsole.conf | |
9 | and /etc/X11, which are unused in Guix anyway. | |
10 | ||
11 | Patch by Ludovic Courtès <ludo@gnu.org>. | |
12 | ||
13 | diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c | |
14 | index 6b6b32a591..46aab472b0 100644 | |
15 | --- a/src/locale/keymap-util.c | |
16 | +++ b/src/locale/keymap-util.c | |
17 | @@ -174,32 +174,16 @@ int vconsole_read_data(Context *c, sd_bus_message *m) { | |
18 | c->vc_cache = sd_bus_message_ref(m); | |
19 | } | |
20 | ||
21 | - if (stat("/etc/vconsole.conf", &st) < 0) { | |
22 | - if (errno != ENOENT) | |
23 | - return -errno; | |
24 | - | |
25 | - c->vc_mtime = USEC_INFINITY; | |
26 | - context_free_vconsole(c); | |
27 | - return 0; | |
28 | - } | |
29 | - | |
30 | - /* If mtime is not changed, then we do not need to re-read */ | |
31 | - t = timespec_load(&st.st_mtim); | |
32 | - if (c->vc_mtime != USEC_INFINITY && t == c->vc_mtime) | |
33 | - return 0; | |
34 | - | |
35 | - c->vc_mtime = t; | |
36 | + c->vc_mtime = USEC_INFINITY; | |
37 | context_free_vconsole(c); | |
38 | - | |
39 | - r = parse_env_file(NULL, "/etc/vconsole.conf", | |
40 | - "KEYMAP", &c->vc_keymap, | |
41 | - "KEYMAP_TOGGLE", &c->vc_keymap_toggle); | |
42 | - if (r < 0) | |
43 | - return r; | |
44 | - | |
45 | return 0; | |
46 | } | |
47 | ||
48 | +static char *getenv_strdup(const char *variable) { | |
49 | + const char *value = getenv(variable); | |
50 | + return value == NULL ? NULL : strdup(value); | |
51 | +} | |
52 | + | |
53 | int x11_read_data(Context *c, sd_bus_message *m) { | |
54 | _cleanup_fclose_ FILE *f = NULL; | |
55 | bool in_section = false; | |
56 | @@ -216,258 +200,27 @@ int x11_read_data(Context *c, sd_bus_message *m) { | |
57 | c->x11_cache = sd_bus_message_ref(m); | |
58 | } | |
59 | ||
60 | - if (stat("/etc/X11/xorg.conf.d/00-keyboard.conf", &st) < 0) { | |
61 | - if (errno != ENOENT) | |
62 | - return -errno; | |
63 | - | |
64 | - c->x11_mtime = USEC_INFINITY; | |
65 | - context_free_x11(c); | |
66 | - return 0; | |
67 | - } | |
68 | - | |
69 | - /* If mtime is not changed, then we do not need to re-read */ | |
70 | - t = timespec_load(&st.st_mtim); | |
71 | - if (c->x11_mtime != USEC_INFINITY && t == c->x11_mtime) | |
72 | - return 0; | |
73 | - | |
74 | - c->x11_mtime = t; | |
75 | + c->x11_mtime = 0; | |
76 | context_free_x11(c); | |
77 | ||
78 | - f = fopen("/etc/X11/xorg.conf.d/00-keyboard.conf", "re"); | |
79 | - if (!f) | |
80 | - return -errno; | |
81 | - | |
82 | - for (;;) { | |
83 | - _cleanup_free_ char *line = NULL; | |
84 | - char *l; | |
85 | - | |
86 | - r = read_line(f, LONG_LINE_MAX, &line); | |
87 | - if (r < 0) | |
88 | - return r; | |
89 | - if (r == 0) | |
90 | - break; | |
91 | - | |
92 | - l = strstrip(line); | |
93 | - if (IN_SET(l[0], 0, '#')) | |
94 | - continue; | |
95 | - | |
96 | - if (in_section && first_word(l, "Option")) { | |
97 | - _cleanup_strv_free_ char **a = NULL; | |
98 | - | |
99 | - r = strv_split_extract(&a, l, WHITESPACE, EXTRACT_QUOTES); | |
100 | - if (r < 0) | |
101 | - return r; | |
102 | - | |
103 | - if (strv_length(a) == 3) { | |
104 | - char **p = NULL; | |
105 | - | |
106 | - if (streq(a[1], "XkbLayout")) | |
107 | - p = &c->x11_layout; | |
108 | - else if (streq(a[1], "XkbModel")) | |
109 | - p = &c->x11_model; | |
110 | - else if (streq(a[1], "XkbVariant")) | |
111 | - p = &c->x11_variant; | |
112 | - else if (streq(a[1], "XkbOptions")) | |
113 | - p = &c->x11_options; | |
114 | - | |
115 | - if (p) { | |
116 | - free_and_replace(*p, a[2]); | |
117 | - } | |
118 | - } | |
119 | - | |
120 | - } else if (!in_section && first_word(l, "Section")) { | |
121 | - _cleanup_strv_free_ char **a = NULL; | |
122 | - | |
123 | - r = strv_split_extract(&a, l, WHITESPACE, EXTRACT_QUOTES); | |
124 | - if (r < 0) | |
125 | - return -ENOMEM; | |
126 | - | |
127 | - if (strv_length(a) == 2 && streq(a[1], "InputClass")) | |
128 | - in_section = true; | |
129 | - | |
130 | - } else if (in_section && first_word(l, "EndSection")) | |
131 | - in_section = false; | |
132 | - } | |
133 | + c->x11_layout = getenv_strdup("GUIX_XKB_LAYOUT"); | |
134 | + c->x11_model = getenv_strdup("GUIX_XKB_MODEL"); | |
135 | + c->x11_variant = getenv_strdup("GUIX_XKB_VARIANT"); | |
136 | + c->x11_options = getenv_strdup("GUIX_XKB_OPTIONS"); | |
137 | ||
138 | return 0; | |
139 | } | |
140 | ||
141 | int locale_write_data(Context *c, char ***settings) { | |
142 | - _cleanup_strv_free_ char **l = NULL; | |
143 | - struct stat st; | |
144 | - int r, p; | |
145 | - | |
146 | - /* Set values will be returned as strv in *settings on success. */ | |
147 | - | |
148 | - for (p = 0; p < _VARIABLE_LC_MAX; p++) { | |
149 | - _cleanup_free_ char *t = NULL; | |
150 | - char **u; | |
151 | - const char *name; | |
152 | - | |
153 | - name = locale_variable_to_string(p); | |
154 | - assert(name); | |
155 | - | |
156 | - if (isempty(c->locale[p])) | |
157 | - continue; | |
158 | - | |
159 | - if (asprintf(&t, "%s=%s", name, c->locale[p]) < 0) | |
160 | - return -ENOMEM; | |
161 | - | |
162 | - u = strv_env_set(l, t); | |
163 | - if (!u) | |
164 | - return -ENOMEM; | |
165 | - | |
166 | - strv_free_and_replace(l, u); | |
167 | - } | |
168 | - | |
169 | - if (strv_isempty(l)) { | |
170 | - if (unlink("/etc/locale.conf") < 0) | |
171 | - return errno == ENOENT ? 0 : -errno; | |
172 | - | |
173 | - c->locale_mtime = USEC_INFINITY; | |
174 | - return 0; | |
175 | - } | |
176 | - | |
177 | - r = write_env_file_label("/etc/locale.conf", l); | |
178 | - if (r < 0) | |
179 | - return r; | |
180 | - | |
181 | - *settings = TAKE_PTR(l); | |
182 | - | |
183 | - if (stat("/etc/locale.conf", &st) >= 0) | |
184 | - c->locale_mtime = timespec_load(&st.st_mtim); | |
185 | - | |
186 | - return 0; | |
187 | + return -ENOSYS; | |
188 | } | |
189 | ||
190 | int vconsole_write_data(Context *c) { | |
191 | - _cleanup_strv_free_ char **l = NULL; | |
192 | - struct stat st; | |
193 | - int r; | |
194 | - | |
195 | - r = load_env_file(NULL, "/etc/vconsole.conf", &l); | |
196 | - if (r < 0 && r != -ENOENT) | |
197 | - return r; | |
198 | - | |
199 | - if (isempty(c->vc_keymap)) | |
200 | - l = strv_env_unset(l, "KEYMAP"); | |
201 | - else { | |
202 | - _cleanup_free_ char *s = NULL; | |
203 | - char **u; | |
204 | - | |
205 | - s = strappend("KEYMAP=", c->vc_keymap); | |
206 | - if (!s) | |
207 | - return -ENOMEM; | |
208 | - | |
209 | - u = strv_env_set(l, s); | |
210 | - if (!u) | |
211 | - return -ENOMEM; | |
212 | - | |
213 | - strv_free_and_replace(l, u); | |
214 | - } | |
215 | - | |
216 | - if (isempty(c->vc_keymap_toggle)) | |
217 | - l = strv_env_unset(l, "KEYMAP_TOGGLE"); | |
218 | - else { | |
219 | - _cleanup_free_ char *s = NULL; | |
220 | - char **u; | |
221 | - | |
222 | - s = strappend("KEYMAP_TOGGLE=", c->vc_keymap_toggle); | |
223 | - if (!s) | |
224 | - return -ENOMEM; | |
225 | - | |
226 | - u = strv_env_set(l, s); | |
227 | - if (!u) | |
228 | - return -ENOMEM; | |
229 | - | |
230 | - strv_free_and_replace(l, u); | |
231 | - } | |
232 | - | |
233 | - if (strv_isempty(l)) { | |
234 | - if (unlink("/etc/vconsole.conf") < 0) | |
235 | - return errno == ENOENT ? 0 : -errno; | |
236 | - | |
237 | - c->vc_mtime = USEC_INFINITY; | |
238 | - return 0; | |
239 | - } | |
240 | - | |
241 | - r = write_env_file_label("/etc/vconsole.conf", l); | |
242 | - if (r < 0) | |
243 | - return r; | |
244 | - | |
245 | - if (stat("/etc/vconsole.conf", &st) >= 0) | |
246 | - c->vc_mtime = timespec_load(&st.st_mtim); | |
247 | - | |
248 | - return 0; | |
249 | + return -ENOSYS; | |
250 | } | |
251 | ||
252 | int x11_write_data(Context *c) { | |
253 | - _cleanup_fclose_ FILE *f = NULL; | |
254 | - _cleanup_free_ char *temp_path = NULL; | |
255 | - struct stat st; | |
256 | - int r; | |
257 | - | |
258 | - if (isempty(c->x11_layout) && | |
259 | - isempty(c->x11_model) && | |
260 | - isempty(c->x11_variant) && | |
261 | - isempty(c->x11_options)) { | |
262 | - | |
263 | - if (unlink("/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) | |
264 | - return errno == ENOENT ? 0 : -errno; | |
265 | - | |
266 | - c->vc_mtime = USEC_INFINITY; | |
267 | - return 0; | |
268 | - } | |
269 | - | |
270 | - mkdir_p_label("/etc/X11/xorg.conf.d", 0755); | |
271 | - | |
272 | - r = fopen_temporary("/etc/X11/xorg.conf.d/00-keyboard.conf", &f, &temp_path); | |
273 | - if (r < 0) | |
274 | - return r; | |
275 | - | |
276 | - (void) __fsetlocking(f, FSETLOCKING_BYCALLER); | |
277 | - (void) fchmod(fileno(f), 0644); | |
278 | - | |
279 | - fputs("# Written by systemd-localed(8), read by systemd-localed and Xorg. It's\n" | |
280 | - "# probably wise not to edit this file manually. Use localectl(1) to\n" | |
281 | - "# instruct systemd-localed to update it.\n" | |
282 | - "Section \"InputClass\"\n" | |
283 | - " Identifier \"system-keyboard\"\n" | |
284 | - " MatchIsKeyboard \"on\"\n", f); | |
285 | - | |
286 | - if (!isempty(c->x11_layout)) | |
287 | - fprintf(f, " Option \"XkbLayout\" \"%s\"\n", c->x11_layout); | |
288 | - | |
289 | - if (!isempty(c->x11_model)) | |
290 | - fprintf(f, " Option \"XkbModel\" \"%s\"\n", c->x11_model); | |
291 | - | |
292 | - if (!isempty(c->x11_variant)) | |
293 | - fprintf(f, " Option \"XkbVariant\" \"%s\"\n", c->x11_variant); | |
294 | - | |
295 | - if (!isempty(c->x11_options)) | |
296 | - fprintf(f, " Option \"XkbOptions\" \"%s\"\n", c->x11_options); | |
297 | - | |
298 | - fputs("EndSection\n", f); | |
299 | - | |
300 | - r = fflush_sync_and_check(f); | |
301 | - if (r < 0) | |
302 | - goto fail; | |
303 | - | |
304 | - if (rename(temp_path, "/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) { | |
305 | - r = -errno; | |
306 | - goto fail; | |
307 | - } | |
308 | - | |
309 | - if (stat("/etc/X11/xorg.conf.d/00-keyboard.conf", &st) >= 0) | |
310 | - c->x11_mtime = timespec_load(&st.st_mtim); | |
311 | - | |
312 | - return 0; | |
313 | - | |
314 | -fail: | |
315 | - if (temp_path) | |
316 | - (void) unlink(temp_path); | |
317 | - | |
318 | - return r; | |
319 | + return -ENOSYS; | |
320 | } | |
321 | ||
322 | static int read_next_mapping(const char* filename, |