[PATCH] main: Fix running with --run-from-build-dir



Previously, NM failed to find out plugins with --run-from-build-dir option.
This patch fixes the issue.

Signed-off-by: Masashi Honma <masashi honma gmail com>
---
 src/main.c                 |  8 ++++++--
 src/nm-manager.c           | 10 ++++++++++
 src/nm-manager.h           |  1 +
 src/settings/nm-settings.c | 15 ++++++++++++++-
 src/settings/nm-settings.h |  2 ++
 5 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/main.c b/src/main.c
index d59da05..8b5e533 100644
--- a/src/main.c
+++ b/src/main.c
@@ -198,7 +198,7 @@ do_early_setup (int *argc, char **argv[], NMConfigCmdLineOptions *config_cli)
                  "PLATFORM,RFKILL,WIFI" },
                { "g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &global_opt.g_fatal_warnings, N_("Make all 
warnings fatal"), NULL },
                { "pid-file", 'p', 0, G_OPTION_ARG_FILENAME, &global_opt.pidfile, N_("Specify the location of 
a PID file"), NM_DEFAULT_PID_FILE },
-               { "run-from-build-dir", 0, 0, G_OPTION_ARG_NONE, &global_opt.run_from_build_dir, "Run from 
build directory", NULL },
+               { "run-from-build-dir", 0, 0, G_OPTION_ARG_NONE, &global_opt.run_from_build_dir, "Run from 
build directory (Before using this option, disable AppArmor)", NULL },
                { "print-config", 0, 0, G_OPTION_ARG_NONE, &global_opt.print_config, N_("Print NetworkManager 
configuration and exit"), NULL },
                {NULL}
        };
@@ -227,6 +227,7 @@ main (int argc, char *argv[])
        GError *error = NULL;
        gboolean wrote_pidfile = FALSE;
        char *bad_domains = NULL;
+       char *plugin_path = NULL;
        NMConfigCmdLineOptions *config_cli;
        guint sd_id = 0;
 
@@ -282,7 +283,7 @@ main (int argc, char *argv[])
                 * the last three components */
                path = realpath ("/proc/self/exe", NULL);
                g_assert (path != NULL);
-               for (g = 0; g < 3; ++g) {
+               for (g = 0; g < 2; ++g) {
                        slash = strrchr (path, '/');
                        g_assert (slash != NULL);
                        *slash = '\0';
@@ -291,6 +292,7 @@ main (int argc, char *argv[])
                /* don't free these strings, we need them for the entire
                 * process lifetime */
                nm_dhcp_helper_path = g_strdup_printf ("%s/src/dhcp/nm-dhcp-helper", path);
+               plugin_path = g_strdup_printf ("%s/src/settings/plugins/ifupdown/.libs", path);
 
                g_free (path);
        }
@@ -396,6 +398,8 @@ main (int argc, char *argv[])
 
        nm_manager_setup ();
 
+       nm_manager_set_plugin_path(nm_manager_get (), plugin_path);
+
        if (!nm_bus_manager_get_connection (nm_bus_manager_get ())) {
                nm_log_warn (LOGD_CORE, "Failed to connect to D-Bus; only private bus is available");
        } else {
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 3b2b486..146f88e 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -152,6 +152,7 @@ typedef struct {
 
        GSList *auth_chains;
        GHashTable *sleep_devices;
+       const char *plugin_path;
 
        /* Firmware dir monitor */
        GFileMonitor *fw_monitor;
@@ -5198,6 +5199,7 @@ nm_manager_start (NMManager *self, GError **error)
        gs_free NMSettingsConnection **connections = NULL;
        guint i;
 
+       nm_settings_set_plugin_path(priv->settings, priv->plugin_path);
        if (!nm_settings_start (priv->settings, error))
                return FALSE;
 
@@ -6069,6 +6071,14 @@ nm_manager_set_capability (NMManager *self,
        _notify (self, PROP_CAPABILITIES);
 }
 
+void
+nm_manager_set_plugin_path (NMManager *self, const char *plugin_path)
+{
+       NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
+
+       priv->plugin_path = plugin_path;
+}
+
 /*****************************************************************************/
 
 NM_DEFINE_SINGLETON_REGISTER (NMManager);
diff --git a/src/nm-manager.h b/src/nm-manager.h
index 622edb5..8b661e7 100644
--- a/src/nm-manager.h
+++ b/src/nm-manager.h
@@ -125,6 +125,7 @@ gboolean            nm_manager_deactivate_connection   (NMManager *manager,
                                                         GError **error);
 
 void                nm_manager_set_capability   (NMManager *self, NMCapability cap);
+void                nm_manager_set_plugin_path  (NMManager *self, const char *plugin_path);
 
 NMDevice *          nm_manager_get_device    (NMManager *self,
                                               const char *ifname,
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index e2b467a..979c51e 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -154,6 +154,7 @@ typedef struct {
 
        NMHostnameManager *hostname_manager;
 
+       const char *plugin_path;
 } NMSettingsPrivate;
 
 struct _NMSettings {
@@ -686,6 +687,7 @@ 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;
@@ -750,7 +752,8 @@ load_plugin:
                        int errsv;
 
                        full_name = g_strdup_printf ("nm-settings-plugin-%s", pname);
-                       path = g_module_build_path (NMPLUGINDIR, full_name);
+                       path = g_module_build_path (
+                               priv->plugin_path ? priv->plugin_path : NMPLUGINDIR, full_name);
 
                        if (stat (path, &st) != 0) {
                                errsv = errno;
@@ -1789,6 +1792,16 @@ nm_settings_get_startup_complete (NMSettings *self)
 
 /*****************************************************************************/
 
+void
+nm_settings_set_plugin_path (NMSettings *self, const char *plugin_path)
+{
+       NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
+
+       priv->plugin_path = plugin_path;
+}
+
+/*****************************************************************************/
+
 static void
 _hostname_changed_cb (NMHostnameManager *hostname_manager,
                       GParamSpec *pspec,
diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h
index eede76b..8f804de 100644
--- a/src/settings/nm-settings.h
+++ b/src/settings/nm-settings.h
@@ -125,4 +125,6 @@ void nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean qu
 
 gboolean nm_settings_get_startup_complete (NMSettings *self);
 
+void nm_settings_set_plugin_path (NMSettings *self, const char *plugin_path);
+
 #endif  /* __NM_SETTINGS_H__ */
-- 
2.7.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]