* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-01-29 23:22 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-01-29 23:22 UTC (permalink / raw
To: gentoo-commits
commit: c634bc83ca40dcf3e0079905d77089d7e5090421
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 29 23:22:17 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Sun Jan 29 23:22:17 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=c634bc83
Thread safety
---
src/hostnamed.c | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/src/hostnamed.c b/src/hostnamed.c
index f0c2357..b431aac 100644
--- a/src/hostnamed.c
+++ b/src/hostnamed.c
@@ -43,9 +43,12 @@ gboolean read_only = FALSE;
static OpenrcSettingsdHostnamedHostname1 *hostname1 = NULL;
static gchar hostname[HOST_NAME_MAX + 1];
+static GStaticMutex hostname_mutex = G_STATIC_MUTEX_INIT;
static gchar *static_hostname = NULL;
+static GStaticMutex static_hostname_mutex = G_STATIC_MUTEX_INIT;
static gchar *pretty_hostname = NULL;
static gchar *icon_name = NULL;
+static GStaticMutex machine_info_mutex = G_STATIC_MUTEX_INIT;
static gboolean
hostname_is_valid (const gchar *name)
@@ -120,6 +123,7 @@ on_handle_set_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
goto end;
}
+ g_static_mutex_lock (&hostname_mutex);
/* Don't allow an empty or invalid hostname */
if (!hostname_is_valid (name)) {
name = hostname;
@@ -131,10 +135,13 @@ on_handle_set_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
g_dbus_method_invocation_return_dbus_error (invocation,
DBUS_ERROR_FAILED,
strerror (errsv));
+ g_static_mutex_unlock (&hostname_mutex);
+ goto end;
}
g_strlcpy (hostname, name, HOST_NAME_MAX + 1);
openrc_settingsd_hostnamed_hostname1_complete_set_hostname (hostname1, invocation);
openrc_settingsd_hostnamed_hostname1_set_hostname (hostname1, hostname);
+ g_static_mutex_unlock (&hostname_mutex);
end:
return TRUE;
@@ -162,6 +169,7 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
goto end;
}
+ g_static_mutex_lock (&static_hostname_mutex);
/* Don't allow an empty or invalid hostname */
if (!hostname_is_valid (name))
name = "localhost";
@@ -169,6 +177,7 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
confd_file = shell_utils_trivial_new (SYSCONFDIR "/conf.d/hostname", &err);
if (confd_file == NULL) {
g_dbus_method_invocation_return_gerror (invocation, err);
+ g_static_mutex_unlock (&static_hostname_mutex);
goto end;
}
@@ -179,11 +188,13 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
g_dbus_method_invocation_return_dbus_error (invocation,
DBUS_ERROR_FAILED,
"Failed to set static hostname in " SYSCONFDIR "/conf.d/hostname");
+ g_static_mutex_unlock (&static_hostname_mutex);
goto end;
}
if (!shell_utils_trivial_save (confd_file, &err)) {
g_dbus_method_invocation_return_gerror (invocation, err);
+ g_static_mutex_unlock (&static_hostname_mutex);
goto end;
}
@@ -191,6 +202,7 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
static_hostname = g_strdup (name);
openrc_settingsd_hostnamed_hostname1_complete_set_static_hostname (hostname1, invocation);
openrc_settingsd_hostnamed_hostname1_set_static_hostname (hostname1, static_hostname);
+ g_static_mutex_unlock (&static_hostname_mutex);
end:
shell_utils_trivial_free (confd_file);
@@ -223,6 +235,7 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1,
goto end;
}
+ g_static_mutex_lock (&machine_info_mutex);
/* Don't allow a null pretty hostname */
if (name == NULL)
name = "";
@@ -230,6 +243,7 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1,
confd_file = shell_utils_trivial_new (SYSCONFDIR "/machine-info", &err);
if (confd_file == NULL) {
g_dbus_method_invocation_return_gerror (invocation, err);
+ g_static_mutex_unlock (&machine_info_mutex);
goto end;
}
@@ -239,11 +253,13 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1,
g_dbus_method_invocation_return_dbus_error (invocation,
DBUS_ERROR_FAILED,
"Failed to value in " SYSCONFDIR "/machine-info");
+ g_static_mutex_unlock (&machine_info_mutex);
goto end;
}
if (!shell_utils_trivial_save (confd_file, &err)) {
g_dbus_method_invocation_return_gerror (invocation, err);
+ g_static_mutex_unlock (&machine_info_mutex);
goto end;
}
@@ -258,6 +274,7 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1,
openrc_settingsd_hostnamed_hostname1_complete_set_icon_name (hostname1, invocation);
openrc_settingsd_hostnamed_hostname1_set_icon_name (hostname1, icon_name);
}
+ g_static_mutex_unlock (&machine_info_mutex);
end:
shell_utils_trivial_free (confd_file);
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-02-05 0:20 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-02-05 0:20 UTC (permalink / raw
To: gentoo-commits
commit: 8f23cc229ef22542624b08b8b7f28219d0c3a5f8
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 5 00:01:35 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Sun Feb 5 00:20:04 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=8f23cc22
GStaticMutex is deprecated in glib-2.31
---
src/hostnamed.c | 32 ++++++++++++++++----------------
1 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/hostnamed.c b/src/hostnamed.c
index b431aac..d910fb0 100644
--- a/src/hostnamed.c
+++ b/src/hostnamed.c
@@ -43,12 +43,12 @@ gboolean read_only = FALSE;
static OpenrcSettingsdHostnamedHostname1 *hostname1 = NULL;
static gchar hostname[HOST_NAME_MAX + 1];
-static GStaticMutex hostname_mutex = G_STATIC_MUTEX_INIT;
+G_LOCK_DEFINE_STATIC (hostname);
static gchar *static_hostname = NULL;
-static GStaticMutex static_hostname_mutex = G_STATIC_MUTEX_INIT;
+G_LOCK_DEFINE_STATIC (static_hostname);
static gchar *pretty_hostname = NULL;
static gchar *icon_name = NULL;
-static GStaticMutex machine_info_mutex = G_STATIC_MUTEX_INIT;
+G_LOCK_DEFINE_STATIC (machine_info);
static gboolean
hostname_is_valid (const gchar *name)
@@ -123,7 +123,7 @@ on_handle_set_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
goto end;
}
- g_static_mutex_lock (&hostname_mutex);
+ G_LOCK (hostname);
/* Don't allow an empty or invalid hostname */
if (!hostname_is_valid (name)) {
name = hostname;
@@ -135,13 +135,13 @@ on_handle_set_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
g_dbus_method_invocation_return_dbus_error (invocation,
DBUS_ERROR_FAILED,
strerror (errsv));
- g_static_mutex_unlock (&hostname_mutex);
+ G_UNLOCK (hostname);
goto end;
}
g_strlcpy (hostname, name, HOST_NAME_MAX + 1);
openrc_settingsd_hostnamed_hostname1_complete_set_hostname (hostname1, invocation);
openrc_settingsd_hostnamed_hostname1_set_hostname (hostname1, hostname);
- g_static_mutex_unlock (&hostname_mutex);
+ G_UNLOCK (hostname);
end:
return TRUE;
@@ -169,7 +169,7 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
goto end;
}
- g_static_mutex_lock (&static_hostname_mutex);
+ G_LOCK (static_hostname);
/* Don't allow an empty or invalid hostname */
if (!hostname_is_valid (name))
name = "localhost";
@@ -177,7 +177,7 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
confd_file = shell_utils_trivial_new (SYSCONFDIR "/conf.d/hostname", &err);
if (confd_file == NULL) {
g_dbus_method_invocation_return_gerror (invocation, err);
- g_static_mutex_unlock (&static_hostname_mutex);
+ G_UNLOCK (static_hostname);
goto end;
}
@@ -188,13 +188,13 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
g_dbus_method_invocation_return_dbus_error (invocation,
DBUS_ERROR_FAILED,
"Failed to set static hostname in " SYSCONFDIR "/conf.d/hostname");
- g_static_mutex_unlock (&static_hostname_mutex);
+ G_UNLOCK (static_hostname);
goto end;
}
if (!shell_utils_trivial_save (confd_file, &err)) {
g_dbus_method_invocation_return_gerror (invocation, err);
- g_static_mutex_unlock (&static_hostname_mutex);
+ G_UNLOCK (static_hostname);
goto end;
}
@@ -202,7 +202,7 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
static_hostname = g_strdup (name);
openrc_settingsd_hostnamed_hostname1_complete_set_static_hostname (hostname1, invocation);
openrc_settingsd_hostnamed_hostname1_set_static_hostname (hostname1, static_hostname);
- g_static_mutex_unlock (&static_hostname_mutex);
+ G_UNLOCK (static_hostname);
end:
shell_utils_trivial_free (confd_file);
@@ -235,7 +235,7 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1,
goto end;
}
- g_static_mutex_lock (&machine_info_mutex);
+ G_LOCK (machine_info);
/* Don't allow a null pretty hostname */
if (name == NULL)
name = "";
@@ -243,7 +243,7 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1,
confd_file = shell_utils_trivial_new (SYSCONFDIR "/machine-info", &err);
if (confd_file == NULL) {
g_dbus_method_invocation_return_gerror (invocation, err);
- g_static_mutex_unlock (&machine_info_mutex);
+ G_UNLOCK (machine_info);
goto end;
}
@@ -253,13 +253,13 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1,
g_dbus_method_invocation_return_dbus_error (invocation,
DBUS_ERROR_FAILED,
"Failed to value in " SYSCONFDIR "/machine-info");
- g_static_mutex_unlock (&machine_info_mutex);
+ G_UNLOCK (machine_info);
goto end;
}
if (!shell_utils_trivial_save (confd_file, &err)) {
g_dbus_method_invocation_return_gerror (invocation, err);
- g_static_mutex_unlock (&machine_info_mutex);
+ G_UNLOCK (machine_info);
goto end;
}
@@ -274,7 +274,7 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1,
openrc_settingsd_hostnamed_hostname1_complete_set_icon_name (hostname1, invocation);
openrc_settingsd_hostnamed_hostname1_set_icon_name (hostname1, icon_name);
}
- g_static_mutex_unlock (&machine_info_mutex);
+ G_UNLOCK (machine_info);
end:
shell_utils_trivial_free (confd_file);
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-02-05 7:52 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-02-05 7:52 UTC (permalink / raw
To: gentoo-commits
commit: c5fa3dd0f29f669d8495f3500ec82851a28e21ce
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 5 07:51:55 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Sun Feb 5 07:51:55 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=c5fa3dd0
Better variable names
---
src/main.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/main.c b/src/main.c
index 1cff0f5..7463fd3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -31,7 +31,7 @@
static gboolean debug = FALSE;
-static GOptionEntry entries[] =
+static GOptionEntry option_entries[] =
{
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Enable debugging messages", NULL },
{ NULL }
@@ -51,15 +51,15 @@ gint
main (gint argc, gchar *argv[])
{
GError *error = NULL;
- GOptionContext *context;
+ GOptionContext *option_context;
GMainLoop *loop = NULL;
g_type_init ();
g_log_set_default_handler (log_handler, NULL);
- context = g_option_context_new ("- system settings D-Bus service for OpenRC");
- g_option_context_add_main_entries (context, entries, NULL);
- if (!g_option_context_parse (context, &argc, &argv, &error)) {
+ option_context = g_option_context_new ("- system settings D-Bus service for OpenRC");
+ g_option_context_add_main_entries (option_context, option_entries, NULL);
+ if (!g_option_context_parse (option_context, &argc, &argv, &error)) {
g_printerr ("Failed to parse options: %s\n", error->message);
exit (1);
}
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-02-06 10:24 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-02-06 10:24 UTC (permalink / raw
To: gentoo-commits
commit: 52f4dc6163ecbc334f9ba949d6436f650ecf138d
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Mon Feb 6 10:19:08 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Mon Feb 6 10:19:08 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=52f4dc61
Check polkit authorization asynchronously
The other alternative (spawning a thread for each authorization
request) seems less elegant, since such requests can take arbitrarily
long to complete.
---
src/bus-utils.c | 137 +++++++++++++++++++++-------
src/bus-utils.h | 13 ++-
src/hostnamed.c | 275 ++++++++++++++++++++++++++++++++++++++-----------------
3 files changed, 302 insertions(+), 123 deletions(-)
diff --git a/src/bus-utils.c b/src/bus-utils.c
index d3bc7b2..aef8037 100644
--- a/src/bus-utils.c
+++ b/src/bus-utils.c
@@ -20,44 +20,115 @@
#include <gio/gio.h>
#include <polkit/polkit.h>
+#include "bus-utils.h"
+
+struct check_polkit_data {
+ const gchar *unique_name;
+ const gchar *action_id;
+ gboolean user_interaction;
+ GAsyncReadyCallback callback;
+ gpointer user_data;
+
+ PolkitAuthority *authority;
+ PolkitSubject *subject;
+};
+
+void
+check_polkit_data_free (struct check_polkit_data *data)
+{
+ if (data == NULL)
+ return;
+
+ if (data->subject != NULL)
+ g_object_unref (data->subject);
+ if (data->authority != NULL)
+ g_object_unref (data->authority);
+
+ g_free (data);
+}
+
gboolean
-check_polkit (const gchar *unique_name,
- const gchar *action_id,
- const gboolean user_interaction,
- GError **error)
+check_polkit_finish (GAsyncResult *res,
+ GError **error)
{
- gboolean ret = FALSE;
- GDBusConnection *connection = NULL;
- PolkitAuthority *authority = NULL;
- PolkitSubject *subject = NULL;
- PolkitAuthorizationResult *result = NULL;
-
- if ((authority = polkit_authority_get_sync (NULL, error)) == NULL)
- goto end;
-
- if (unique_name == NULL || action_id == NULL ||
- (subject = polkit_system_bus_name_new (unique_name)) == NULL) {
- g_propagate_error (error,
- g_error_new (POLKIT_ERROR, POLKIT_ERROR_FAILED,
- "Authorizing for '%s': failed sanity check", action_id));
- goto end;
- }
+ GSimpleAsyncResult *simple;
+
+ simple = G_SIMPLE_ASYNC_RESULT (res);
+ if (g_simple_async_result_propagate_error (simple, error))
+ return FALSE;
+
+ return g_simple_async_result_get_op_res_gboolean (simple);
+}
+
+static void
+check_polkit_authorization_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer _data)
+{
+ struct check_polkit_data *data;
+ PolkitAuthorizationResult *result;
+ GSimpleAsyncResult *simple;
+ GError *err = NULL;
- if ((result = polkit_authority_check_authorization_sync (authority, subject, action_id, NULL, (PolkitCheckAuthorizationFlags) user_interaction, NULL, error)) == NULL)
- goto end;
+ data = (struct check_polkit_data *) _data;
+ if ((result = polkit_authority_check_authorization_finish (data->authority, res, &err)) == NULL) {
+ g_simple_async_report_take_gerror_in_idle (NULL, data->callback, data->user_data, err);
+ goto out;
+ }
- if ((ret = polkit_authorization_result_get_is_authorized (result)) == FALSE) {
- g_propagate_error (error,
- g_error_new (POLKIT_ERROR, POLKIT_ERROR_NOT_AUTHORIZED,
- "Authorizing for '%s': not authorized", action_id));
+ if (!polkit_authorization_result_get_is_authorized (result)) {
+ g_simple_async_report_error_in_idle (NULL, data->callback, data->user_data, POLKIT_ERROR, POLKIT_ERROR_NOT_AUTHORIZED, "Authorizing for '%s': not authorized", data->action_id);
+ goto out;
}
-
- end:
+ simple = g_simple_async_result_new (NULL, data->callback, data->user_data, check_polkit_async);
+ g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ g_simple_async_result_complete_in_idle (simple);
+ g_object_unref (simple);
+
+ out:
+ check_polkit_data_free (data);
if (result != NULL)
g_object_unref (result);
- if (subject != NULL)
- g_object_unref (subject);
- if (authority != NULL)
- g_object_unref (authority);
- return ret;
+}
+
+static void
+check_polkit_authority_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer _data)
+{
+ struct check_polkit_data *data;
+ GError *err = NULL;
+
+ data = (struct check_polkit_data *) _data;
+ if ((data->authority = polkit_authority_get_finish (res, &err)) == NULL) {
+ g_simple_async_report_take_gerror_in_idle (NULL, data->callback, data->user_data, err);
+ check_polkit_data_free (data);
+ return;
+ }
+ if (data->unique_name == NULL || data->action_id == NULL ||
+ (data->subject = polkit_system_bus_name_new (data->unique_name)) == NULL) {
+ g_simple_async_report_error_in_idle (NULL, data->callback, data->user_data, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Authorizing for '%s': failed sanity check", data->action_id);
+ check_polkit_data_free (data);
+ return;
+ }
+ polkit_authority_check_authorization (data->authority, data->subject, data->action_id, NULL, (PolkitCheckAuthorizationFlags) data->user_interaction, NULL, check_polkit_authorization_cb, data);
+}
+
+void
+check_polkit_async (const gchar *unique_name,
+ const gchar *action_id,
+ const gboolean user_interaction,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ struct check_polkit_data *data;
+
+ data = g_new0 (struct check_polkit_data, 1);
+ data->unique_name = unique_name;
+ data->action_id = action_id;
+ data->user_interaction = user_interaction;
+ data->callback = callback;
+ data->user_data = user_data;
+
+ polkit_authority_get_async (NULL, check_polkit_authority_cb, data);
}
\ No newline at end of file
diff --git a/src/bus-utils.h b/src/bus-utils.h
index 31a2ef1..f2e80ea 100644
--- a/src/bus-utils.h
+++ b/src/bus-utils.h
@@ -21,10 +21,15 @@
#include <glib.h>
+void
+check_polkit_async (const gchar *unique_name,
+ const gchar *action_id,
+ const gboolean user_interaction,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
gboolean
-check_polkit (const gchar *unique_name,
- const gchar *action_id,
- const gboolean user_interaction,
- GError **error);
+check_polkit_finish (GAsyncResult *res,
+ GError **error);
#endif
\ No newline at end of file
diff --git a/src/hostnamed.c b/src/hostnamed.c
index 4f95d04..c5914bd 100644
--- a/src/hostnamed.c
+++ b/src/hostnamed.c
@@ -36,6 +36,11 @@
#define QUOTE(macro) #macro
#define STR(macro) QUOTE(macro)
+struct invoked_name {
+ GDBusMethodInvocation *invocation;
+ gchar *name; /* newly allocated */
+};
+
guint bus_id = 0;
gboolean read_only = FALSE;
@@ -103,152 +108,250 @@ guess_icon_name ()
icon_name = g_strdup ("computer");
}
-static gboolean
-on_handle_set_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
- GDBusMethodInvocation *invocation,
- const gchar *name,
- const gboolean user_interaction,
- gpointer user_data)
+static void
+on_handle_set_hostname_authorized_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
GError *err = NULL;
-
- if (read_only) {
- g_dbus_method_invocation_return_dbus_error (invocation,
- DBUS_ERROR_NOT_SUPPORTED,
- "openrc-settingsd hostnamed is in read-only mode");
- goto end;
- }
-
- if (!check_polkit (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.hostname1.set-hostname", user_interaction, &err)) {
- g_dbus_method_invocation_return_gerror (invocation, err);
- goto end;
+ struct invoked_name *data;
+
+ data = (struct invoked_name *) user_data;
+ if (!check_polkit_finish (res, &err)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
+ goto out;
}
G_LOCK (hostname);
/* Don't allow an empty or invalid hostname */
- if (!hostname_is_valid (name)) {
- name = hostname;
- if (!hostname_is_valid (name))
- name = "localhost";
+ if (!hostname_is_valid (data->name)) {
+ if (data->name != NULL)
+ g_free (data->name);
+
+ if (hostname_is_valid (hostname))
+ data->name = g_strdup (hostname);
+ else
+ data->name = g_strdup ("localhost");
}
- if (sethostname (name, strlen(name))) {
+ if (sethostname (data->name, strlen(data->name))) {
int errsv = errno;
- g_dbus_method_invocation_return_dbus_error (invocation,
+ g_dbus_method_invocation_return_dbus_error (data->invocation,
DBUS_ERROR_FAILED,
strerror (errsv));
G_UNLOCK (hostname);
- goto end;
+ goto out;
}
- g_strlcpy (hostname, name, HOST_NAME_MAX + 1);
- openrc_settingsd_hostnamed_hostname1_complete_set_hostname (hostname1, invocation);
+ g_strlcpy (hostname, data->name, HOST_NAME_MAX + 1);
+ openrc_settingsd_hostnamed_hostname1_complete_set_hostname (hostname1, data->invocation);
openrc_settingsd_hostnamed_hostname1_set_hostname (hostname1, hostname);
G_UNLOCK (hostname);
- end:
- return TRUE;
+ out:
+ g_free (data->name);
+ g_free (data);
+ if (err != NULL)
+ g_error_free (err);
}
static gboolean
-on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
- GDBusMethodInvocation *invocation,
- const gchar *name,
- const gboolean user_interaction,
- gpointer user_data)
+on_handle_set_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
+ GDBusMethodInvocation *invocation,
+ const gchar *name,
+ const gboolean user_interaction,
+ gpointer user_data)
{
- ShellUtilsTrivial *confd_file = NULL;
- GError *err = NULL;
-
- if (read_only) {
+ if (read_only)
g_dbus_method_invocation_return_dbus_error (invocation,
DBUS_ERROR_NOT_SUPPORTED,
"openrc-settingsd hostnamed is in read-only mode");
- goto end;
+ else {
+ struct invoked_name *data;
+ data = g_new0 (struct invoked_name, 1);
+ data->invocation = invocation;
+ data->name = g_strdup (name);
+ check_polkit_async (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.hostname1.set-hostname", user_interaction, on_handle_set_hostname_authorized_cb, data);
}
- if (!check_polkit (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.hostname1.set-static-hostname", user_interaction, &err)) {
- g_dbus_method_invocation_return_gerror (invocation, err);
- goto end;
+ return TRUE;
+}
+
+static void
+on_handle_set_static_hostname_authorized_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *err = NULL;
+ struct invoked_name *data;
+
+ data = (struct invoked_name *) user_data;
+ if (!check_polkit_finish (res, &err)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
+ goto out;
}
G_LOCK (static_hostname);
/* Don't allow an empty or invalid hostname */
- if (!hostname_is_valid (name))
- name = "localhost";
+ if (!hostname_is_valid (data->name)) {
+ if (data->name != NULL)
+ g_free (data->name);
+
+ data->name = g_strdup ("localhost");
+ }
- if (!shell_utils_trivial_set_and_save (static_hostname_file, &err, "hostname", "HOSTNAME", name, NULL)) {
- g_dbus_method_invocation_return_gerror (invocation, err);
+ if (!shell_utils_trivial_set_and_save (static_hostname_file, &err, "hostname", "HOSTNAME", data->name, NULL)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
G_UNLOCK (static_hostname);
- goto end;
+ goto out;
}
g_free (static_hostname);
- static_hostname = g_strdup (name);
- openrc_settingsd_hostnamed_hostname1_complete_set_static_hostname (hostname1, invocation);
+ static_hostname = data->name; /* data->name is g_strdup-ed already */;
+ openrc_settingsd_hostnamed_hostname1_complete_set_static_hostname (hostname1, data->invocation);
openrc_settingsd_hostnamed_hostname1_set_static_hostname (hostname1, static_hostname);
G_UNLOCK (static_hostname);
- end:
- shell_utils_trivial_free (confd_file);
+ out:
+ g_free (data);
if (err != NULL)
g_error_free (err);
+}
+
+static gboolean
+on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
+ GDBusMethodInvocation *invocation,
+ const gchar *name,
+ const gboolean user_interaction,
+ gpointer user_data)
+{
+ if (read_only)
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ DBUS_ERROR_NOT_SUPPORTED,
+ "openrc-settingsd hostnamed is in read-only mode");
+ else {
+ struct invoked_name *data;
+ data = g_new0 (struct invoked_name, 1);
+ data->invocation = invocation;
+ data->name = g_strdup (name);
+ check_polkit_async (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.hostname1.set-static-hostname", user_interaction, on_handle_set_static_hostname_authorized_cb, data);
+ }
return TRUE; /* Always return TRUE to indicate signal has been handled */
}
-static gboolean
-on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1,
- GDBusMethodInvocation *invocation,
- const gchar *name,
- const gboolean user_interaction,
- gpointer user_data)
+static void
+on_handle_set_pretty_hostname_authorized_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- ShellUtilsTrivial *confd_file = NULL;
GError *err = NULL;
- gboolean is_pretty_hostname = GPOINTER_TO_INT(user_data);
+ struct invoked_name *data;
+
+ data = (struct invoked_name *) user_data;
+ if (!check_polkit_finish (res, &err)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
+ goto out;
+ }
+
+ G_LOCK (machine_info);
+ /* Don't allow a null pretty hostname */
+ if (data->name == NULL)
+ data->name = g_strdup ("");
- if (read_only) {
+ if (!shell_utils_trivial_set_and_save (machine_info_file, &err, "PRETTY_HOSTNAME", NULL, data->name, NULL)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
+ G_UNLOCK (machine_info);
+ goto out;
+ }
+
+ g_free (pretty_hostname);
+ pretty_hostname = data->name; /* data->name is g_strdup-ed already */
+ openrc_settingsd_hostnamed_hostname1_complete_set_pretty_hostname (hostname1, data->invocation);
+ openrc_settingsd_hostnamed_hostname1_set_pretty_hostname (hostname1, pretty_hostname);
+ G_UNLOCK (machine_info);
+
+ out:
+ g_free (data);
+ if (err != NULL)
+ g_error_free (err);
+}
+
+static gboolean
+on_handle_set_pretty_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1,
+ GDBusMethodInvocation *invocation,
+ const gchar *name,
+ const gboolean user_interaction,
+ gpointer user_data)
+{
+ if (read_only)
g_dbus_method_invocation_return_dbus_error (invocation,
DBUS_ERROR_NOT_SUPPORTED,
"openrc-settingsd hostnamed is in read-only mode");
- goto end;
+ else {
+ struct invoked_name *data;
+ data = g_new0 (struct invoked_name, 1);
+ data->invocation = invocation;
+ data->name = g_strdup (name);
+ check_polkit_async (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.hostname1.set-machine-info", user_interaction, on_handle_set_pretty_hostname_authorized_cb, data);
}
- if (!check_polkit (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.hostname1.set-machine-info", user_interaction, &err)) {
- g_dbus_method_invocation_return_gerror (invocation, err);
- goto end;
+ return TRUE; /* Always return TRUE to indicate signal has been handled */
+}
+
+static void
+on_handle_set_icon_name_authorized_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *err = NULL;
+ struct invoked_name *data;
+
+ data = (struct invoked_name *) user_data;
+ if (!check_polkit_finish (res, &err)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
+ goto out;
}
G_LOCK (machine_info);
/* Don't allow a null pretty hostname */
- if (name == NULL)
- name = "";
+ if (data->name == NULL)
+ data->name = g_strdup ("");
- if ((is_pretty_hostname &&
- !shell_utils_trivial_set_and_save (machine_info_file, &err, "PRETTY_HOSTNAME", NULL, name, NULL)) ||
- (!is_pretty_hostname &&
- !shell_utils_trivial_set_and_save (machine_info_file, &err, "ICON_NAME", NULL, name, NULL))) {
- g_dbus_method_invocation_return_gerror (invocation, err);
+ if (!shell_utils_trivial_set_and_save (machine_info_file, &err, "ICON_NAME", NULL, data->name, NULL)) {
+ g_dbus_method_invocation_return_gerror (data->invocation, err);
G_UNLOCK (machine_info);
- goto end;
+ goto out;
}
- if (is_pretty_hostname) {
- g_free (pretty_hostname);
- pretty_hostname = g_strdup (name);
- openrc_settingsd_hostnamed_hostname1_complete_set_pretty_hostname (hostname1, invocation);
- openrc_settingsd_hostnamed_hostname1_set_pretty_hostname (hostname1, pretty_hostname);
- } else {
- g_free (icon_name);
- icon_name = g_strdup (name);
- openrc_settingsd_hostnamed_hostname1_complete_set_icon_name (hostname1, invocation);
- openrc_settingsd_hostnamed_hostname1_set_icon_name (hostname1, icon_name);
- }
+ g_free (icon_name);
+ icon_name = data->name; /* data->name is g_strdup-ed already */
+ openrc_settingsd_hostnamed_hostname1_complete_set_icon_name (hostname1, data->invocation);
+ openrc_settingsd_hostnamed_hostname1_set_icon_name (hostname1, icon_name);
G_UNLOCK (machine_info);
- end:
- shell_utils_trivial_free (confd_file);
+ out:
+ g_free (data);
if (err != NULL)
g_error_free (err);
+}
+
+static gboolean
+on_handle_set_icon_name (OpenrcSettingsdHostnamedHostname1 *hostname1,
+ GDBusMethodInvocation *invocation,
+ const gchar *name,
+ const gboolean user_interaction,
+ gpointer user_data)
+{
+ if (read_only)
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ DBUS_ERROR_NOT_SUPPORTED,
+ "openrc-settingsd hostnamed is in read-only mode");
+ else {
+ struct invoked_name *data;
+ data = g_new0 (struct invoked_name, 1);
+ data->invocation = invocation;
+ data->name = g_strdup (name);
+ check_polkit_async (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.hostname1.set-machine-info", user_interaction, on_handle_set_icon_name_authorized_cb, data);
+ }
return TRUE; /* Always return TRUE to indicate signal has been handled */
}
@@ -272,8 +375,8 @@ on_bus_acquired (GDBusConnection *connection,
g_signal_connect (hostname1, "handle-set-hostname", G_CALLBACK (on_handle_set_hostname), NULL);
g_signal_connect (hostname1, "handle-set-static-hostname", G_CALLBACK (on_handle_set_static_hostname), NULL);
- g_signal_connect (hostname1, "handle-set-pretty-hostname", G_CALLBACK (on_handle_set_machine_info), GINT_TO_POINTER(TRUE));
- g_signal_connect (hostname1, "handle-set-icon-name", G_CALLBACK (on_handle_set_machine_info), GINT_TO_POINTER(FALSE));
+ g_signal_connect (hostname1, "handle-set-pretty-hostname", G_CALLBACK (on_handle_set_pretty_hostname), NULL);
+ g_signal_connect (hostname1, "handle-set-icon-name", G_CALLBACK (on_handle_set_icon_name), NULL);
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (hostname1),
connection,
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-02-08 5:01 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-02-08 5:01 UTC (permalink / raw
To: gentoo-commits
commit: fb55754fc1b2ad11dc51ed96126fc0cfacab569b
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 8 04:01:45 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Wed Feb 8 04:01:45 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=fb55754f
Fix transient hostname error handling, and dynamically allocate it
Ensure that setting the transient hostname behaves as described in
http://www.freedesktop.org/wiki/Software/systemd/hostnamed
---
src/hostnamed.c | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/hostnamed.c b/src/hostnamed.c
index c5f6f9c..88c166e 100644
--- a/src/hostnamed.c
+++ b/src/hostnamed.c
@@ -46,7 +46,7 @@ gboolean read_only = FALSE;
static OpenrcSettingsdHostnamedHostname1 *hostname1 = NULL;
-static gchar hostname[HOST_NAME_MAX + 1];
+static gchar *hostname = NULL;
G_LOCK_DEFINE_STATIC (hostname);
static gchar *static_hostname = NULL;
static GFile *static_hostname_file = NULL;
@@ -128,8 +128,8 @@ on_handle_set_hostname_authorized_cb (GObject *source_object,
if (data->name != NULL)
g_free (data->name);
- if (hostname_is_valid (hostname))
- data->name = g_strdup (hostname);
+ if (hostname_is_valid (static_hostname))
+ data->name = g_strdup (static_hostname);
else
data->name = g_strdup ("localhost");
}
@@ -141,13 +141,13 @@ on_handle_set_hostname_authorized_cb (GObject *source_object,
G_UNLOCK (hostname);
goto out;
}
- g_strlcpy (hostname, data->name, HOST_NAME_MAX + 1);
+ g_free (hostname);
+ hostname = data->name; /* data->name is g_strdup-ed already */;
openrc_settingsd_hostnamed_hostname1_complete_set_hostname (hostname1, data->invocation);
openrc_settingsd_hostnamed_hostname1_set_hostname (hostname1, hostname);
G_UNLOCK (hostname);
out:
- g_free (data->name);
g_free (data);
if (err != NULL)
g_error_free (err);
@@ -416,10 +416,10 @@ hostnamed_init (gboolean _read_only)
{
GError *err = NULL;
- memset (hostname, 0, HOST_NAME_MAX + 1);
+ hostname = g_malloc0 (HOST_NAME_MAX + 1);
if (gethostname (hostname, HOST_NAME_MAX)) {
perror (NULL);
- hostname[0] = 0;
+ g_strlcpy (hostname, "localhost", HOST_NAME_MAX + 1);
}
static_hostname_file = g_file_new_for_path (SYSCONFDIR "/conf.d/hostname");
@@ -470,6 +470,7 @@ hostnamed_destroy (void)
bus_id = 0;
read_only = FALSE;
memset (hostname, 0, HOST_NAME_MAX + 1);
+ g_free (hostname);
g_free (static_hostname);
g_free (pretty_hostname);
g_free (icon_name);
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-02-08 5:57 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-02-08 5:57 UTC (permalink / raw
To: gentoo-commits
commit: d115eb0c9710c1701d66df0a1394d803b1c3c2b9
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 8 05:54:18 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Wed Feb 8 05:54:18 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=d115eb0c
Unneeded #include
---
src/hostnamed.h | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/src/hostnamed.h b/src/hostnamed.h
index e3107a0..cf1606a 100644
--- a/src/hostnamed.h
+++ b/src/hostnamed.h
@@ -21,7 +21,6 @@
#include <glib.h>
#include <gio/gio.h>
-#include <polkit/polkit.h>
void
hostnamed_on_bus_acquired (GDBusConnection *connection,
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-02-08 6:53 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-02-08 6:53 UTC (permalink / raw
To: gentoo-commits
commit: c3516b35670967090b6851f77e5f90648607a900
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 8 06:40:57 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Wed Feb 8 06:40:57 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=c3516b35
hostname is dynamically allocated now
---
src/hostnamed.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/src/hostnamed.c b/src/hostnamed.c
index df522c5..f0992bd 100644
--- a/src/hostnamed.c
+++ b/src/hostnamed.c
@@ -469,7 +469,6 @@ hostnamed_destroy (void)
g_bus_unown_name (bus_id);
bus_id = 0;
read_only = FALSE;
- memset (hostname, 0, HOST_NAME_MAX + 1);
g_free (hostname);
g_free (static_hostname);
g_free (pretty_hostname);
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-03-18 11:02 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-03-18 11:02 UTC (permalink / raw
To: gentoo-commits
commit: 749e33db64ef0c97155758c093ad1e3fce398141
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 18 10:59:39 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Sun Mar 18 10:59:39 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=749e33db
Add a simplistic xorg.conf.d/30-keyboard.conf parser
---
src/localed.c | 471 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 471 insertions(+), 0 deletions(-)
diff --git a/src/localed.c b/src/localed.c
index 12d9ad7..0dc8765 100644
--- a/src/localed.c
+++ b/src/localed.c
@@ -17,6 +17,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include <dbus/dbus-protocol.h>
#include <glib.h>
@@ -53,8 +54,455 @@ static gchar *x11_layout = NULL;
static gchar *x11_model = NULL;
static gchar *x11_variant = NULL;
static gchar *x11_options = NULL;
+static GFile *x11_gentoo_file = NULL;
+static GFile *x11_systemd_file = NULL;
G_LOCK_DEFINE_STATIC (xorg_conf);
+/* Trivial /etc/X11/xorg.conf.d/30-keyboard.conf parser */
+
+enum XORG_CONFD_LINE_TYPE {
+ XORG_CONFD_LINE_TYPE_UNKNOWN,
+ XORG_CONFD_LINE_TYPE_COMMENT,
+ XORG_CONFD_LINE_TYPE_SECTION_INPUT_CLASS,
+ XORG_CONFD_LINE_TYPE_SECTION_OTHER,
+ XORG_CONFD_LINE_TYPE_END_SECTION,
+ XORG_CONFD_LINE_TYPE_MATCH_IS_KEYBOARD,
+ XORG_CONFD_LINE_TYPE_XKB_LAYOUT,
+ XORG_CONFD_LINE_TYPE_XKB_MODEL,
+ XORG_CONFD_LINE_TYPE_XKB_VARIANT,
+ XORG_CONFD_LINE_TYPE_XKB_OPTIONS,
+};
+
+GRegex *xorg_confd_line_comment_re = NULL;
+GRegex *xorg_confd_line_section_input_class_re = NULL;
+GRegex *xorg_confd_line_section_re = NULL;
+GRegex *xorg_confd_line_end_section_re = NULL;
+GRegex *xorg_confd_line_match_is_keyboard_re = NULL;
+GRegex *xorg_confd_line_xkb_layout_re = NULL;
+GRegex *xorg_confd_line_xkb_model_re = NULL;
+GRegex *xorg_confd_line_xkb_variant_re = NULL;
+GRegex *xorg_confd_line_xkb_options_re = NULL;
+
+struct xorg_confd_line_entry {
+ gchar *string;
+ gchar *value; /* for one of the options we are interested in */
+ enum XORG_CONFD_LINE_TYPE type;
+};
+
+struct xorg_confd_parser {
+ GFile *file;
+ gchar *filename;
+ GList *line_list;
+ GList *section; /* start of relevant InputClass section */
+};
+
+static void
+xorg_confd_regex_destroy ()
+{
+ if (xorg_confd_line_comment_re != NULL) {
+ g_regex_unref (xorg_confd_line_comment_re);
+ xorg_confd_line_comment_re = NULL;
+ }
+ if (xorg_confd_line_section_input_class_re != NULL) {
+ g_regex_unref (xorg_confd_line_section_input_class_re);
+ xorg_confd_line_section_input_class_re = NULL;
+ }
+ if (xorg_confd_line_section_re != NULL) {
+ g_regex_unref (xorg_confd_line_section_re);
+ xorg_confd_line_section_re = NULL;
+ }
+ if (xorg_confd_line_end_section_re != NULL) {
+ g_regex_unref (xorg_confd_line_end_section_re);
+ xorg_confd_line_end_section_re = NULL;
+ }
+ if (xorg_confd_line_match_is_keyboard_re != NULL) {
+ g_regex_unref (xorg_confd_line_match_is_keyboard_re);
+ xorg_confd_line_match_is_keyboard_re = NULL;
+ }
+ if (xorg_confd_line_xkb_layout_re != NULL) {
+ g_regex_unref (xorg_confd_line_xkb_layout_re);
+ xorg_confd_line_xkb_layout_re = NULL;
+ }
+ if (xorg_confd_line_xkb_model_re != NULL) {
+ g_regex_unref (xorg_confd_line_xkb_model_re);
+ xorg_confd_line_xkb_model_re = NULL;
+ }
+ if (xorg_confd_line_xkb_variant_re != NULL) {
+ g_regex_unref (xorg_confd_line_xkb_variant_re);
+ xorg_confd_line_xkb_variant_re = NULL;
+ }
+ if (xorg_confd_line_xkb_options_re != NULL) {
+ g_regex_unref (xorg_confd_line_xkb_options_re);
+ xorg_confd_line_xkb_options_re = NULL;
+ }
+}
+
+static void
+xorg_confd_regex_init ()
+{
+ if (xorg_confd_line_comment_re == NULL) {
+ xorg_confd_line_comment_re = g_regex_new ("^\\s*#", G_REGEX_ANCHORED|G_REGEX_CASELESS, 0, NULL);
+ g_assert (xorg_confd_line_comment_re != NULL);
+ }
+ if (xorg_confd_line_section_input_class_re == NULL) {
+ xorg_confd_line_section_input_class_re = g_regex_new ("^\\s*Section\\s+\"InputClass\"", G_REGEX_ANCHORED|G_REGEX_CASELESS, 0, NULL);
+ g_assert (xorg_confd_line_section_input_class_re != NULL);
+ }
+ if (xorg_confd_line_section_re == NULL) {
+ xorg_confd_line_section_re = g_regex_new ("^\\s*Section\\s+\"([^\"])\"", G_REGEX_ANCHORED|G_REGEX_CASELESS, 0, NULL);
+ g_assert (xorg_confd_line_section_re != NULL);
+ }
+ if (xorg_confd_line_end_section_re == NULL) {
+ xorg_confd_line_end_section_re = g_regex_new ("^\\s*EndSection", G_REGEX_ANCHORED|G_REGEX_CASELESS, 0, NULL);
+ g_assert (xorg_confd_line_end_section_re != NULL);
+ }
+ if (xorg_confd_line_match_is_keyboard_re == NULL) {
+ xorg_confd_line_match_is_keyboard_re = g_regex_new ("^\\s*MatchIsKeyboard(?:\\s*$|\\s+\"(?:1|on|true|yes)\")", G_REGEX_ANCHORED|G_REGEX_CASELESS, 0, NULL);
+ g_assert (xorg_confd_line_match_is_keyboard_re != NULL);
+ }
+ if (xorg_confd_line_xkb_layout_re == NULL) {
+ xorg_confd_line_xkb_layout_re = g_regex_new ("^(\\s*Option\\s+\"XkbLayout\"\\s+)\"([^\"]*)\"", G_REGEX_ANCHORED|G_REGEX_CASELESS, 0, NULL);
+ g_assert (xorg_confd_line_xkb_layout_re != NULL);
+ }
+ if (xorg_confd_line_xkb_model_re == NULL) {
+ xorg_confd_line_xkb_model_re = g_regex_new ("^(\\s*Option\\s+\"XkbModel\"\\s+)\"([^\"]*)\"", G_REGEX_ANCHORED|G_REGEX_CASELESS, 0, NULL);
+ g_assert (xorg_confd_line_xkb_model_re != NULL);
+ }
+ if (xorg_confd_line_xkb_variant_re == NULL) {
+ xorg_confd_line_xkb_variant_re = g_regex_new ("^(\\s*Option\\s+\"XkbVariant\"\\s+)\"([^\"]*)\"", G_REGEX_ANCHORED|G_REGEX_CASELESS, 0, NULL);
+ g_assert (xorg_confd_line_xkb_variant_re != NULL);
+ }
+ if (xorg_confd_line_xkb_options_re == NULL) {
+ xorg_confd_line_xkb_options_re = g_regex_new ("^(\\s*Option\\s+\"XkbOptions\"\\s+)\"([^\"]*)\"", G_REGEX_ANCHORED|G_REGEX_CASELESS, 0, NULL);
+ g_assert (xorg_confd_line_xkb_options_re != NULL);
+ }
+}
+
+static void
+xorg_confd_line_entry_free (struct xorg_confd_line_entry *entry)
+{
+ if (entry == NULL)
+ return;
+
+ g_free (entry->string);
+ g_free (entry->value);
+
+ g_free (entry);
+}
+
+static void
+xorg_confd_parser_free (struct xorg_confd_parser *parser)
+{
+ if (parser == NULL)
+ return;
+
+ if (parser->file != NULL)
+ g_object_unref (parser->file);
+
+ g_free (parser->filename);
+
+ if (parser->line_list != NULL)
+ g_list_free_full (parser->line_list, (GDestroyNotify)xorg_confd_line_entry_free);
+
+ g_free (parser);
+}
+
+static struct xorg_confd_parser *
+xorg_confd_parser_new (GFile *xorg_confd_file,
+ GError **error)
+{
+ struct xorg_confd_parser *parser = NULL;
+ gchar *filebuf = NULL;
+ gchar **linebuf = NULL;
+ gchar **lines = NULL;
+ GList *input_class_section_start = NULL;
+ gboolean in_section = FALSE, in_xkb_section = FALSE;
+
+ if (xorg_confd_file == NULL)
+ return NULL;
+
+ parser = g_new0 (struct xorg_confd_parser, 1);
+ parser->file = g_object_ref (xorg_confd_file);
+ parser->filename = g_file_get_path (xorg_confd_file);
+ g_debug ("Parsing xorg.conf.d file: '%s'", parser->filename);
+ if (!g_file_load_contents (xorg_confd_file, NULL, &filebuf, NULL, NULL, error)) {
+ g_prefix_error (error, "Unable to read '%s':", parser->filename);
+ goto fail;
+ }
+
+ lines = g_strsplit (filebuf, "\n", 0);
+ if (lines == NULL)
+ goto out;
+
+ for (linebuf = lines; *linebuf != NULL; linebuf++) {
+ struct xorg_confd_line_entry *entry = NULL;
+ GMatchInfo *match_info = NULL;
+ gboolean matched = FALSE;
+
+ entry = g_new0 (struct xorg_confd_line_entry, 1);
+ entry->string = *linebuf;
+ entry->type = XORG_CONFD_LINE_TYPE_UNKNOWN;
+
+ if (g_regex_match (xorg_confd_line_comment_re, *linebuf, 0, &match_info)) {
+ g_debug ("Parsed line '%s' as comment", *linebuf);
+ entry->type = XORG_CONFD_LINE_TYPE_COMMENT;
+ } else if (g_regex_match (xorg_confd_line_section_input_class_re, *linebuf, 0, &match_info)) {
+ g_debug ("Parsed line '%s' as InputClass section", *linebuf);
+ if (in_section)
+ goto no_match;
+ in_section = TRUE;
+ entry->type = XORG_CONFD_LINE_TYPE_SECTION_INPUT_CLASS;
+ } else if (g_regex_match (xorg_confd_line_section_re, *linebuf, 0, &match_info)) {
+ g_debug ("Parsed line '%s' as non-InputClass section", *linebuf);
+ if (in_section)
+ goto no_match;
+ in_section = TRUE;
+ entry->type = XORG_CONFD_LINE_TYPE_SECTION_OTHER;
+ } else if (g_regex_match (xorg_confd_line_end_section_re, *linebuf, 0, &match_info)) {
+ g_debug ("Parsed line '%s' as end of section", *linebuf);
+ if (!in_section)
+ goto no_match;
+ entry->type = XORG_CONFD_LINE_TYPE_END_SECTION;
+ } else if (g_regex_match (xorg_confd_line_match_is_keyboard_re, *linebuf, 0, &match_info)) {
+ g_debug ("Parsed line '%s' as MatchIsKeyboard declaration", *linebuf);
+ if (!in_section)
+ goto no_match;
+ entry->type = XORG_CONFD_LINE_TYPE_MATCH_IS_KEYBOARD;
+ in_xkb_section = TRUE;
+ } else if (g_regex_match (xorg_confd_line_xkb_layout_re, *linebuf, 0, &match_info)) {
+ g_debug ("Parsed line '%s' as XkbLayout option", *linebuf);
+ if (!in_section)
+ goto no_match;
+ entry->type = XORG_CONFD_LINE_TYPE_XKB_LAYOUT;
+ entry->value = g_match_info_fetch (match_info, 2);
+ } else if (g_regex_match (xorg_confd_line_xkb_model_re, *linebuf, 0, &match_info)) {
+ g_debug ("Parsed line '%s' as XkbModel option", *linebuf);
+ if (!in_section)
+ goto no_match;
+ entry->type = XORG_CONFD_LINE_TYPE_XKB_MODEL;
+ entry->value = g_match_info_fetch (match_info, 2);
+ } else if (g_regex_match (xorg_confd_line_xkb_variant_re, *linebuf, 0, &match_info)) {
+ g_debug ("Parsed line '%s' as XkbVariant option", *linebuf);
+ if (!in_section)
+ goto no_match;
+ entry->type = XORG_CONFD_LINE_TYPE_XKB_VARIANT;
+ entry->value = g_match_info_fetch (match_info, 2);
+ } else if (g_regex_match (xorg_confd_line_xkb_options_re, *linebuf, 0, &match_info)) {
+ g_debug ("Parsed line '%s' as XkbOptions option", *linebuf);
+ if (!in_section)
+ goto no_match;
+ entry->type = XORG_CONFD_LINE_TYPE_XKB_OPTIONS;
+ entry->value = g_match_info_fetch (match_info, 2);
+ }
+
+ if (entry->type == XORG_CONFD_LINE_TYPE_UNKNOWN)
+ g_debug ("Parsing line '%s' as unknown", *linebuf);
+
+ g_match_info_free (match_info);
+ parser->line_list = g_list_prepend (parser->line_list, entry);
+ if (in_section) {
+ if (entry->type == XORG_CONFD_LINE_TYPE_SECTION_INPUT_CLASS)
+ input_class_section_start = parser->line_list;
+ else if (entry->type == XORG_CONFD_LINE_TYPE_END_SECTION) {
+ if (in_xkb_section)
+ parser->section = input_class_section_start;
+
+ input_class_section_start = NULL;
+ in_section = FALSE;
+ in_xkb_section = FALSE;
+ }
+ }
+ continue;
+
+ no_match:
+ /* Nothing matched... */
+ g_free (entry);
+ g_match_info_free (match_info);
+ goto parse_fail;
+ }
+
+ if (in_section) {
+ /* Unterminated section */
+ goto parse_fail;
+ }
+
+ parser->line_list = g_list_reverse (parser->line_list);
+
+ out:
+ g_free (filebuf);
+ return parser;
+
+ parse_fail:
+ g_propagate_error (error,
+ g_error_new (G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ "Unable to parse '%s'", parser->filename));
+ fail:
+ g_free (filebuf);
+ g_strfreev (lines);
+ xorg_confd_parser_free (parser);
+ return NULL;
+}
+
+static void
+xorg_confd_parser_get_xkb (const struct xorg_confd_parser *parser,
+ gchar **layout_p,
+ gchar **model_p,
+ gchar **variant_p,
+ gchar **options_p)
+{
+ GList *curr = NULL;
+ gchar *layout = NULL, *model = NULL, *variant = NULL, *options = NULL;
+
+ if (parser == NULL)
+ return;
+ for (curr = parser->section; curr != NULL; curr = curr->next) {
+ GMatchInfo *match_info = NULL;
+ struct xorg_confd_line_entry *entry = (struct xorg_confd_line_entry *) curr->data;
+
+ if (entry->type == XORG_CONFD_LINE_TYPE_END_SECTION)
+ break;
+ else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_LAYOUT)
+ layout = entry->value;
+ else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_MODEL)
+ model = entry->value;
+ else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_VARIANT)
+ variant = entry->value;
+ else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_OPTIONS)
+ options = entry->value;
+ }
+ *layout_p = g_strdup (layout);
+ *model_p = g_strdup (model);
+ *variant_p = g_strdup (variant);
+ *options_p = g_strdup (options);
+}
+
+static GList *
+xorg_confd_parser_line_set_or_delete (GList *line,
+ const gchar *value,
+ const GRegex *re)
+{
+ gchar *replacement = NULL, *replaced = NULL;
+
+ g_assert (line != NULL);
+
+ struct xorg_confd_line_entry *entry = (struct xorg_confd_line_entry *) line->data;
+
+ if (value == NULL || !g_strcmp0 (value, "")) {
+ /* If value is null, we delete the line and return previous one */
+ GList *prev = line->prev;
+ prev->next = line->next;
+ prev->next->prev = prev;
+ line->prev = NULL;
+ line->next = NULL;
+ g_list_free_full (line, (GDestroyNotify)xorg_confd_line_entry_free);
+ return prev;
+ }
+ entry->value = g_strdup (value);
+ replacement = g_strdup_printf ("\1\"%s\"", value);
+ replaced = g_regex_replace (re, entry->string, 0, 0, replacement, 0, NULL);
+ g_free (replacement);
+ g_free (entry->string);
+ entry->string = replaced;
+
+ return line;
+}
+
+static void
+xorg_confd_parser_set_xkb (struct xorg_confd_parser *parser,
+ const gchar *layout,
+ const gchar *model,
+ const gchar *variant,
+ const gchar *options)
+{
+ GList *curr = NULL;
+ gboolean layout_found = FALSE, model_found = FALSE, variant_found = FALSE, options_found = FALSE;
+
+ if (parser == NULL)
+ return;
+
+ if (parser->section == NULL) {
+ struct xorg_confd_line_entry *entry = NULL;
+ GList *section = NULL;
+
+ entry = g_new0 (struct xorg_confd_line_entry, 1);
+ entry->string = g_strdup("Section \"InputClass\"\n");
+ entry->type = XORG_CONFD_LINE_TYPE_SECTION_INPUT_CLASS;
+ section = g_list_prepend (section, entry);
+
+ entry = g_new0 (struct xorg_confd_line_entry, 1);
+ entry->string = g_strdup("MatchIsKeyboard \"on\"\n");
+ entry->type = XORG_CONFD_LINE_TYPE_MATCH_IS_KEYBOARD;
+ section = g_list_prepend (section, entry);
+
+ entry = g_new0 (struct xorg_confd_line_entry, 1);
+ entry->string = g_strdup("EndSection\n");
+ entry->type = XORG_CONFD_LINE_TYPE_END_SECTION;
+ section = g_list_prepend (section, entry);
+
+ section = g_list_reverse (section);
+ parser->section = section;
+ parser->line_list = g_list_concat (parser->line_list, section);
+ }
+
+ for (curr = parser->section; curr != NULL; curr = curr->next) {
+ struct xorg_confd_line_entry *entry = (struct xorg_confd_line_entry *) curr->data;
+
+ if (entry->type == XORG_CONFD_LINE_TYPE_END_SECTION)
+ break;
+ else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_LAYOUT)
+ curr = xorg_confd_parser_line_set_or_delete (curr, layout, xorg_confd_line_xkb_layout_re);
+ else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_MODEL)
+ curr = xorg_confd_parser_line_set_or_delete (curr, model, xorg_confd_line_xkb_model_re);
+ else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_VARIANT)
+ curr = xorg_confd_parser_line_set_or_delete (curr, variant, xorg_confd_line_xkb_variant_re);
+ else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_OPTIONS)
+ curr = xorg_confd_parser_line_set_or_delete (curr, options, xorg_confd_line_xkb_options_re);
+ }
+}
+
+static gboolean
+xorg_confd_parser_save (const struct xorg_confd_parser *parser,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ GList *curr = NULL;
+ GFileOutputStream *os;
+
+ g_assert (parser != NULL && parser->file != NULL && parser->filename != NULL);
+ if ((os = g_file_replace (parser->file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, error)) == NULL) {
+ g_prefix_error (error, "Unable to save '%s': ", parser->filename);
+ goto out;
+ }
+
+ for (curr = parser->line_list; curr != NULL; curr = curr->next) {
+ struct xorg_confd_line_entry *entry = (struct xorg_confd_line_entry *) curr->data;
+ gsize written;
+
+ if (!g_output_stream_write_all (G_OUTPUT_STREAM (os), entry->string, strlen (entry->string), &written, NULL, error)) {
+ g_prefix_error (error, "Unable to save '%s': ", parser->filename);
+ goto out;
+ }
+ if (!g_output_stream_write_all (G_OUTPUT_STREAM (os), "\n", 1, &written, NULL, error)) {
+ g_prefix_error (error, "Unable to save '%s': ", parser->filename);
+ goto out;
+ }
+ }
+
+ if (!g_output_stream_close (G_OUTPUT_STREAM (os), NULL, error)) {
+ g_prefix_error (error, "Unable to save '%s': ", parser->filename);
+ g_output_stream_close (G_OUTPUT_STREAM (os), NULL, NULL);
+ goto out;
+ }
+ ret = TRUE;
+
+ out:
+ if (os)
+ g_object_unref (os);
+ return ret;
+}
+
+/* End of trivial /etc/X11/xorg.conf.d/30-keyboard.conf parser */
+
static gboolean
on_handle_set_locale (OpenrcSettingsdLocaledLocale1 *locale1,
GDBusMethodInvocation *invocation,
@@ -163,11 +611,16 @@ localed_init (gboolean _read_only)
{
GError *err = NULL;
gchar **locale_values = NULL;
+ struct xorg_confd_parser *x11_parser = NULL;
read_only = _read_only;
locale_file = g_file_new_for_path (SYSCONFDIR "/env.d/02locale");
keymaps_file = g_file_new_for_path (SYSCONFDIR "/conf.d/keymaps");
+ /* See http://www.gentoo.org/doc/en/xorg-config.xml */
+ x11_gentoo_file = g_file_new_for_path (SYSCONFDIR "/X11/xorg.conf.d/30-keyboard.conf");
+ x11_systemd_file = g_file_new_for_path (SYSCONFDIR "/X11/xorg.conf.d/00-keyboard.conf");
+
locale = g_new0 (gchar *, g_strv_length (locale_variables) + 1);
locale_values = shell_utils_trivial_source_var_list (locale_file, (const gchar * const *)locale_variables, &err);
if (locale_values != NULL) {
@@ -198,6 +651,21 @@ localed_init (gboolean _read_only)
/* We don't have a good equivalent for this in openrc at the moment */
vconsole_keymap_toggle = g_strdup ("");
+ xorg_confd_regex_init ();
+
+ if (!g_file_query_exists (x11_gentoo_file, NULL) && g_file_query_exists (x11_systemd_file, NULL))
+ x11_parser = xorg_confd_parser_new (x11_systemd_file, &err);
+ else
+ x11_parser = xorg_confd_parser_new (x11_gentoo_file, &err);
+
+ if (x11_parser != NULL) {
+ xorg_confd_parser_get_xkb (x11_parser, &x11_layout, &x11_model, &x11_variant, &x11_options);
+ xorg_confd_parser_free (x11_parser);
+ } else {
+ g_debug ("%s", err->message);
+ g_clear_error (&err);
+ }
+
bus_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
"org.freedesktop.locale1",
G_BUS_NAME_OWNER_FLAGS_NONE,
@@ -215,6 +683,7 @@ localed_destroy (void)
bus_id = 0;
read_only = FALSE;
g_strfreev (locale);
+ xorg_confd_regex_destroy ();
g_free (vconsole_keymap);
g_free (vconsole_keymap_toggle);
g_free (x11_layout);
@@ -224,4 +693,6 @@ localed_destroy (void)
g_object_unref (locale_file);
g_object_unref (keymaps_file);
+ g_object_unref (x11_gentoo_file);
+ g_object_unref (x11_systemd_file);
}
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-03-19 2:05 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-03-19 2:05 UTC (permalink / raw
To: gentoo-commits
commit: 04e58bfae74958fd2f37afc8304ed32668840965
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 19 02:04:41 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Mon Mar 19 02:04:41 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=04e58bfa
Fix xorg.conf.d parsing
---
src/localed.c | 88 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 70 insertions(+), 18 deletions(-)
diff --git a/src/localed.c b/src/localed.c
index 0dc8765..706a8ed 100644
--- a/src/localed.c
+++ b/src/localed.c
@@ -190,6 +190,20 @@ xorg_confd_line_entry_free (struct xorg_confd_line_entry *entry)
g_free (entry);
}
+/* Note that string and value are not duplicated */
+static struct xorg_confd_line_entry *
+xorg_confd_line_entry_new (const gchar *string,
+ const gchar *value,
+ enum XORG_CONFD_LINE_TYPE type)
+{
+ struct xorg_confd_line_entry *entry;
+
+ entry = g_new0 (struct xorg_confd_line_entry, 1);
+ entry->string = g_strdup (string);
+ entry->value = g_strdup (value);
+ entry->type = type;
+}
+
static void
xorg_confd_parser_free (struct xorg_confd_parser *parser)
{
@@ -239,9 +253,7 @@ xorg_confd_parser_new (GFile *xorg_confd_file,
GMatchInfo *match_info = NULL;
gboolean matched = FALSE;
- entry = g_new0 (struct xorg_confd_line_entry, 1);
- entry->string = *linebuf;
- entry->type = XORG_CONFD_LINE_TYPE_UNKNOWN;
+ entry = xorg_confd_line_entry_new (*linebuf, NULL, XORG_CONFD_LINE_TYPE_UNKNOWN);
if (g_regex_match (xorg_confd_line_comment_re, *linebuf, 0, &match_info)) {
g_debug ("Parsed line '%s' as comment", *linebuf);
@@ -330,6 +342,7 @@ xorg_confd_parser_new (GFile *xorg_confd_file,
out:
g_free (filebuf);
+ g_strfreev (lines);
return parser;
parse_fail:
@@ -414,7 +427,7 @@ xorg_confd_parser_set_xkb (struct xorg_confd_parser *parser,
const gchar *variant,
const gchar *options)
{
- GList *curr = NULL;
+ GList *curr = NULL, *end = NULL;
gboolean layout_found = FALSE, model_found = FALSE, variant_found = FALSE, options_found = FALSE;
if (parser == NULL)
@@ -424,19 +437,16 @@ xorg_confd_parser_set_xkb (struct xorg_confd_parser *parser,
struct xorg_confd_line_entry *entry = NULL;
GList *section = NULL;
- entry = g_new0 (struct xorg_confd_line_entry, 1);
- entry->string = g_strdup("Section \"InputClass\"\n");
- entry->type = XORG_CONFD_LINE_TYPE_SECTION_INPUT_CLASS;
+ entry = xorg_confd_line_entry_new ("Section \"InputClass\"\n", NULL, XORG_CONFD_LINE_TYPE_SECTION_INPUT_CLASS);
+ section = g_list_prepend (section, entry);
+
+ entry = xorg_confd_line_entry_new (" Identifier \"keyboard-all\"\n", NULL, XORG_CONFD_LINE_TYPE_UNKNOWN);
section = g_list_prepend (section, entry);
- entry = g_new0 (struct xorg_confd_line_entry, 1);
- entry->string = g_strdup("MatchIsKeyboard \"on\"\n");
- entry->type = XORG_CONFD_LINE_TYPE_MATCH_IS_KEYBOARD;
+ entry = entry = xorg_confd_line_entry_new (" MatchIsKeyboard \"on\"\n", NULL, XORG_CONFD_LINE_TYPE_MATCH_IS_KEYBOARD);
section = g_list_prepend (section, entry);
- entry = g_new0 (struct xorg_confd_line_entry, 1);
- entry->string = g_strdup("EndSection\n");
- entry->type = XORG_CONFD_LINE_TYPE_END_SECTION;
+ entry = entry = xorg_confd_line_entry_new ("EndSection\n", NULL, XORG_CONFD_LINE_TYPE_END_SECTION);
section = g_list_prepend (section, entry);
section = g_list_reverse (section);
@@ -447,16 +457,58 @@ xorg_confd_parser_set_xkb (struct xorg_confd_parser *parser,
for (curr = parser->section; curr != NULL; curr = curr->next) {
struct xorg_confd_line_entry *entry = (struct xorg_confd_line_entry *) curr->data;
- if (entry->type == XORG_CONFD_LINE_TYPE_END_SECTION)
+ if (entry->type == XORG_CONFD_LINE_TYPE_END_SECTION) {
+ end = curr;
break;
- else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_LAYOUT)
+ } else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_LAYOUT) {
+ layout_found = TRUE;
curr = xorg_confd_parser_line_set_or_delete (curr, layout, xorg_confd_line_xkb_layout_re);
- else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_MODEL)
+ } else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_MODEL) {
+ model_found = TRUE;
curr = xorg_confd_parser_line_set_or_delete (curr, model, xorg_confd_line_xkb_model_re);
- else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_VARIANT)
+ } else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_VARIANT) {
+ variant_found = TRUE;
curr = xorg_confd_parser_line_set_or_delete (curr, variant, xorg_confd_line_xkb_variant_re);
- else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_OPTIONS)
+ } else if (entry->type == XORG_CONFD_LINE_TYPE_XKB_OPTIONS) {
+ options_found = TRUE;
curr = xorg_confd_parser_line_set_or_delete (curr, options, xorg_confd_line_xkb_options_re);
+ }
+ }
+ if (!layout_found && layout != NULL && g_strcmp0 (layout, "")) {
+ struct xorg_confd_line_entry *entry;
+ gchar *string;
+
+ string = g_strdup_printf (" Option \"XkbLayout\" \"%s\"", layout);
+ entry = xorg_confd_line_entry_new (string, layout, XORG_CONFD_LINE_TYPE_XKB_LAYOUT);
+ parser->line_list = g_list_insert_before (parser->line_list, end, entry);
+ g_free (string);
+ }
+ if (!model_found && model != NULL && g_strcmp0 (model, "")) {
+ struct xorg_confd_line_entry *entry;
+ gchar *string;
+
+ string = g_strdup_printf (" Option \"XkbModel\" \"%s\"", model);
+ entry = xorg_confd_line_entry_new (string, model, XORG_CONFD_LINE_TYPE_XKB_MODEL);
+ parser->line_list = g_list_insert_before (parser->line_list, end, entry);
+ g_free (string);
+ }
+ if (!variant_found && variant != NULL && g_strcmp0 (variant, "")) {
+ struct xorg_confd_line_entry *entry;
+ gchar *string;
+
+ string = g_strdup_printf (" Option \"XkbVariant\" \"%s\"", variant);
+ entry = xorg_confd_line_entry_new (string, variant, XORG_CONFD_LINE_TYPE_XKB_VARIANT);
+ parser->line_list = g_list_insert_before (parser->line_list, end, entry);
+ g_free (string);
+ }
+ if (!options_found && options != NULL && g_strcmp0 (options, "")) {
+ struct xorg_confd_line_entry *entry;
+ gchar *string;
+
+ string = g_strdup_printf (" Option \"XkbOptions\" \"%s\"", options);
+ entry = xorg_confd_line_entry_new (string, options, XORG_CONFD_LINE_TYPE_XKB_OPTIONS);
+ parser->line_list = g_list_insert_before (parser->line_list, end, entry);
+ g_free (string);
}
}
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-03-19 3:03 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-03-19 3:03 UTC (permalink / raw
To: gentoo-commits
commit: 0d5b2a081c7d48464d059494ed889e52c0d185d9
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 19 03:01:51 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Mon Mar 19 03:01:51 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=0d5b2a08
Respect --debug switch when using >=glib-2.31.2
---
src/main.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/src/main.c b/src/main.c
index fabb96c..887cccd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,6 +40,7 @@ static GOptionEntry option_entries[] =
{ NULL }
};
+/* Emulates the new behavior of g_log_default_handler introduced in glib-2.31.2 */
static void
log_handler (const gchar *log_domain,
GLogLevelFlags log_level,
@@ -58,7 +59,6 @@ main (gint argc, gchar *argv[])
GMainLoop *loop = NULL;
g_type_init ();
- g_log_set_default_handler (log_handler, NULL);
option_context = g_option_context_new ("- system settings D-Bus service for OpenRC");
g_option_context_add_main_entries (option_context, option_entries, NULL);
@@ -67,6 +67,12 @@ main (gint argc, gchar *argv[])
exit (1);
}
+ if (glib_check_version (2, 31, 2) == NULL) {
+ if (debug)
+ g_setenv("G_MESSAGES_DEBUG", "all", TRUE);
+ } else
+ g_log_set_default_handler (log_handler, NULL);
+
shell_utils_init ();
hostnamed_init (read_only);
localed_init (read_only);
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-09-05 16:54 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-09-05 16:54 UTC (permalink / raw
To: gentoo-commits
commit: 85d40b110c5ae791d1d0c7546adf632bcae032b4
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Wed Sep 5 16:12:37 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Wed Sep 5 16:12:37 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=85d40b11
Cleanup to make valgrind happy
---
src/shell-utils.c | 8 +++-----
1 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/shell-utils.c b/src/shell-utils.c
index 545c5dd..f5c9b20 100644
--- a/src/shell-utils.c
+++ b/src/shell-utils.c
@@ -54,7 +54,7 @@ shell_utils_source_var (GFile *file,
GError **error)
{
gchar *argv[4] = { "sh", "-c", NULL, NULL };
- gchar *filename, *quoted_filename;
+ gchar *filename = NULL, *quoted_filename = NULL;
gchar *output = NULL;
GFileInfo *info;
const GFileAttributeInfo *attribute_info;
@@ -88,10 +88,8 @@ shell_utils_source_var (GFile *file,
}
out:
- if (filename != NULL)
- g_free (filename);
- if (quoted_filename != NULL)
- g_free (quoted_filename);
+ g_free (filename);
+ g_free (quoted_filename);
if (info != NULL)
g_object_unref (info);
if (argv[2] != NULL)
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-09-05 21:19 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-09-05 21:19 UTC (permalink / raw
To: gentoo-commits
commit: e9fcecdeba5c70c2035d47ac20c6fb433b2471af
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Wed Sep 5 20:54:36 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Wed Sep 5 20:54:36 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=e9fcecde
Forgot to set data->invocation
---
src/timedated.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/timedated.c b/src/timedated.c
index bb16cf0..6247679 100644
--- a/src/timedated.c
+++ b/src/timedated.c
@@ -555,6 +555,7 @@ on_handle_set_local_rtc (OpenrcSettingsdTimedatedTimedate1 *timedate1,
else {
struct invoked_set_local_rtc *data;
data = g_new0 (struct invoked_set_local_rtc, 1);
+ data->invocation = invocation;
data->local_rtc = _local_rtc;
data->fix_system = fix_system;
check_polkit_async (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.timedate1.set-local-rtc", user_interaction, on_handle_set_local_rtc_authorized_cb, data);
@@ -617,6 +618,7 @@ on_handle_set_ntp (OpenrcSettingsdTimedatedTimedate1 *timedate1,
else {
struct invoked_set_ntp *data;
data = g_new0 (struct invoked_set_ntp, 1);
+ data->invocation = invocation;
data->use_ntp = _use_ntp;
check_polkit_async (g_dbus_method_invocation_get_sender (invocation), "org.freedesktop.timedate1.set-ntp", user_interaction, on_handle_set_ntp_authorized_cb, data);
}
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-09-05 21:19 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-09-05 21:19 UTC (permalink / raw
To: gentoo-commits
commit: 368ae06be039a6b14fed5c3deea960ddabbaf774
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Wed Sep 5 20:59:45 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Wed Sep 5 20:59:45 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=368ae06b
Use full service script path when spawning
---
src/timedated.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/timedated.c b/src/timedated.c
index 6247679..7a66663 100644
--- a/src/timedated.c
+++ b/src/timedated.c
@@ -224,7 +224,7 @@ service_disable (const gchar *service,
}
g_debug ("Stopping %s rc service", service);
- argv[0] = service;
+ argv[0] = service_script;
if (!g_spawn_sync (NULL, (gchar **)argv, NULL, 0, NULL, NULL, NULL, NULL, &exit_status, error)) {
g_prefix_error (error, "Failed to spawn %s rc service:", service);
goto out;
@@ -271,7 +271,7 @@ service_enable (const gchar *service,
}
g_debug ("Starting %s rc service", service);
- argv[0] = service;
+ argv[0] = service_script;
if (!g_spawn_sync (NULL, (gchar **)argv, NULL, 0, NULL, NULL, NULL, NULL, &exit_status, error)) {
g_prefix_error (error, "Failed to spawn %s rc service:", service);
goto out;
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-09-05 21:19 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-09-05 21:19 UTC (permalink / raw
To: gentoo-commits
commit: 015407cd9c0a148e88057ddcb08273f6b2cb3494
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Wed Sep 5 21:10:51 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Wed Sep 5 21:10:51 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=015407cd
Wrong g_free() due to careless copy/paste
---
src/timedated.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/src/timedated.c b/src/timedated.c
index 7a66663..b8a41fc 100644
--- a/src/timedated.c
+++ b/src/timedated.c
@@ -526,7 +526,6 @@ on_handle_set_local_rtc_authorized_cb (GObject *source_object,
}
openrc_settingsd_timedated_timedate1_complete_set_timezone (timedate1, data->invocation);
- g_free (timezone_name);
local_rtc = data->local_rtc;
openrc_settingsd_timedated_timedate1_set_local_rtc (timedate1, local_rtc);
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-09-05 23:46 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-09-05 23:46 UTC (permalink / raw
To: gentoo-commits
commit: 51b24876f8d7af6b4a292bc43266d2012dde3cae
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Wed Sep 5 23:45:42 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Wed Sep 5 23:45:42 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=51b24876
Fix memory leaks
---
src/localed.c | 9 +++++++--
src/timedated.c | 1 +
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/localed.c b/src/localed.c
index 0cb4404..5eb3f65 100644
--- a/src/localed.c
+++ b/src/localed.c
@@ -620,6 +620,7 @@ xorg_confd_parser_line_set_or_delete (GList *line,
next->prev = prev;
return prev;
}
+ g_free (entry->value);
entry->value = g_strdup (value);
replacement = g_strdup_printf ("\\1\"%s\"", value);
replaced = g_regex_replace (re, entry->string, -1, 0, replacement, 0, NULL);
@@ -871,7 +872,10 @@ on_handle_set_locale_authorized_cb (GObject *source_object,
out:
shell_parser_free (locale_file_parsed);
- g_strfreev (locale_values);
+ /* g_strfreev (locale_values) will leak, since it stops at first NULL value */
+ for (val = locale_values, var = locale_variables; *var != NULL; val++, var++)
+ g_free (*val);
+ g_free (locale_values);
invoked_locale_free (data);
if (err != NULL)
g_error_free (err);
@@ -1281,11 +1285,12 @@ localed_init (gboolean _read_only)
for (variable = locale_variables, value = locale_values; *variable != NULL; variable++, value++) {
if (*value != NULL) {
*loc = g_strdup_printf ("%s=%s", *variable, *value);
+ g_free (*value);
loc++;
}
}
- g_strfreev (locale_values);
+ g_free (locale_values);
}
if (err != NULL) {
g_debug ("%s", err->message);
diff --git a/src/timedated.c b/src/timedated.c
index d6588f4..32e9171 100644
--- a/src/timedated.c
+++ b/src/timedated.c
@@ -63,6 +63,7 @@ get_local_rtc (GError **error)
clock = shell_source_var (hwclock_file, "${clock}", error);
if (!g_strcmp0 (clock, "local"))
ret = TRUE;
+ g_free (clock);
return ret;
}
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-09-08 0:20 Alexandre Restovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Restovtsev @ 2012-09-08 0:20 UTC (permalink / raw
To: gentoo-commits
commit: bf6d6faacbb2f74a9f05a949bd27696b84076dd0
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Fri Sep 7 23:41:41 2012 +0000
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com>
CommitDate: Sat Sep 8 00:03:04 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=bf6d6faa
Better diagnostics for missing ntp implementation
---
src/timedated.c | 34 +++++++++++++++++++++++++---------
1 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/src/timedated.c b/src/timedated.c
index 4e5939e..70c41b4 100644
--- a/src/timedated.c
+++ b/src/timedated.c
@@ -52,7 +52,8 @@ G_LOCK_DEFINE_STATIC (clock);
gboolean use_ntp = FALSE;
static const gchar *ntp_preferred_service = NULL;
-static const gchar *ntp_default_services[4] = { "ntpd", "chronyd", "busybox-ntpd", NULL };
+static const gchar *ntp_default_services[] = { "ntpd", "chronyd", "busybox-ntpd", NULL };
+#define NTP_DEFAULT_SERVICES_PACKAGES "ntp, openntpd, chrony, busybox-ntpd"
G_LOCK_DEFINE_STATIC (ntp);
static gboolean
@@ -177,8 +178,6 @@ ntp_service ()
}
free (runlevel);
- if (service == NULL)
- service = ntp_default_services[0];
return service;
}
@@ -188,6 +187,8 @@ service_started (const gchar *service,
{
RC_SERVICE state;
+ g_assert (service != NULL);
+
if (!rc_service_exists (service)) {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "%s rc service not found", service);
return FALSE;
@@ -207,6 +208,8 @@ service_disable (const gchar *service,
gboolean ret = FALSE;
gint exit_status = 0;
+ g_assert (service != NULL);
+
if (!rc_service_exists (service)) {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "%s rc service not found", service);
goto out;
@@ -254,6 +257,8 @@ service_enable (const gchar *service,
gboolean ret = FALSE;
gint exit_status = 0;
+ g_assert (service != NULL);
+
if (!rc_service_exists (service)) {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "%s rc service not found", service);
goto out;
@@ -584,8 +589,14 @@ on_handle_set_ntp_authorized_cb (GObject *source_object,
}
G_LOCK (ntp);
- if ((data->use_ntp && !service_enable (ntp_service(), &err)) ||
- (!data->use_ntp && !service_disable (ntp_service(), &err)))
+ if (ntp_service () == NULL) {
+ g_dbus_method_invocation_return_dbus_error (data->invocation, DBUS_ERROR_FAILED,
+ "No ntp implementation found. Please install one of the following packages: "
+ NTP_DEFAULT_SERVICES_PACKAGES);
+ goto unlock;
+ }
+ if ((data->use_ntp && !service_enable (ntp_service (), &err)) ||
+ (!data->use_ntp && !service_disable (ntp_service (), &err)))
{
g_dbus_method_invocation_return_gerror (data->invocation, err);
goto unlock;
@@ -702,10 +713,15 @@ timedated_init (gboolean _read_only,
g_warning ("%s", err->message);
g_clear_error (&err);
}
- use_ntp = service_started (ntp_service (), &err);
- if (err != NULL) {
- g_warning ("%s", err->message);
- g_clear_error (&err);
+ if (ntp_service () == NULL) {
+ g_warning ("No ntp implementation found. Please install one of the following packages: " NTP_DEFAULT_SERVICES_PACKAGES);
+ use_ntp = FALSE;
+ } else {
+ use_ntp = service_started (ntp_service (), &err);
+ if (err != NULL) {
+ g_warning ("%s", err->message);
+ g_clear_error (&err);
+ }
}
bus_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/openrc-settingsd:master commit in: src/
@ 2012-09-09 3:47 Alexandre Rostovtsev
0 siblings, 0 replies; 17+ messages in thread
From: Alexandre Rostovtsev @ 2012-09-09 3:47 UTC (permalink / raw
To: gentoo-commits
commit: 7830416baf2f95d57a54434f2bd57e04da580ce3
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
AuthorDate: Sun Sep 9 03:38:41 2012 +0000
Commit: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org>
CommitDate: Sun Sep 9 03:46:56 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=7830416b
Lennart Poettering requested attribution in file headers
---
src/hostnamed.c | 6 +++++-
src/timedated.c | 3 +++
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/src/hostnamed.c b/src/hostnamed.c
index dce16cd..cc49569 100644
--- a/src/hostnamed.c
+++ b/src/hostnamed.c
@@ -1,6 +1,9 @@
/*
Copyright 2012 Alexandre Rostovtsev
+ Some parts are based on the code from the systemd project; these are
+ copyright 2011 Lennart Poettering and others.
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
@@ -82,7 +85,8 @@ guess_icon_name ()
#if defined(__i386__) || defined(__x86_64__)
/*
- Taken with a few minor changes from systemd's hostnamed
+ Taken with a few minor changes from systemd's hostnamed.c,
+ copyright 2011 Lennart Poettering.
See the SMBIOS Specification 2.7.1 section 7.4.1 for
details about the values listed here:
diff --git a/src/timedated.c b/src/timedated.c
index 70c41b4..93429b8 100644
--- a/src/timedated.c
+++ b/src/timedated.c
@@ -1,6 +1,9 @@
/*
Copyright 2012 Alexandre Rostovtsev
+ Some parts are based on the code from the systemd project; these are
+ copyright 2011 Lennart Poettering and others.
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
^ permalink raw reply related [flat|nested] 17+ messages in thread
end of thread, other threads:[~2012-09-09 3:48 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-08 6:53 [gentoo-commits] proj/openrc-settingsd:master commit in: src/ Alexandre Restovtsev
-- strict thread matches above, loose matches on Subject: below --
2012-09-09 3:47 Alexandre Rostovtsev
2012-09-08 0:20 Alexandre Restovtsev
2012-09-05 23:46 Alexandre Restovtsev
2012-09-05 21:19 Alexandre Restovtsev
2012-09-05 21:19 Alexandre Restovtsev
2012-09-05 21:19 Alexandre Restovtsev
2012-09-05 16:54 Alexandre Restovtsev
2012-03-19 3:03 Alexandre Restovtsev
2012-03-19 2:05 Alexandre Restovtsev
2012-03-18 11:02 Alexandre Restovtsev
2012-02-08 5:57 Alexandre Restovtsev
2012-02-08 5:01 Alexandre Restovtsev
2012-02-06 10:24 Alexandre Restovtsev
2012-02-05 7:52 Alexandre Restovtsev
2012-02-05 0:20 Alexandre Restovtsev
2012-01-29 23:22 Alexandre Restovtsev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox