SHA256
1
0
forked from pool/systemd
systemd/localectl-support-systems-without-locale-archive.patch
Stephan Kulow 22e9bed03a Accepting request 149704 from Base:System
- Add systemctl-options.patch: handle SYSTEMCTL_OPTIONS internaly
  (bnc#798620).
- Update crypt-loop-file.patch to correctly detect crypto loop
  files (bnc#799514).
- Add journalctl-remove-leftover-message.patch: remove debug
  message in systemctl.
- Add job-avoid-recursion-when-cancelling.patch: prevent potential
  recursion when cancelling a service.
- Add sysctl-parse-all-keys.patch: ensure sysctl file is fully
  parsed.
- Add journal-fix-cutoff-max-date.patch: fix computation of cutoff
  max date for journal.
- Add reword-rescue-mode-hints.patch: reword rescue prompt.
- Add improve-overflow-checks.patch: improve time overflow checks.
- Add fix-swap-behaviour-with-symlinks.patch: fix swap behaviour
  with symlinks.
- Add hostnamectl-fix-set-hostname-with-no-argument.patch: ensure
  hostnamectl requires an argument when called with set-hostname
  option.
- Add agetty-overrides-term.patch: pass correctly terminal type to
  agetty.
- Add check-for-empty-strings-in-strto-conversions.patch: better
  check for empty strings in strto* conversions.
- Add strv-cleanup-error-path-loops.patch: cleanup strv on error
  path.
- Add cryptsetup-handle-plain.patch: correctly handle "plain"
  option in cryptsetup.
- Add fstab-generator-improve-error-message.patch: improve error
  message in fstab-generator.
- Add delta-accept-t-option.patch: accept -t option in (forwarded request 149703 from fcrozat)

OBS-URL: https://build.opensuse.org/request/show/149704
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=122
2013-01-24 09:41:58 +00:00

164 lines
4.5 KiB
Diff

From 17d33cecaa762f7e43200307328af5e9135e2091 Mon Sep 17 00:00:00 2001
From: Giovanni Campagna <scampa.giovanni@gmail.com>
Date: Sat, 5 Jan 2013 01:29:53 +0100
Subject: [PATCH] localectl: support systems without locale-archive
Not all systems ships with locales inside /usr/lib/locale-archive, some
prefer to have locale data as individual subdirectories of /usr/lib/locale.
(A notable example of this is OpenEmbeddded, and OSes deriving from it
like gnome-ostree).
Given that glibc supports both ways, localectl should too.
---
src/locale/localectl.c | 101 ++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 85 insertions(+), 16 deletions(-)
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 5d35f9c..b3acb3e 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -266,7 +266,7 @@ finish:
return r;
}
-static int list_locales(DBusConnection *bus, char **args, unsigned n) {
+static int add_locales_from_archive(Set *locales) {
/* Stolen from glibc... */
struct locarhead {
@@ -304,21 +304,15 @@ static int list_locales(DBusConnection *bus, char **args, unsigned n) {
const struct namehashent *e;
const void *p = MAP_FAILED;
_cleanup_close_ int fd = -1;
- _cleanup_strv_free_ char **l = NULL;
- char **j;
- Set *locales;
size_t sz = 0;
struct stat st;
unsigned i;
int r;
- locales = set_new(string_hash_func, string_compare_func);
- if (!locales)
- return log_oom();
-
fd = open("/usr/lib/locale/locale-archive", O_RDONLY|O_NOCTTY|O_CLOEXEC);
if (fd < 0) {
- log_error("Failed to open locale archive: %m");
+ if (errno != ENOENT)
+ log_error("Failed to open locale archive: %m");
r = -errno;
goto finish;
}
@@ -380,15 +374,93 @@ static int list_locales(DBusConnection *bus, char **args, unsigned n) {
}
}
+ r = 0;
+
+ finish:
+ if (p != MAP_FAILED)
+ munmap((void*) p, sz);
+
+ return r;
+}
+
+static int add_locales_from_libdir (Set *locales) {
+ DIR *dir;
+ struct dirent *entry;
+ int r;
+
+ dir = opendir("/usr/lib/locale");
+ if (!dir) {
+ log_error("Failed to open locale directory: %m");
+ r = -errno;
+ goto finish;
+ }
+
+ errno = 0;
+ while ((entry = readdir(dir))) {
+ char *z;
+
+ if (entry->d_type != DT_DIR)
+ continue;
+
+ if (ignore_file(entry->d_name))
+ continue;
+
+ z = strdup(entry->d_name);
+ if (!z) {
+ r = log_oom();
+ goto finish;
+ }
+
+ r = set_put(locales, z);
+ if (r < 0) {
+ free(z);
+
+ if (r != -EEXIST) {
+ log_error("Failed to add locale: %s", strerror(-r));
+ goto finish;
+ }
+ }
+
+ errno = 0;
+ }
+
+ if (errno != 0) {
+ log_error("Failed to read locale directory: %m");
+ r = -errno;
+ goto finish;
+ }
+
+ r = 0;
+
+ finish:
+ closedir(dir);
+ return r;
+}
+
+static int list_locales(DBusConnection *bus, char **args, unsigned n) {
+ Set *locales;
+ _cleanup_strv_free_ char **l = NULL;
+ char **j;
+ int r;
+
+ locales = set_new(string_hash_func, string_compare_func);
+ if (!locales)
+ return log_oom();
+
+ r = add_locales_from_archive(locales);
+ if (r < 0 && r != -ENOENT)
+ goto finish;
+
+ r = add_locales_from_libdir(locales);
+ if (r < 0)
+ goto finish;
+
l = set_get_strv(locales);
if (!l) {
r = log_oom();
goto finish;
}
- set_free(locales);
- locales = NULL;
-
strv_sort(l);
pager_open_if_enabled();
@@ -399,10 +471,7 @@ static int list_locales(DBusConnection *bus, char **args, unsigned n) {
r = 0;
finish:
- if (p != MAP_FAILED)
- munmap((void*) p, sz);
-
- set_free_free(locales);
+ set_free(locales);
return r;
}
--
1.7.10.4