mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-20 08:31:47 +00:00
core: add option for running from the build tree
Add hidden command line option --run-from-build-dir; with that, helpers like nm-avahi-autoipd.action and nm-dhcp-helper will be called from the build tree instead of libexecdir, which allows testing without having to install first. Helper paths are now stored in global variables instead of macros, and get modified with that new option. https://bugzilla.gnome.org/show_bug.cgi?id=698752
This commit is contained in:
parent
a05941881e
commit
fd4709fa27
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <arpa/inet.h>
|
||||
|
||||
#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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
27
src/main.c
27
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 <basedir>/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
|
||||
|
|
Loading…
Reference in a new issue