1 |
commit: fb55754fc1b2ad11dc51ed96126fc0cfacab569b |
2 |
Author: Alexandre Rostovtsev <tetromino <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Feb 8 04:01:45 2012 +0000 |
4 |
Commit: Alexandre Restovtsev <tetromino <AT> gmail <DOT> com> |
5 |
CommitDate: Wed Feb 8 04:01:45 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=fb55754f |
7 |
|
8 |
Fix transient hostname error handling, and dynamically allocate it |
9 |
|
10 |
Ensure that setting the transient hostname behaves as described in |
11 |
http://www.freedesktop.org/wiki/Software/systemd/hostnamed |
12 |
|
13 |
--- |
14 |
src/hostnamed.c | 15 ++++++++------- |
15 |
1 files changed, 8 insertions(+), 7 deletions(-) |
16 |
|
17 |
diff --git a/src/hostnamed.c b/src/hostnamed.c |
18 |
index c5f6f9c..88c166e 100644 |
19 |
--- a/src/hostnamed.c |
20 |
+++ b/src/hostnamed.c |
21 |
@@ -46,7 +46,7 @@ gboolean read_only = FALSE; |
22 |
|
23 |
static OpenrcSettingsdHostnamedHostname1 *hostname1 = NULL; |
24 |
|
25 |
-static gchar hostname[HOST_NAME_MAX + 1]; |
26 |
+static gchar *hostname = NULL; |
27 |
G_LOCK_DEFINE_STATIC (hostname); |
28 |
static gchar *static_hostname = NULL; |
29 |
static GFile *static_hostname_file = NULL; |
30 |
@@ -128,8 +128,8 @@ on_handle_set_hostname_authorized_cb (GObject *source_object, |
31 |
if (data->name != NULL) |
32 |
g_free (data->name); |
33 |
|
34 |
- if (hostname_is_valid (hostname)) |
35 |
- data->name = g_strdup (hostname); |
36 |
+ if (hostname_is_valid (static_hostname)) |
37 |
+ data->name = g_strdup (static_hostname); |
38 |
else |
39 |
data->name = g_strdup ("localhost"); |
40 |
} |
41 |
@@ -141,13 +141,13 @@ on_handle_set_hostname_authorized_cb (GObject *source_object, |
42 |
G_UNLOCK (hostname); |
43 |
goto out; |
44 |
} |
45 |
- g_strlcpy (hostname, data->name, HOST_NAME_MAX + 1); |
46 |
+ g_free (hostname); |
47 |
+ hostname = data->name; /* data->name is g_strdup-ed already */; |
48 |
openrc_settingsd_hostnamed_hostname1_complete_set_hostname (hostname1, data->invocation); |
49 |
openrc_settingsd_hostnamed_hostname1_set_hostname (hostname1, hostname); |
50 |
G_UNLOCK (hostname); |
51 |
|
52 |
out: |
53 |
- g_free (data->name); |
54 |
g_free (data); |
55 |
if (err != NULL) |
56 |
g_error_free (err); |
57 |
@@ -416,10 +416,10 @@ hostnamed_init (gboolean _read_only) |
58 |
{ |
59 |
GError *err = NULL; |
60 |
|
61 |
- memset (hostname, 0, HOST_NAME_MAX + 1); |
62 |
+ hostname = g_malloc0 (HOST_NAME_MAX + 1); |
63 |
if (gethostname (hostname, HOST_NAME_MAX)) { |
64 |
perror (NULL); |
65 |
- hostname[0] = 0; |
66 |
+ g_strlcpy (hostname, "localhost", HOST_NAME_MAX + 1); |
67 |
} |
68 |
|
69 |
static_hostname_file = g_file_new_for_path (SYSCONFDIR "/conf.d/hostname"); |
70 |
@@ -470,6 +470,7 @@ hostnamed_destroy (void) |
71 |
bus_id = 0; |
72 |
read_only = FALSE; |
73 |
memset (hostname, 0, HOST_NAME_MAX + 1); |
74 |
+ g_free (hostname); |
75 |
g_free (static_hostname); |
76 |
g_free (pretty_hostname); |
77 |
g_free (icon_name); |