+ 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;
+