+ if (errno != 0) {
+ log_error("Failed to read locale directory: %m");
+ return -errno;
+ }
+
+ return 0;
+}
+
+static int list_locales(DBusConnection *bus, char **args, unsigned n) {
+ _cleanup_set_free_ Set *locales;
+ _cleanup_strv_free_ char **l = NULL;
+ 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)
+ return r;
+
+ r = add_locales_from_libdir(locales);
+ if (r < 0)
+ return r;
+
+ l = set_get_strv(locales);
+ if (!l)
+ return log_oom();
+
+ strv_sort(l);
+
+ pager_open_if_enabled();
+
+ strv_print(l);
+
+ return 0;