aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Rostovtsev <tetromino@gentoo.org>2012-02-07 23:01:45 -0500
committerAlexandre Rostovtsev <tetromino@gentoo.org>2012-02-07 23:01:45 -0500
commitfb55754fc1b2ad11dc51ed96126fc0cfacab569b (patch)
treed92193e2eff140666530af86fb571fff81744be3
parentnewline at end of file (diff)
downloadopenrc-settingsd-fb55754fc1b2ad11dc51ed96126fc0cfacab569b.tar.gz
openrc-settingsd-fb55754fc1b2ad11dc51ed96126fc0cfacab569b.tar.bz2
openrc-settingsd-fb55754fc1b2ad11dc51ed96126fc0cfacab569b.zip
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
-rw-r--r--src/hostnamed.c15
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);