Commit 5bfb7c3c authored by Thomas Haller's avatar Thomas Haller

hostname: split out hostname management from NMSettings

Hostname management is complicated. At least, how it is implemented currently.
For example, NMPolicy also sets the hostname (NMPolicy calls
nm_settings_set_transient_hostname() to have hostnamed set the hostname,
but then falls back to sethostname() in settings_set_hostname_cb()).
Also, NMManager tracks the hostname in NM_MANAGER_HOSTNAME too, and
NMPolicy listens to changes from there -- instead of changes from
NMSettings.

Eventually, NMHostnameManager should contain the hostname parts from NMSettings
and NMPolicy.
parent f3dfe0f7
......@@ -1391,6 +1391,9 @@ src_libNetworkManager_la_SOURCES = \
src/ppp/nm-ppp-manager.h \
src/ppp/nm-ppp-status.h \
\
src/nm-hostname-manager.c \
src/nm-hostname-manager.h \
\
src/settings/nm-agent-manager.c \
src/settings/nm-agent-manager.h \
src/settings/nm-inotify-helper.c \
......
This diff is collapsed.
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager
*
* Søren Sandmann <sandmann@daimi.au.dk>
* Dan Williams <dcbw@redhat.com>
* Tambet Ingo <tambet@gmail.com>
*
* 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2007 - 2011, 2017 Red Hat, Inc.
* (C) Copyright 2008 Novell, Inc.
*/
#ifndef __NM_HOSTNAME_MANAGER_H__
#define __NM_HOSTNAME_MANAGER_H__
#define NM_TYPE_HOSTNAME_MANAGER (nm_hostname_manager_get_type ())
#define NM_HOSTNAME_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_HOSTNAME_MANAGER, NMHostnameManager))
#define NM_HOSTNAME_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_HOSTNAME_MANAGER, NMHostnameManagerClass))
#define NM_IS_HOSTNAME_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_HOSTNAME_MANAGER))
#define NM_IS_HOSTNAME_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_HOSTNAME_MANAGER))
#define NM_HOSTNAME_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_HOSTNAME_MANAGER, NMHostnameManagerClass))
#define NM_HOSTNAME_MANAGER_HOSTNAME "hostname"
typedef struct _NMHostnameManager NMHostnameManager;
typedef struct _NMHostnameManagerClass NMHostnameManagerClass;
typedef void (*NMHostnameManagerSetHostnameCb) (const char *name, gboolean result, gpointer user_data);
GType nm_hostname_manager_get_type (void);
NMHostnameManager *nm_hostname_manager_get (void);
char *nm_hostname_manager_get_hostname (NMHostnameManager *self);
gboolean nm_hostname_manager_write_hostname (NMHostnameManager *self, const char *hostname);
void nm_hostname_manager_set_transient_hostname (NMHostnameManager *self,
const char *hostname,
NMHostnameManagerSetHostnameCb cb,
gpointer user_data);
gboolean nm_hostname_manager_get_transient_hostname (NMHostnameManager *self,
char **hostname);
gboolean nm_hostname_manager_validate_hostname (const char *hostname);
#endif /* __NM_HOSTNAME_MANAGER_H__ */
......@@ -1412,7 +1412,10 @@ system_hostname_changed_cb (NMSettings *settings,
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
char *hostname;
hostname = nm_settings_get_hostname (priv->settings);
g_object_get (priv->settings,
NM_SETTINGS_HOSTNAME,
&hostname,
NULL);
/* nm_settings_get_hostname() does not return an empty hostname. */
nm_assert (!hostname || *hostname);
......
......@@ -49,6 +49,7 @@
#include "nm-dhcp6-config.h"
#include "nm-config.h"
#include "nm-netns.h"
#include "nm-hostname-manager.h"
/*****************************************************************************/
......@@ -73,6 +74,8 @@ typedef struct {
NMSettings *settings;
NMHostnameManager *hostname_manager;
NMDevice *default_device4, *activating_device4;
NMDevice *default_device6, *activating_device6;
......@@ -460,7 +463,7 @@ _get_hostname (NMPolicy *self, char **hostname)
}
/* try to get the hostname via dbus... */
if (nm_settings_get_transient_hostname (priv->settings, hostname)) {
if (nm_hostname_manager_get_transient_hostname (priv->hostname_manager, hostname)) {
_LOGT (LOGD_DNS, "get-hostname: \"%s\" (from dbus)", *hostname);
return *hostname;
}
......@@ -549,10 +552,10 @@ _set_hostname (NMPolicy *self,
/* Ask NMSettings to update the transient hostname using its
* systemd-hostnamed proxy */
nm_settings_set_transient_hostname (priv->settings,
name,
settings_set_hostname_cb,
g_object_ref (self));
nm_hostname_manager_set_transient_hostname (priv->hostname_manager,
name,
settings_set_hostname_cb,
g_object_ref (self));
}
static void
......@@ -2300,6 +2303,8 @@ nm_policy_init (NMPolicy *self)
priv->netns = g_object_ref (nm_netns_get ());
priv->hostname_manager = g_object_ref (nm_hostname_manager_get ());
hostname_mode = nm_config_data_get_value (NM_CONFIG_GET_DATA_ORIG,
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE,
......
This diff is collapsed.
......@@ -119,20 +119,10 @@ gboolean nm_settings_has_connection (NMSettings *self, NMSettingsConnection *con
const GSList *nm_settings_get_unmanaged_specs (NMSettings *self);
char *nm_settings_get_hostname (NMSettings *self);
void nm_settings_device_added (NMSettings *self, NMDevice *device);
void nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean quitting);
gboolean nm_settings_get_startup_complete (NMSettings *self);
void nm_settings_set_transient_hostname (NMSettings *self,
const char *hostname,
NMSettingsSetHostnameCb cb,
gpointer user_data);
gboolean nm_settings_get_transient_hostname (NMSettings *self,
char **hostname);
#endif /* __NM_SETTINGS_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment