#include "dbus-common.h"
#include "polkit.h"
#include "def.h"
+#include "env-util.h"
+#include "fileio.h"
+#include "fileio-label.h"
+#include "label.h"
#define INTERFACE \
" <interface name=\"org.freedesktop.locale1\">\n" \
[PROP_LC_IDENTIFICATION] = "LC_IDENTIFICATION"
};
-static char *data[_PROP_MAX] = {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
-};
+static char *data[_PROP_MAX] = {};
typedef struct State {
char *x11_layout, *x11_model, *x11_variant, *x11_options;
int r, p;
char **l = NULL;
- r = load_env_file("/etc/locale.conf", &l);
+ r = load_env_file("/etc/locale.conf", NULL, &l);
if (r < 0 && r != -ENOENT)
return r;
return 0;
}
- r = write_env_file("/etc/locale.conf", l);
+ r = write_env_file_label("/etc/locale.conf", l);
strv_free(l);
return r;
int r;
char **l = NULL;
- r = load_env_file("/etc/vconsole.conf", &l);
+ r = load_env_file("/etc/vconsole.conf", NULL, &l);
if (r < 0 && r != -ENOENT)
return r;
return 0;
}
- r = write_env_file("/etc/vconsole.conf", l);
+ r = write_env_file_label("/etc/vconsole.conf", l);
strv_free(l);
return r;
return 0;
}
- mkdir_parents_label("/etc/X11/xorg.conf.d", 0755);
+ 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)
free_data_x11();
} else {
- FILE *f;
+ _cleanup_fclose_ FILE *f;
unsigned n = 0;
unsigned best_matching = 0;
char *new_keymap = NULL;
return -errno;
for (;;) {
- char **a;
+ _cleanup_strv_free_ char **a = NULL;
unsigned matching = 0;
int r;
r = read_next_mapping(f, &n, &a);
- if (r < 0) {
- fclose(f);
+ if (r < 0)
return r;
- }
-
if (r == 0)
break;
* layout stripped off. */
if (x > 0 &&
strlen(a[1]) == x &&
- strncmp(state.x11_layout, a[1], x) == 0)
+ strneq(state.x11_layout, a[1], x))
matching = 5;
else {
size_t w;
free(new_keymap);
new_keymap = strdup(a[0]);
-
- if (!new_keymap) {
- strv_free(a);
- fclose(f);
+ if (!new_keymap)
return -ENOMEM;
- }
}
-
- strv_free(a);
}
- fclose(f);
-
if (!streq_ptr(state.vc_keymap, new_keymap)) {
free(state.vc_keymap);
state.vc_keymap = new_keymap;
if (modified) {
dbus_bool_t b;
- DBusMessage *changed;
+
+ _cleanup_dbus_message_unref_ DBusMessage *changed = NULL;
int r;
r = write_data_vconsole();
"org.freedesktop.locale1",
"VConsoleKeymap\0"
"VConsoleKeymapToggle\0");
-
if (!changed)
return -ENOMEM;
b = dbus_connection_send(connection, changed, NULL);
- dbus_message_unref(changed);
-
if (!b)
return -ENOMEM;
}
static int append_locale(DBusMessageIter *i, const char *property, void *userdata) {
- int r, c = 0, p;
- char **l;
+ int c, p;
+ _cleanup_strv_free_ char **l = NULL;
l = new0(char*, _PROP_MAX+1);
if (!l)
return -ENOMEM;
- for (p = 0; p < _PROP_MAX; p++) {
+ for (p = 0, c = 0; p < _PROP_MAX; p++) {
char *t;
if (isempty(data[p]))
continue;
- if (asprintf(&t, "%s=%s", names[p], data[p]) < 0) {
- strv_free(l);
+ if (asprintf(&t, "%s=%s", names[p], data[p]) < 0)
return -ENOMEM;
- }
l[c++] = t;
}
- r = bus_property_append_strv(i, property, (void*) l);
- strv_free(l);
-
- return r;
+ return bus_property_append_strv(i, property, (void*) l);
}
static const BusProperty bus_locale_properties[] = {
dbus_bool_t interactive;
DBusMessageIter iter;
bool modified = false;
- bool passed[_PROP_MAX];
+ bool passed[_PROP_MAX] = {};
int p;
if (!dbus_message_iter_init(message, &iter))
dbus_message_iter_get_basic(&iter, &interactive);
- zero(passed);
-
/* Check whether a variable changed and if so valid */
STRV_FOREACH(i, l) {
bool valid = false;
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
- if (!dbus_connection_send(connection, reply, NULL))
+ if (!bus_maybe_send_reply(connection, message, reply))
goto oom;
dbus_message_unref(reply);
log_set_target(LOG_TARGET_AUTO);
log_parse_environment();
log_open();
-
+ label_init("/etc");
umask(0022);
if (argc == 2 && streq(argv[1], "--introspect")) {