Commit b3e8361f authored by Dan Winship's avatar Dan Winship

settings: don't pass config_path to NMSettings and settings plugins

They can just call nm_config_get() now to get the config, and
nm_config_get_path() to get its path.
parent 26de9db1
......@@ -494,9 +494,7 @@ main (int argc, char *argv[])
dns_mgr = nm_dns_manager_get ();
g_assert (dns_mgr != NULL);
settings = nm_settings_new (nm_config_get_path (config),
nm_config_get_plugins (config),
&error);
settings = nm_settings_new (&error);
if (!settings) {
nm_log_err (LOGD_CORE, "failed to initialize settings storage: %s",
error && error->message ? error->message : "(unknown)");
......
......@@ -10,6 +10,7 @@ INCLUDES = -I${top_srcdir} \
-I${top_builddir}/src/generated \
-I${top_srcdir}/src/generated \
-I${top_srcdir}/src/logging \
-I${top_srcdir}/src/config \
-I${top_srcdir}/src
noinst_LTLIBRARIES = libsettings.la libtest-settings-utils.la
......
......@@ -69,6 +69,7 @@
#include "nm-agent-manager.h"
#include "nm-settings-utils.h"
#include "nm-connection-provider.h"
#include "nm-config.h"
#define CONFIG_KEY_NO_AUTO_DEFAULT "no-auto-default"
......@@ -123,7 +124,7 @@ typedef struct {
NMAgentManager *agent_mgr;
char *config_file;
NMConfig *config;
NMSessionMonitor *session_monitor;
GSList *auths;
......@@ -567,10 +568,9 @@ find_plugin (GSList *list, const char *pname)
static void
add_keyfile_plugin (NMSettings *self)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
GObject *keyfile_plugin;
keyfile_plugin = nm_settings_keyfile_plugin_new (priv->config_file);
keyfile_plugin = nm_settings_keyfile_plugin_new ();
g_assert (keyfile_plugin);
add_plugin (self, NM_SYSTEM_CONFIG_INTERFACE (keyfile_plugin));
}
......@@ -578,7 +578,6 @@ add_keyfile_plugin (NMSettings *self)
static gboolean
load_plugins (NMSettings *self, const char **plugins, GError **error)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
GSList *list = NULL;
const char **iter;
gboolean keyfile_added = FALSE;
......@@ -589,7 +588,7 @@ load_plugins (NMSettings *self, const char **plugins, GError **error)
char *full_name, *path;
const char *pname = *iter;
GObject *obj;
GObject * (*factory_func) (const char *);
GObject * (*factory_func) (void);
/* strip leading spaces */
while (g_ascii_isspace (*pname))
......@@ -637,7 +636,7 @@ load_plugins (NMSettings *self, const char **plugins, GError **error)
break;
}
obj = (*factory_func) (priv->config_file);
obj = (*factory_func) ();
if (!obj || !NM_IS_SYSTEM_CONFIG_INTERFACE (obj)) {
g_set_error (error, 0, 0,
"Plugin '%s' returned invalid system config object.",
......@@ -1379,6 +1378,7 @@ static gboolean
is_mac_auto_wired_blacklisted (NMSettings *self, const GByteArray *mac)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
const char *config_file;
GKeyFile *config;
char **list, **iter;
gboolean found = FALSE;
......@@ -1386,12 +1386,13 @@ is_mac_auto_wired_blacklisted (NMSettings *self, const GByteArray *mac)
g_return_val_if_fail (mac != NULL, FALSE);
if (!priv->config_file)
config_file = nm_config_get_path (priv->config);
if (!config_file)
return FALSE;
config = g_key_file_new ();
g_key_file_set_list_separator (config, ',');
if (!g_key_file_load_from_file (config, priv->config_file, G_KEY_FILE_NONE, NULL))
if (!g_key_file_load_from_file (config, config_file, G_KEY_FILE_NONE, NULL))
goto out;
hwaddr_type = nm_utils_hwaddr_type (mac->len);
......@@ -1431,6 +1432,7 @@ default_wired_deleted (NMDefaultWiredConnection *wired,
NMSettingConnection *s_con;
int hwaddr_type;
char *tmp;
const char *config_file;
GKeyFile *config;
char **list, **iter, **updated;
gboolean found = FALSE;
......@@ -1438,7 +1440,8 @@ default_wired_deleted (NMDefaultWiredConnection *wired,
char *data;
/* If there was no config file specified, there's nothing to do */
if (!priv->config_file)
config_file = nm_config_get_path (priv->config);
if (!config_file)
goto cleanup;
/* When the default wired connection is removed (either deleted or saved
......@@ -1466,7 +1469,7 @@ default_wired_deleted (NMDefaultWiredConnection *wired,
goto cleanup;
g_key_file_set_list_separator (config, ',');
g_key_file_load_from_file (config, priv->config_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
g_key_file_load_from_file (config, config_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
list = g_key_file_get_string_list (config, "main", CONFIG_KEY_NO_AUTO_DEFAULT, &len, NULL);
for (iter = list; iter && *iter; iter++) {
......@@ -1507,7 +1510,7 @@ default_wired_deleted (NMDefaultWiredConnection *wired,
data = g_key_file_to_data (config, &len, NULL);
if (data) {
g_file_set_contents (priv->config_file, data, len, NULL);
g_file_set_contents (config_file, data, len, NULL);
g_free (data);
}
}
......@@ -1741,9 +1744,7 @@ get_connections (NMConnectionProvider *provider)
/***************************************************************/
NMSettings *
nm_settings_new (const char *config_file,
const char **plugins,
GError **error)
nm_settings_new (GError **error)
{
NMSettings *self;
NMSettingsPrivate *priv;
......@@ -1752,12 +1753,12 @@ nm_settings_new (const char *config_file,
priv = NM_SETTINGS_GET_PRIVATE (self);
priv->config_file = g_strdup (config_file);
priv->config = nm_config_get ();
priv->dbus_mgr = nm_dbus_manager_get ();
priv->bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
/* Load the plugins; fail if a plugin is not found. */
if (!load_plugins (self, plugins, error)) {
if (!load_plugins (self, nm_config_get_plugins (priv->config), error)) {
g_object_unref (self);
return NULL;
}
......@@ -1826,8 +1827,6 @@ finalize (GObject *object)
g_slist_foreach (priv->plugins, (GFunc) g_object_unref, NULL);
g_slist_free (priv->plugins);
g_free (priv->config_file);
G_OBJECT_CLASS (nm_settings_parent_class)->finalize (object);
}
......
......@@ -76,9 +76,7 @@ typedef struct {
GType nm_settings_get_type (void);
NMSettings *nm_settings_new (const char *config_file,
const char **plugins,
GError **error);
NMSettings *nm_settings_new (GError **error);
typedef void (*NMSettingsForEachFunc) (NMSettings *settings,
NMSettingsConnection *connection,
......
......@@ -39,7 +39,7 @@ G_BEGIN_DECLS
/* Plugin's factory function that returns a GObject that implements
* NMSystemConfigInterface.
*/
GObject * nm_system_config_factory (const char *config_file);
GObject * nm_system_config_factory (void);
#define NM_TYPE_SYSTEM_CONFIG_INTERFACE (nm_system_config_interface_get_type ())
#define NM_SYSTEM_CONFIG_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SYSTEM_CONFIG_INTERFACE, NMSystemConfigInterface))
......
INCLUDES = \
-I$(top_srcdir)/src/config \
-I$(top_srcdir)/src/settings \
-I$(top_srcdir)/include \
-I$(top_builddir)/include \
......
......@@ -34,6 +34,7 @@
#include <nm-setting.h>
#include <nm-setting-connection.h>
#include <nm-utils.h>
#include <nm-config.h>
#include "plugin.h"
#include "nm-system-config-interface.h"
......@@ -99,7 +100,7 @@ typedef struct {
* plugin has some specific options (like unmanaged devices) that
* might be changed at runtime.
*/
char *conf_file;
const char *conf_file;
GFileMonitor *conf_file_monitor;
guint conf_file_monitor_id;
......@@ -775,8 +776,6 @@ dispose (GObject *object)
g_free (priv->hostname);
priv->hostname = NULL;
g_free (priv->conf_file);
priv->conf_file = NULL;
/* Chain up to the superclass */
G_OBJECT_CLASS (sc_plugin_example_parent_class)->dispose (object);
......@@ -848,7 +847,7 @@ system_config_interface_init (NMSystemConfigInterface *sci_intf)
* twice.
*/
G_MODULE_EXPORT GObject *
nm_system_config_factory (const char *config_file)
nm_system_config_factory (void)
{
static SCPluginExample *singleton = NULL;
SCPluginExamplePrivate *priv;
......@@ -859,7 +858,7 @@ nm_system_config_factory (const char *config_file)
priv = SC_PLUGIN_EXAMPLE_GET_PRIVATE (singleton);
/* Cache the config file path */
priv->conf_file = g_strdup (config_file);
priv->conf_file = nm_config_get_path (nm_config_get ());
} else {
/* This function should never be called twice */
g_assert_not_reached ();
......
......@@ -852,7 +852,7 @@ system_config_interface_init (NMSystemConfigInterface *system_config_interface_c
}
G_MODULE_EXPORT GObject *
nm_system_config_factory (const char *config_file)
nm_system_config_factory (void)
{
static SCPluginIfcfg *singleton = NULL;
SCPluginIfcfgPrivate *priv;
......
......@@ -309,7 +309,7 @@ system_config_interface_init (NMSystemConfigInterface *system_config_interface_c
}
G_MODULE_EXPORT GObject *
nm_system_config_factory (const char *config_file)
nm_system_config_factory (void)
{
static SCPluginIfcfg *singleton = NULL;
......
......@@ -3,6 +3,7 @@ SUBDIRS = . tests
@GNOME_CODE_COVERAGE_RULES@
INCLUDES = \
-I$(top_srcdir)/src/config \
-I$(top_srcdir)/src/wifi \
-I$(top_srcdir)/src/settings \
-I$(top_srcdir)/include \
......
......@@ -32,6 +32,7 @@
#include "NetworkManager.h"
#include "nm-system-config-interface.h"
#include "nm-ifnet-connection.h"
#include "nm-config.h"
#include "plugin.h"
#include "net_utils.h"
......@@ -48,7 +49,6 @@
typedef struct {
GHashTable *config_connections;
gchar *hostname;
char *conf_file;
gboolean unmanaged_well_known;
GFileMonitor *hostname_monitor;
......@@ -535,7 +535,6 @@ dispose (GObject * object)
}
g_free (priv->hostname);
g_free (priv->conf_file);
ifnet_destroy ();
wpa_parser_destroy ();
G_OBJECT_CLASS (sc_plugin_ifnet_parent_class)->dispose (object);
......@@ -572,22 +571,11 @@ sc_plugin_ifnet_class_init (SCPluginIfnetClass * req_class)
const char *
ifnet_plugin_get_conf_file (void)
{
SCPluginIfnet *ifnet_plugin;
SCPluginIfnetPrivate *priv;
/* Get config file name. Plugin's singleton has already been created
* with correct config file path, so the string passed here has no efect
* and we get the valid file name.
*/
ifnet_plugin = SC_PLUGIN_IFNET (nm_system_config_factory ("fake string"));
priv = SC_PLUGIN_IFNET_GET_PRIVATE (ifnet_plugin);
g_object_unref (ifnet_plugin);
return priv->conf_file;
return nm_config_get_path (nm_config_get ());
}
G_MODULE_EXPORT GObject *
nm_system_config_factory (const char *config_file)
nm_system_config_factory (void)
{
static SCPluginIfnet *singleton = NULL;
SCPluginIfnetPrivate *priv;
......@@ -595,7 +583,6 @@ nm_system_config_factory (const char *config_file)
if (!singleton) {
singleton = SC_PLUGIN_IFNET (g_object_new (SC_TYPE_PLUGIN_IFNET, NULL));
priv = SC_PLUGIN_IFNET_GET_PRIVATE (singleton);
priv->conf_file = strdup (config_file);
} else
g_object_ref (singleton);
......
......@@ -4,6 +4,7 @@ SUBDIRS = . tests
INCLUDES = \
-I$(top_srcdir)/src/logging \
-I$(top_srcdir)/src/config \
-I$(top_srcdir)/src/settings \
-I$(top_srcdir)/include \
-I$(top_builddir)/include \
......
......@@ -50,6 +50,7 @@
#include "nm-inotify-helper.h"
#include "nm-logging.h"
#include "nm-config.h"
#include <arpa/inet.h>
......@@ -79,7 +80,7 @@ typedef struct {
GHashTable *well_known_interfaces;
GHashTable *well_known_ifaces;
gboolean unmanage_well_known;
char *conf_file;
const char *conf_file;
gulong inotify_event_id;
int inotify_system_hostname_wd;
......@@ -698,8 +699,6 @@ GObject__dispose (GObject *object)
if (priv->well_known_interfaces)
g_hash_table_destroy(priv->well_known_interfaces);
g_free (priv->conf_file);
if (priv->client)
g_object_unref (priv->client);
......@@ -708,7 +707,7 @@ GObject__dispose (GObject *object)
}
G_MODULE_EXPORT GObject *
nm_system_config_factory (const char *config_file)
nm_system_config_factory (void)
{
static SCPluginIfupdown *singleton = NULL;
SCPluginIfupdownPrivate *priv;
......@@ -716,7 +715,7 @@ nm_system_config_factory (const char *config_file)
if (!singleton) {
singleton = SC_PLUGIN_IFUPDOWN (g_object_new (SC_TYPE_PLUGIN_IFUPDOWN, NULL));
priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (singleton);
priv->conf_file = strdup (config_file);
priv->conf_file = nm_config_get_path (nm_config_get ());
} else
g_object_ref (singleton);
......
......@@ -3,6 +3,7 @@ SUBDIRS = . tests
@GNOME_CODE_COVERAGE_RULES@
INCLUDES = \
-I$(top_srcdir)/src/config \
-I$(top_srcdir)/src/settings \
-I$(top_srcdir)/include \
-I$(top_builddir)/include \
......
......@@ -35,6 +35,7 @@
#include <nm-setting.h>
#include <nm-setting-connection.h>
#include <nm-utils.h>
#include <nm-config.h>
#include "plugin.h"
#include "nm-system-config-interface.h"
......@@ -58,7 +59,7 @@ typedef struct {
GFileMonitor *monitor;
guint monitor_id;
char *conf_file;
const char *conf_file;
GFileMonitor *conf_file_monitor;
guint conf_file_monitor_id;
......@@ -641,7 +642,6 @@ dispose (GObject *object)
}
g_free (priv->hostname);
g_free (priv->conf_file);
if (priv->hash)
g_hash_table_destroy (priv->hash);
......@@ -687,7 +687,7 @@ system_config_interface_init (NMSystemConfigInterface *system_config_interface_c
}
GObject *
nm_settings_keyfile_plugin_new (const char *config_file)
nm_settings_keyfile_plugin_new (void)
{
static SCPluginKeyfile *singleton = NULL;
SCPluginKeyfilePrivate *priv;
......@@ -696,7 +696,7 @@ nm_settings_keyfile_plugin_new (const char *config_file)
singleton = SC_PLUGIN_KEYFILE (g_object_new (SC_TYPE_PLUGIN_KEYFILE, NULL));
priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (singleton);
priv->conf_file = g_strdup (config_file);
priv->conf_file = nm_config_get_path (nm_config_get ());
/* plugin_set_hostname() has to be called *after* priv->conf_file is set */
priv->hostname = plugin_get_hostname (singleton);
......
......@@ -43,6 +43,6 @@ GType sc_plugin_keyfile_get_type (void);
GQuark keyfile_plugin_error_quark (void);
GObject *nm_settings_keyfile_plugin_new (const char *config_file);
GObject *nm_settings_keyfile_plugin_new (void);
#endif /* _PLUGIN_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