diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index ea775e1b44..112154cf5d 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -78,6 +78,9 @@ static void impl_device_disconnect (NMDevice *device, DBusGMethodInvocation *con #define DBUS_G_TYPE_UINT_STRUCT (dbus_g_type_get_struct ("GValueArray", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID)) +/* default to installed helper, but can be modified for testing */ +const char *nm_device_autoipd_helper_path = LIBEXECDIR "/nm-avahi-autoipd.action"; + /***********************************************************/ #define NM_DEVICE_ERROR (nm_device_error_quark ()) @@ -2128,7 +2131,8 @@ aipd_start (NMDevice *self, NMDeviceStateReason *reason) argv[i++] = (char *) (*aipd_binary); argv[i++] = "--script"; - argv[i++] = LIBEXECDIR "/nm-avahi-autoipd.action"; + argv[i++] = (char *) nm_device_autoipd_helper_path; + if (nm_logging_level_enabled (LOGL_DEBUG)) argv[i++] = "--debug"; argv[i++] = (char *) nm_device_get_ip_iface (self); diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 9ba79c92f8..bd0dfbc53f 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -317,4 +317,7 @@ gboolean nm_device_supports_vlans (NMDevice *device); G_END_DECLS +/* For testing only */ +extern const char* nm_device_autoipd_helper_path; + #endif /* NM_DEVICE_H */ diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c b/src/dhcp-manager/nm-dhcp-dhclient.c index c2fc707c36..6ef0a4b094 100644 --- a/src/dhcp-manager/nm-dhcp-dhclient.c +++ b/src/dhcp-manager/nm-dhcp-dhclient.c @@ -39,14 +39,13 @@ #include "nm-utils.h" #include "nm-logging.h" #include "nm-dhcp-dhclient-utils.h" +#include "nm-dhcp-manager.h" #include "nm-posix-signals.h" G_DEFINE_TYPE (NMDHCPDhclient, nm_dhcp_dhclient, NM_TYPE_DHCP_CLIENT) #define NM_DHCP_DHCLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_DHCLIENT, NMDHCPDhclientPrivate)) -#define ACTION_SCRIPT_PATH LIBEXECDIR "/nm-dhcp-helper" - typedef struct { const char *path; char *conf_file; @@ -589,7 +588,7 @@ dhclient_start (NMDHCPClient *client, g_ptr_array_add (argv, (gpointer) mode_opt); } g_ptr_array_add (argv, (gpointer) "-sf"); /* Set script file */ - g_ptr_array_add (argv, (gpointer) ACTION_SCRIPT_PATH ); + g_ptr_array_add (argv, (gpointer) nm_dhcp_helper_path); if (pid_file) { g_ptr_array_add (argv, (gpointer) "-pf"); /* Set pid file */ diff --git a/src/dhcp-manager/nm-dhcp-dhcpcd.c b/src/dhcp-manager/nm-dhcp-dhcpcd.c index 5ee6f8a7c3..7709720428 100644 --- a/src/dhcp-manager/nm-dhcp-dhcpcd.c +++ b/src/dhcp-manager/nm-dhcp-dhcpcd.c @@ -33,6 +33,7 @@ #include #include "nm-dhcp-dhcpcd.h" +#include "nm-dhcp-manager.h" #include "nm-utils.h" #include "nm-logging.h" #include "nm-posix-signals.h" @@ -41,8 +42,6 @@ G_DEFINE_TYPE (NMDHCPDhcpcd, nm_dhcp_dhcpcd, NM_TYPE_DHCP_CLIENT) #define NM_DHCP_DHCPCD_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_DHCPCD, NMDHCPDhcpcdPrivate)) -#define ACTION_SCRIPT_PATH LIBEXECDIR "/nm-dhcp-helper" - typedef struct { const char *path; char *pid_file; @@ -134,7 +133,7 @@ ip4_start (NMDHCPClient *client, g_ptr_array_add (argv, (gpointer) "-G"); /* Let NM handle routing */ g_ptr_array_add (argv, (gpointer) "-c"); /* Set script file */ - g_ptr_array_add (argv, (gpointer) ACTION_SCRIPT_PATH ); + g_ptr_array_add (argv, (gpointer) nm_dhcp_helper_path); if (hostname && strlen (hostname)) { g_ptr_array_add (argv, (gpointer) "-h"); /* Send hostname to DHCP server */ diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c index 893fa8219b..f2962e6b2c 100644 --- a/src/dhcp-manager/nm-dhcp-manager.c +++ b/src/dhcp-manager/nm-dhcp-manager.c @@ -64,6 +64,9 @@ nm_dhcp_manager_error_quark (void) static NMDHCPManager *singleton = NULL; +/* default to installed helper, but can be modified for testing */ +const char *nm_dhcp_helper_path = LIBEXECDIR "/nm-dhcp-helper"; + typedef GSList * (*GetLeaseConfigFunc) (const char *iface, const char *uuid, gboolean ipv6); typedef struct { @@ -726,4 +729,3 @@ nm_dhcp_manager_class_init (NMDHCPManagerClass *manager_class) object_class->finalize = finalize; object_class->dispose = dispose; } - diff --git a/src/dhcp-manager/nm-dhcp-manager.h b/src/dhcp-manager/nm-dhcp-manager.h index e61468e3cd..9b19f4a971 100644 --- a/src/dhcp-manager/nm-dhcp-manager.h +++ b/src/dhcp-manager/nm-dhcp-manager.h @@ -93,4 +93,6 @@ NMIP4Config *nm_dhcp_manager_test_ip4_options_to_config (const char *dhcp_client GHashTable *options, const char *reason); +extern const char* nm_dhcp_helper_path; + #endif /* NM_DHCP_MANAGER_H */ diff --git a/src/main.c b/src/main.c index 5a8276fc1f..5de7662bfe 100644 --- a/src/main.c +++ b/src/main.c @@ -304,7 +304,7 @@ int main (int argc, char *argv[]) { GOptionContext *opt_ctx = NULL; - gboolean become_daemon = FALSE; + gboolean become_daemon = FALSE, run_from_build_dir = FALSE; gboolean debug = FALSE; gboolean g_fatal_warnings = FALSE; gs_free char *pidfile = NULL; @@ -330,6 +330,7 @@ main (int argc, char *argv[]) { "g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, N_("Make all warnings fatal"), NULL }, { "pid-file", 'p', 0, G_OPTION_ARG_FILENAME, &pidfile, N_("Specify the location of a PID file"), N_("filename") }, { "state-file", 0, 0, G_OPTION_ARG_FILENAME, &state_file, N_("State file location"), N_("/path/to/state.file") }, + { "run-from-build-dir", 0, 0, G_OPTION_ARG_NONE, &run_from_build_dir, "Run from build directory", NULL }, {NULL} }; @@ -374,6 +375,30 @@ main (int argc, char *argv[]) exit (1); } + /* When running from the build directory, determine our build directory + * base and set helper paths in the build tree */ + if (run_from_build_dir) { + char *path, *slash; + int i; + + /* exe is /src/.libs/lt-NetworkManager, so chop off + * the last three components */ + path = realpath ("/proc/self/exe", NULL); + g_assert (path != NULL); + for (i = 0; i < 3; ++i) { + slash = strrchr (path, '/'); + g_assert (slash != NULL); + *slash = '\0'; + } + + /* don't free these strings, we need them for the entire + * process lifetime */ + nm_dhcp_helper_path = g_strdup_printf ("%s/src/dhcp-manager/nm-dhcp-helper", path); + nm_device_autoipd_helper_path = g_strdup_printf ("%s/callouts/nm-avahi-autoipd.action", path); + + g_free (path); + } + /* Make GIO ignore the remote VFS service; otherwise it tries to use the * session bus to contact the remote service, and NM shouldn't ever be * talking on the session bus. See rh #588745