1 |
commit: c634bc83ca40dcf3e0079905d77089d7e5090421 |
2 |
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Jan 29 23:22:17 2012 +0000 |
4 |
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com> |
5 |
CommitDate: Sun Jan 29 23:22:17 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=c634bc83 |
7 |
|
8 |
Thread safety |
9 |
|
10 |
--- |
11 |
src/hostnamed.c | 17 +++++++++++++++++ |
12 |
1 files changed, 17 insertions(+), 0 deletions(-) |
13 |
|
14 |
diff --git a/src/hostnamed.c b/src/hostnamed.c |
15 |
index f0c2357..b431aac 100644 |
16 |
--- a/src/hostnamed.c |
17 |
+++ b/src/hostnamed.c |
18 |
@@ -43,9 +43,12 @@ gboolean read_only = FALSE; |
19 |
static OpenrcSettingsdHostnamedHostname1 *hostname1 = NULL; |
20 |
|
21 |
static gchar hostname[HOST_NAME_MAX + 1]; |
22 |
+static GStaticMutex hostname_mutex = G_STATIC_MUTEX_INIT; |
23 |
static gchar *static_hostname = NULL; |
24 |
+static GStaticMutex static_hostname_mutex = G_STATIC_MUTEX_INIT; |
25 |
static gchar *pretty_hostname = NULL; |
26 |
static gchar *icon_name = NULL; |
27 |
+static GStaticMutex machine_info_mutex = G_STATIC_MUTEX_INIT; |
28 |
|
29 |
static gboolean |
30 |
hostname_is_valid (const gchar *name) |
31 |
@@ -120,6 +123,7 @@ on_handle_set_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1, |
32 |
goto end; |
33 |
} |
34 |
|
35 |
+ g_static_mutex_lock (&hostname_mutex); |
36 |
/* Don't allow an empty or invalid hostname */ |
37 |
if (!hostname_is_valid (name)) { |
38 |
name = hostname; |
39 |
@@ -131,10 +135,13 @@ on_handle_set_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1, |
40 |
g_dbus_method_invocation_return_dbus_error (invocation, |
41 |
DBUS_ERROR_FAILED, |
42 |
strerror (errsv)); |
43 |
+ g_static_mutex_unlock (&hostname_mutex); |
44 |
+ goto end; |
45 |
} |
46 |
g_strlcpy (hostname, name, HOST_NAME_MAX + 1); |
47 |
openrc_settingsd_hostnamed_hostname1_complete_set_hostname (hostname1, invocation); |
48 |
openrc_settingsd_hostnamed_hostname1_set_hostname (hostname1, hostname); |
49 |
+ g_static_mutex_unlock (&hostname_mutex); |
50 |
|
51 |
end: |
52 |
return TRUE; |
53 |
@@ -162,6 +169,7 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1, |
54 |
goto end; |
55 |
} |
56 |
|
57 |
+ g_static_mutex_lock (&static_hostname_mutex); |
58 |
/* Don't allow an empty or invalid hostname */ |
59 |
if (!hostname_is_valid (name)) |
60 |
name = "localhost"; |
61 |
@@ -169,6 +177,7 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1, |
62 |
confd_file = shell_utils_trivial_new (SYSCONFDIR "/conf.d/hostname", &err); |
63 |
if (confd_file == NULL) { |
64 |
g_dbus_method_invocation_return_gerror (invocation, err); |
65 |
+ g_static_mutex_unlock (&static_hostname_mutex); |
66 |
goto end; |
67 |
} |
68 |
|
69 |
@@ -179,11 +188,13 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1, |
70 |
g_dbus_method_invocation_return_dbus_error (invocation, |
71 |
DBUS_ERROR_FAILED, |
72 |
"Failed to set static hostname in " SYSCONFDIR "/conf.d/hostname"); |
73 |
+ g_static_mutex_unlock (&static_hostname_mutex); |
74 |
goto end; |
75 |
} |
76 |
|
77 |
if (!shell_utils_trivial_save (confd_file, &err)) { |
78 |
g_dbus_method_invocation_return_gerror (invocation, err); |
79 |
+ g_static_mutex_unlock (&static_hostname_mutex); |
80 |
goto end; |
81 |
} |
82 |
|
83 |
@@ -191,6 +202,7 @@ on_handle_set_static_hostname (OpenrcSettingsdHostnamedHostname1 *hostname1, |
84 |
static_hostname = g_strdup (name); |
85 |
openrc_settingsd_hostnamed_hostname1_complete_set_static_hostname (hostname1, invocation); |
86 |
openrc_settingsd_hostnamed_hostname1_set_static_hostname (hostname1, static_hostname); |
87 |
+ g_static_mutex_unlock (&static_hostname_mutex); |
88 |
|
89 |
end: |
90 |
shell_utils_trivial_free (confd_file); |
91 |
@@ -223,6 +235,7 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1, |
92 |
goto end; |
93 |
} |
94 |
|
95 |
+ g_static_mutex_lock (&machine_info_mutex); |
96 |
/* Don't allow a null pretty hostname */ |
97 |
if (name == NULL) |
98 |
name = ""; |
99 |
@@ -230,6 +243,7 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1, |
100 |
confd_file = shell_utils_trivial_new (SYSCONFDIR "/machine-info", &err); |
101 |
if (confd_file == NULL) { |
102 |
g_dbus_method_invocation_return_gerror (invocation, err); |
103 |
+ g_static_mutex_unlock (&machine_info_mutex); |
104 |
goto end; |
105 |
} |
106 |
|
107 |
@@ -239,11 +253,13 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1, |
108 |
g_dbus_method_invocation_return_dbus_error (invocation, |
109 |
DBUS_ERROR_FAILED, |
110 |
"Failed to value in " SYSCONFDIR "/machine-info"); |
111 |
+ g_static_mutex_unlock (&machine_info_mutex); |
112 |
goto end; |
113 |
} |
114 |
|
115 |
if (!shell_utils_trivial_save (confd_file, &err)) { |
116 |
g_dbus_method_invocation_return_gerror (invocation, err); |
117 |
+ g_static_mutex_unlock (&machine_info_mutex); |
118 |
goto end; |
119 |
} |
120 |
|
121 |
@@ -258,6 +274,7 @@ on_handle_set_machine_info (OpenrcSettingsdHostnamedHostname1 *hostname1, |
122 |
openrc_settingsd_hostnamed_hostname1_complete_set_icon_name (hostname1, invocation); |
123 |
openrc_settingsd_hostnamed_hostname1_set_icon_name (hostname1, icon_name); |
124 |
} |
125 |
+ g_static_mutex_unlock (&machine_info_mutex); |
126 |
|
127 |
end: |
128 |
shell_utils_trivial_free (confd_file); |