summaryrefslogtreecommitdiffstats
path: root/debian/patches/debian/Use-Debian-specific-config-files.patch
blob: 0c0a82a8735d136ea1504261dc63319fb0fdf124 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
From: Michael Biebl <biebl@debian.org>
Date: Thu, 18 Jul 2013 20:11:02 +0200
Subject: Use Debian specific config files

Use /etc/default/locale instead of /etc/locale.conf for locale settings.

Use /etc/default/keyboard instead of /etc/X11/xorg.conf.d/00-keyboard.conf for
keyboard configuration.

Read/write /etc/timezone if /etc/localtime does not exist.
---
 src/basic/time-util.c    |  34 ++++++--
 src/core/locale-setup.c  |  21 +++++
 src/locale/keymap-util.c | 208 ++++++++++++++++++++++++-----------------------
 src/timedate/timedated.c |  21 ++++-
 4 files changed, 173 insertions(+), 111 deletions(-)

diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index 5318d63..fa3409d 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -1456,19 +1456,43 @@ int get_timezone(char **ret) {
         const char *e;
         char *z;
         int r;
+        bool use_utc_fallback = false;
 
         r = readlink_malloc("/etc/localtime", &t);
-        if (r == -ENOENT) {
-                /* If the symlink does not exist, assume "UTC", like glibc does*/
-                z = strdup("UTC");
+        if (r < 0) {
+                if (r == -ENOENT)
+                        use_utc_fallback = true;
+                else if (r != -EINVAL)
+                        return r; /* returns EINVAL if not a symlink */
+
+                r = read_one_line_file("/etc/timezone", &t);
+                if (r < 0) {
+                        if (r != -ENOENT)
+                                log_warning_errno(r, "Failed to read /etc/timezone: %m");
+
+                        if (use_utc_fallback) {
+                                /* If the /etc/localtime symlink does not exist and we failed
+                                 * to read /etc/timezone, assume "UTC", like glibc does. */
+                                z = strdup("UTC");
+                                if (!z)
+                                        return -ENOMEM;
+
+                                *ret = z;
+                                return 0;
+                        }
+
+                        return -EINVAL;
+                }
+
+                if (!timezone_is_valid(t, LOG_DEBUG))
+                        return -EINVAL;
+                z = strdup(t);
                 if (!z)
                         return -ENOMEM;
 
                 *ret = z;
                 return 0;
         }
-        if (r < 0)
-                return r; /* returns EINVAL if not a symlink */
 
         e = PATH_STARTSWITH_SET(t, "/usr/share/zoneinfo/", "../usr/share/zoneinfo/");
         if (!e)
diff --git a/src/core/locale-setup.c b/src/core/locale-setup.c
index 64761dd..b4ea9e2 100644
--- a/src/core/locale-setup.c
+++ b/src/core/locale-setup.c
@@ -58,6 +58,27 @@ int locale_setup(char ***environment) {
                         log_warning_errno(r, "Failed to read /etc/locale.conf: %m");
         }
 
+        if (r <= 0) {
+                r = parse_env_file(NULL, "/etc/default/locale",
+                                   "LANG",              &variables[VARIABLE_LANG],
+                                   "LANGUAGE",          &variables[VARIABLE_LANGUAGE],
+                                   "LC_CTYPE",          &variables[VARIABLE_LC_CTYPE],
+                                   "LC_NUMERIC",        &variables[VARIABLE_LC_NUMERIC],
+                                   "LC_TIME",           &variables[VARIABLE_LC_TIME],
+                                   "LC_COLLATE",        &variables[VARIABLE_LC_COLLATE],
+                                   "LC_MONETARY",       &variables[VARIABLE_LC_MONETARY],
+                                   "LC_MESSAGES",       &variables[VARIABLE_LC_MESSAGES],
+                                   "LC_PAPER",          &variables[VARIABLE_LC_PAPER],
+                                   "LC_NAME",           &variables[VARIABLE_LC_NAME],
+                                   "LC_ADDRESS",        &variables[VARIABLE_LC_ADDRESS],
+                                   "LC_TELEPHONE",      &variables[VARIABLE_LC_TELEPHONE],
+                                   "LC_MEASUREMENT",    &variables[VARIABLE_LC_MEASUREMENT],
+                                   "LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION]);
+
+                if (r < 0 && r != -ENOENT)
+                        log_warning_errno(r, "Failed to read /etc/default/locale: %m");
+        }
+
         for (i = 0; i < _VARIABLE_LC_MAX; i++) {
                 char *s;
 
diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c
index 697133a..4e1fedb 100644
--- a/src/locale/keymap-util.c
+++ b/src/locale/keymap-util.c
@@ -95,6 +95,7 @@ void locale_simplify(char *locale[_VARIABLE_LC_MAX]) {
 int locale_read_data(Context *c, sd_bus_message *m) {
         struct stat st;
         int r;
+        const char *path = "/etc/locale.conf";
 
         /* Do not try to re-read the file within single bus operation. */
         if (m) {
@@ -105,7 +106,11 @@ int locale_read_data(Context *c, sd_bus_message *m) {
                 c->locale_cache = sd_bus_message_ref(m);
         }
 
-        r = stat("/etc/locale.conf", &st);
+        r = stat(path, &st);
+        if (r < 0 && errno == ENOENT) {
+                path = "/etc/default/locale";
+                r = stat(path, &st);
+        }
         if (r < 0 && errno != ENOENT)
                 return -errno;
 
@@ -120,7 +125,7 @@ int locale_read_data(Context *c, sd_bus_message *m) {
                 c->locale_mtime = t;
                 context_free_locale(c);
 
-                r = parse_env_file(NULL, "/etc/locale.conf",
+                r = parse_env_file(NULL, path,
                                    "LANG",              &c->locale[VARIABLE_LANG],
                                    "LANGUAGE",          &c->locale[VARIABLE_LANGUAGE],
                                    "LC_CTYPE",          &c->locale[VARIABLE_LC_CTYPE],
@@ -201,8 +206,6 @@ int vconsole_read_data(Context *c, sd_bus_message *m) {
 }
 
 int x11_read_data(Context *c, sd_bus_message *m) {
-        _cleanup_fclose_ FILE *f = NULL;
-        bool in_section = false;
         struct stat st;
         usec_t t;
         int r;
@@ -216,7 +219,7 @@ int x11_read_data(Context *c, sd_bus_message *m) {
                 c->x11_cache = sd_bus_message_ref(m);
         }
 
-        if (stat("/etc/X11/xorg.conf.d/00-keyboard.conf", &st) < 0) {
+        if (stat("/etc/default/keyboard", &st) < 0) {
                 if (errno != ENOENT)
                         return -errno;
 
@@ -233,60 +236,14 @@ int x11_read_data(Context *c, sd_bus_message *m) {
         c->x11_mtime = t;
         context_free_x11(c);
 
-        f = fopen("/etc/X11/xorg.conf.d/00-keyboard.conf", "re");
-        if (!f)
-                return -errno;
-
-        for (;;) {
-                _cleanup_free_ char *line = NULL;
-                char *l;
-
-                r = read_line(f, LONG_LINE_MAX, &line);
-                if (r < 0)
-                        return r;
-                if (r == 0)
-                        break;
-
-                l = strstrip(line);
-                if (IN_SET(l[0], 0, '#'))
-                        continue;
-
-                if (in_section && first_word(l, "Option")) {
-                        _cleanup_strv_free_ char **a = NULL;
-
-                        r = strv_split_full(&a, l, WHITESPACE, EXTRACT_UNQUOTE);
-                        if (r < 0)
-                                return r;
-
-                        if (strv_length(a) == 3) {
-                                char **p = NULL;
-
-                                if (streq(a[1], "XkbLayout"))
-                                        p = &c->x11_layout;
-                                else if (streq(a[1], "XkbModel"))
-                                        p = &c->x11_model;
-                                else if (streq(a[1], "XkbVariant"))
-                                        p = &c->x11_variant;
-                                else if (streq(a[1], "XkbOptions"))
-                                        p = &c->x11_options;
-
-                                if (p)
-                                        free_and_replace(*p, a[2]);
-                        }
-
-                } else if (!in_section && first_word(l, "Section")) {
-                        _cleanup_strv_free_ char **a = NULL;
+        r = parse_env_file(NULL, "/etc/default/keyboard",
+                           "XKBMODEL",          &c->x11_model,
+                           "XKBLAYOUT",         &c->x11_layout,
+                           "XKBVARIANT",        &c->x11_variant,
+                           "XKBOPTIONS",        &c->x11_options);
 
-                        r = strv_split_full(&a, l, WHITESPACE, EXTRACT_UNQUOTE);
-                        if (r < 0)
-                                return -ENOMEM;
-
-                        if (strv_length(a) == 2 && streq(a[1], "InputClass"))
-                                in_section = true;
-
-                } else if (in_section && first_word(l, "EndSection"))
-                        in_section = false;
-        }
+        if (r < 0)
+                return r;
 
         return 0;
 }
@@ -295,9 +252,18 @@ int locale_write_data(Context *c, char ***settings) {
         _cleanup_strv_free_ char **l = NULL;
         struct stat st;
         int r, p;
+        const char *path = "/etc/locale.conf";
 
         /* Set values will be returned as strv in *settings on success. */
 
+        r = load_env_file(NULL, path, &l);
+        if (r < 0 && r == -ENOENT) {
+                path = "/etc/default/locale";
+                r = load_env_file(NULL, path, &l);
+        }
+        if (r < 0 && r != -ENOENT)
+                return r;
+
         for (p = 0; p < _VARIABLE_LC_MAX; p++) {
                 _cleanup_free_ char *t = NULL;
                 char **u;
@@ -320,20 +286,20 @@ int locale_write_data(Context *c, char ***settings) {
         }
 
         if (strv_isempty(l)) {
-                if (unlink("/etc/locale.conf") < 0)
+                if (unlink(path) < 0)
                         return errno == ENOENT ? 0 : -errno;
 
                 c->locale_mtime = USEC_INFINITY;
                 return 0;
         }
 
-        r = write_env_file_label("/etc/locale.conf", l);
+        r = write_env_file_label(path, l);
         if (r < 0)
                 return r;
 
         *settings = TAKE_PTR(l);
 
-        if (stat("/etc/locale.conf", &st) >= 0)
+        if (stat(path, &st) >= 0)
                 c->locale_mtime = timespec_load(&st.st_mtim);
 
         return 0;
@@ -401,68 +367,104 @@ int vconsole_write_data(Context *c) {
 }
 
 int x11_write_data(Context *c) {
-        _cleanup_fclose_ FILE *f = NULL;
-        _cleanup_free_ char *temp_path = NULL;
         struct stat st;
         int r;
+        char *t, **u, **l = NULL;
 
-        if (isempty(c->x11_layout) &&
-            isempty(c->x11_model) &&
-            isempty(c->x11_variant) &&
-            isempty(c->x11_options)) {
+        r = load_env_file(NULL, "/etc/default/keyboard", &l);
+        if (r < 0 && r != -ENOENT)
+                return r;
 
-                if (unlink("/etc/X11/xorg.conf.d/00-keyboard.conf") < 0)
-                        return errno == ENOENT ? 0 : -errno;
+        /* This could perhaps be done more elegantly using an array
+         * like we do for the locale, instead of struct
+         */
+        if (isempty(c->x11_layout)) {
+                l = strv_env_unset(l, "XKBLAYOUT");
+        } else {
+                if (asprintf(&t, "XKBLAYOUT=%s", c->x11_layout) < 0) {
+                        strv_free(l);
+                        return -ENOMEM;
+                }
 
-                c->vc_mtime = USEC_INFINITY;
-                return 0;
+                u = strv_env_set(l, t);
+                free(t);
+                strv_free(l);
+
+                if (!u)
+                        return -ENOMEM;
+
+                l = u;
         }
 
-        (void) mkdir_p_label("/etc/X11/xorg.conf.d", 0755);
-        r = fopen_temporary("/etc/X11/xorg.conf.d/00-keyboard.conf", &f, &temp_path);
-        if (r < 0)
-                return r;
+        if (isempty(c->x11_model)) {
+                l = strv_env_unset(l, "XKBMODEL");
+        } else {
+                if (asprintf(&t, "XKBMODEL=%s", c->x11_model) < 0) {
+                        strv_free(l);
+                        return -ENOMEM;
+                }
 
-        (void) fchmod(fileno(f), 0644);
+                u = strv_env_set(l, t);
+                free(t);
+                strv_free(l);
 
-        fputs("# Written by systemd-localed(8), read by systemd-localed and Xorg. It's\n"
-              "# probably wise not to edit this file manually. Use localectl(1) to\n"
-              "# instruct systemd-localed to update it.\n"
-              "Section \"InputClass\"\n"
-              "        Identifier \"system-keyboard\"\n"
-              "        MatchIsKeyboard \"on\"\n", f);
+                if (!u)
+                        return -ENOMEM;
+
+                l = u;
+        }
+
+        if (isempty(c->x11_variant)) {
+                l = strv_env_unset(l, "XKBVARIANT");
+        } else {
+                if (asprintf(&t, "XKBVARIANT=%s", c->x11_variant) < 0) {
+                        strv_free(l);
+                        return -ENOMEM;
+                }
 
-        if (!isempty(c->x11_layout))
-                fprintf(f, "        Option \"XkbLayout\" \"%s\"\n", c->x11_layout);
+                u = strv_env_set(l, t);
+                free(t);
+                strv_free(l);
 
-        if (!isempty(c->x11_model))
-                fprintf(f, "        Option \"XkbModel\" \"%s\"\n", c->x11_model);
+                if (!u)
+                        return -ENOMEM;
 
-        if (!isempty(c->x11_variant))
-                fprintf(f, "        Option \"XkbVariant\" \"%s\"\n", c->x11_variant);
+                l = u;
+        }
 
-        if (!isempty(c->x11_options))
-                fprintf(f, "        Option \"XkbOptions\" \"%s\"\n", c->x11_options);
+        if (isempty(c->x11_options)) {
+                l = strv_env_unset(l, "XKBOPTIONS");
+        } else {
+                if (asprintf(&t, "XKBOPTIONS=%s", c->x11_options) < 0) {
+                        strv_free(l);
+                        return -ENOMEM;
+                }
 
-        fputs("EndSection\n", f);
+                u = strv_env_set(l, t);
+                free(t);
+                strv_free(l);
 
-        r = fflush_sync_and_check(f);
-        if (r < 0)
-                goto fail;
+                if (!u)
+                        return -ENOMEM;
 
-        if (rename(temp_path, "/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) {
-                r = -errno;
-                goto fail;
+                l = u;
         }
 
-        if (stat("/etc/X11/xorg.conf.d/00-keyboard.conf", &st) >= 0)
-                c->x11_mtime = timespec_load(&st.st_mtim);
+        if (strv_isempty(l)) {
+                strv_free(l);
 
-        return 0;
+                if (unlink("/etc/default/keyboard") < 0)
+                        return errno == ENOENT ? 0 : -errno;
 
-fail:
-        if (temp_path)
-                (void) unlink(temp_path);
+                c->vc_mtime = USEC_INFINITY;
+                return 0;
+        }
+
+        r = write_env_file("/etc/default/keyboard", l);
+        strv_free(l);
+
+        if (r >= 0 && stat("/etc/default/keyboard", &st) >= 0)
+                c->x11_mtime = timespec_load(&st.st_mtim);
 
         return r;
 }
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 8149fac..42c8277 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -283,6 +283,8 @@ static int context_read_data(Context *c) {
 static int context_write_data_timezone(Context *c) {
         _cleanup_free_ char *p = NULL;
         const char *source;
+        int r = 0;
+        struct stat st;
 
         assert(c);
 
@@ -296,9 +298,12 @@ static int context_write_data_timezone(Context *c) {
                 if (access("/usr/share/zoneinfo/UTC", F_OK) < 0) {
 
                         if (unlink("/etc/localtime") < 0 && errno != ENOENT)
-                                return -errno;
+                                r = -errno;
 
-                        return 0;
+                        if (unlink("/etc/timezone") < 0 && errno != ENOENT)
+                                r = -errno;
+
+                        return r;
                 }
 
                 source = "../usr/share/zoneinfo/UTC";
@@ -310,7 +315,17 @@ static int context_write_data_timezone(Context *c) {
                 source = p;
         }
 
-        return symlink_atomic(source, "/etc/localtime");
+        r = symlink_atomic(source, "/etc/localtime");
+        if (r < 0)
+                return r;
+
+        if (stat("/etc/timezone", &st) == 0 && S_ISREG(st.st_mode)) {
+                r = write_string_file("/etc/timezone", c->zone, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC);
+                if (r < 0)
+                        return r;
+        }
+
+        return 0;
 }
 
 static int context_write_data_local_rtc(Context *c) {