diff options
author | 2012-01-29 18:22:17 -0500 | |
---|---|---|
committer | 2012-01-29 18:22:17 -0500 | |
commit | c634bc83ca40dcf3e0079905d77089d7e5090421 (patch) | |
tree | 0bbfd82bb50cdfbb6827b724913779c53f75e263 | |
parent | Added TODO (diff) | |
download | openrc-settingsd-c634bc83ca40dcf3e0079905d77089d7e5090421.tar.gz openrc-settingsd-c634bc83ca40dcf3e0079905d77089d7e5090421.tar.bz2 openrc-settingsd-c634bc83ca40dcf3e0079905d77089d7e5090421.zip |
Thread safety
-rw-r--r-- | 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); |