summary refs log tree commit diff
path: root/src/dnsmasq-manager
diff options
context:
space:
mode:
Diffstat (limited to 'src/dnsmasq-manager')
-rw-r--r--src/dnsmasq-manager/nm-dnsmasq-manager.c95
-rw-r--r--src/dnsmasq-manager/nm-dnsmasq-manager.h11
-rw-r--r--src/dnsmasq-manager/nm-dnsmasq-utils.c3
-rw-r--r--src/dnsmasq-manager/nm-dnsmasq-utils.h6
-rw-r--r--src/dnsmasq-manager/tests/Makefile.am6
-rw-r--r--src/dnsmasq-manager/tests/Makefile.in12
-rw-r--r--src/dnsmasq-manager/tests/test-dnsmasq-utils.c2
7 files changed, 35 insertions, 100 deletions
diff --git a/src/dnsmasq-manager/nm-dnsmasq-manager.c b/src/dnsmasq-manager/nm-dnsmasq-manager.c
index 21bbd23a..2f38ea71 100644
--- a/src/dnsmasq-manager/nm-dnsmasq-manager.c
+++ b/src/dnsmasq-manager/nm-dnsmasq-manager.c
@@ -18,7 +18,8 @@
  * Copyright (C) 2008 - 2012 Red Hat, Inc.
  */
 
-#include <config.h>
+#include "config.h"
+
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <signal.h>
@@ -33,6 +34,7 @@
 #include "nm-glib-compat.h"
 #include "nm-posix-signals.h"
 #include "nm-utils.h"
+#include "NetworkManagerUtils.h"
 
 typedef struct {
 	char *iface;
@@ -53,22 +55,6 @@ enum {
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
-typedef enum {
-	NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND,
-	NM_DNSMASQ_MANAGER_ERROR_INVALID_IP_RANGE,
-} NMDnsMasqManagerError;
-
-GQuark
-nm_dnsmasq_manager_error_quark (void)
-{
-	static GQuark quark;
-
-	if (!quark)
-		quark = g_quark_from_static_string ("nm_dnsmasq_manager_error");
-
-	return quark;
-}
-
 static void
 nm_dnsmasq_manager_init (NMDnsMasqManager *manager)
 {
@@ -168,27 +154,6 @@ nm_cmd_line_add_string (NMCmdLine *cmd, const char *str)
 
 /*******************************************/
 
-static inline const char *
-nm_find_dnsmasq (void)
-{
-	static const char *dnsmasq_binary_paths[] = {
-		DNSMASQ_PATH,
-		"/usr/local/sbin/dnsmasq",
-		"/usr/sbin/dnsmasq",
-		"/sbin/dnsmasq",
-		NULL
-	};
-	const char **dnsmasq_binary = dnsmasq_binary_paths;
-
-	while (*dnsmasq_binary != NULL) {
-		if (**dnsmasq_binary && g_file_test (*dnsmasq_binary, G_FILE_TEST_EXISTS))
-			break;
-		dnsmasq_binary++;
-	}
-
-	return *dnsmasq_binary;
-}
-
 static void
 dm_exit_code (guint dm_exit_status)
 {
@@ -249,7 +214,6 @@ create_dm_cmd_line (const char *iface,
                     const char *pidfile,
                     GError **error)
 {
-	const char *dm_binary;
 	NMCmdLine *cmd;
 	GString *s;
 	const NMPlatformIP4Address *tmp;
@@ -257,16 +221,11 @@ create_dm_cmd_line (const char *iface,
 	char last[INET_ADDRSTRLEN];
 	char localaddr[INET_ADDRSTRLEN];
 	char *error_desc = NULL;
+	const char *dm_binary;
 
-	dm_binary = nm_find_dnsmasq ();
-	if (!dm_binary) {
-		g_set_error_literal (error, NM_DNSMASQ_MANAGER_ERROR, NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND,
-		                     "Could not find dnsmasq binary.");
+	dm_binary = nm_utils_find_helper ("dnsmasq", DNSMASQ_PATH, error);
+	if (!dm_binary)
 		return NULL;
-	}
-
-	/* Find the IP4 address to use */
-	tmp = nm_ip4_config_get_address (ip4_config, 0);
 
 	/* Create dnsmasq command line */
 	cmd = nm_cmd_line_new ();
@@ -297,6 +256,9 @@ create_dm_cmd_line (const char *iface,
 	 */
 	nm_cmd_line_add_string (cmd, "--strict-order");
 
+	/* Find the IP4 address to use */
+	tmp = nm_ip4_config_get_address (ip4_config, 0);
+
 	s = g_string_new ("--listen-address=");
 	nm_utils_inet4_ntop (tmp->address, localaddr);
 	g_string_append (s, localaddr);
@@ -305,12 +267,13 @@ create_dm_cmd_line (const char *iface,
 
 	if (!nm_dnsmasq_utils_get_range (tmp, first, last, &error_desc)) {
 		g_set_error_literal (error,
-		                     NM_DNSMASQ_MANAGER_ERROR,
-		                     NM_DNSMASQ_MANAGER_ERROR_INVALID_IP_RANGE,
+		                     NM_MANAGER_ERROR,
+		                     NM_MANAGER_ERROR_FAILED,
 		                     error_desc);
 		nm_log_warn (LOGD_SHARING, "Failed to find DHCP address ranges: %s", error_desc);
 		g_free (error_desc);
-		goto error;
+		nm_cmd_line_destroy (cmd);
+		return NULL;
 	}
 
 	s = g_string_new ("--dhcp-range=");
@@ -331,10 +294,6 @@ create_dm_cmd_line (const char *iface,
 	g_string_free (s, TRUE);
 
 	return cmd;
-
-error:
-	nm_cmd_line_destroy (cmd);
-	return NULL;
 }
 
 static void
@@ -432,22 +391,6 @@ nm_dnsmasq_manager_start (NMDnsMasqManager *manager,
 	return priv->pid > 0;
 }
 
-static gboolean
-ensure_killed (gpointer data)
-{
-	int pid = GPOINTER_TO_INT (data);
-
-	if (kill (pid, 0) == 0)
-		kill (pid, SIGKILL);
-
-	/* ensure the child is reaped */
-	nm_log_dbg (LOGD_SHARING, "waiting for dnsmasq pid %d to exit", pid);
-	waitpid (pid, NULL, 0);
-	nm_log_dbg (LOGD_SHARING, "dnsmasq pid %d cleaned up", pid);
-
-	return FALSE;
-}
-
 void
 nm_dnsmasq_manager_stop (NMDnsMasqManager *manager)
 {
@@ -463,17 +406,7 @@ nm_dnsmasq_manager_stop (NMDnsMasqManager *manager)
 	}
 
 	if (priv->pid) {
-		if (kill (priv->pid, SIGTERM) == 0)
-			g_timeout_add_seconds (2, ensure_killed, GINT_TO_POINTER (priv->pid));
-		else {
-			kill (priv->pid, SIGKILL);
-
-			/* ensure the child is reaped */
-			nm_log_dbg (LOGD_SHARING, "waiting for dnsmasq pid %d to exit", priv->pid);
-			waitpid (priv->pid, NULL, 0);
-			nm_log_dbg (LOGD_SHARING, "dnsmasq pid %d cleaned up", priv->pid);
-		}
-
+		nm_utils_kill_child_async (priv->pid, SIGTERM, LOGD_SHARING, "dnsmasq", 2000, NULL, NULL);
 		priv->pid = 0;
 	}
 
diff --git a/src/dnsmasq-manager/nm-dnsmasq-manager.h b/src/dnsmasq-manager/nm-dnsmasq-manager.h
index e98a6adb..257cc755 100644
--- a/src/dnsmasq-manager/nm-dnsmasq-manager.h
+++ b/src/dnsmasq-manager/nm-dnsmasq-manager.h
@@ -18,8 +18,8 @@
  * Copyright (C) 2008 Red Hat, Inc.
  */
 
-#ifndef NM_DNSMASQ_MANAGER_H
-#define NM_DNSMASQ_MANAGER_H
+#ifndef __NETWORKMANAGER_DNSMASQ_MANAGER_H__
+#define __NETWORKMANAGER_DNSMASQ_MANAGER_H__
 
 #include <glib.h>
 #include <glib-object.h>
@@ -61,9 +61,4 @@ gboolean nm_dnsmasq_manager_start (NMDnsMasqManager *manager,
 
 void     nm_dnsmasq_manager_stop  (NMDnsMasqManager *manager);
 
-#define NM_DNSMASQ_MANAGER_ERROR nm_dnsmasq_manager_error_quark()
-#define NM_TYPE_DNSMASQ_MANAGER_ERROR (nm_dnsmasq_manager_error_get_type ()) 
-
-GQuark nm_dnsmasq_manager_error_quark (void);
-
-#endif /* NM_DNSMASQ_MANAGER_H */
+#endif /* __NETWORKMANAGER_DNSMASQ_MANAGER_H__ */
diff --git a/src/dnsmasq-manager/nm-dnsmasq-utils.c b/src/dnsmasq-manager/nm-dnsmasq-utils.c
index 7036b409..4394ae7b 100644
--- a/src/dnsmasq-manager/nm-dnsmasq-utils.c
+++ b/src/dnsmasq-manager/nm-dnsmasq-utils.c
@@ -18,7 +18,8 @@
  * Copyright (C) 2013 Red Hat, Inc.
  */
 
-#include <config.h>
+#include "config.h"
+
 #include <string.h>
 #include <arpa/inet.h>
 
diff --git a/src/dnsmasq-manager/nm-dnsmasq-utils.h b/src/dnsmasq-manager/nm-dnsmasq-utils.h
index 4534c6ef..bb468c82 100644
--- a/src/dnsmasq-manager/nm-dnsmasq-utils.h
+++ b/src/dnsmasq-manager/nm-dnsmasq-utils.h
@@ -18,8 +18,8 @@
  * Copyright (C) 2013 Red Hat, Inc.
  */
 
-#ifndef NM_DNSMASQ_UTILS_H
-#define NM_DNSMASQ_UTILS_H
+#ifndef __NETWORKMANAGER_DNSMASQ_UTILS_H__
+#define __NETWORKMANAGER_DNSMASQ_UTILS_H__
 
 #include <glib.h>
 #include "nm-platform.h"
@@ -29,4 +29,4 @@ gboolean nm_dnsmasq_utils_get_range (const NMPlatformIP4Address *addr,
                                      char *out_last,
                                      char **out_error_desc);
 
-#endif /* NM_DNSMASQ_UTILS_H */
+#endif /* __NETWORKMANAGER_DNSMASQ_UTILS_H__ */
diff --git a/src/dnsmasq-manager/tests/Makefile.am b/src/dnsmasq-manager/tests/Makefile.am
index 9c7f4ab5..c6ce1cda 100644
--- a/src/dnsmasq-manager/tests/Makefile.am
+++ b/src/dnsmasq-manager/tests/Makefile.am
@@ -1,12 +1,12 @@
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/include \
-	-I$(top_builddir)/include \
-	-I${top_srcdir}/libnm-util \
-	-I${top_builddir}/libnm-util \
+	-I${top_srcdir}/libnm-core \
+	-I${top_builddir}/libnm-core \
 	-I$(top_srcdir)/src/dnsmasq-manager \
 	-I$(top_srcdir)/src \
 	-I$(top_srcdir)/src/platform \
 	-DG_LOG_DOMAIN=\""NetworkManager"\" \
+	-DNETWORKMANAGER_COMPILATION \
 	-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
 	$(GLIB_CFLAGS) \
 	-DTESTDIR="\"$(abs_srcdir)\""
diff --git a/src/dnsmasq-manager/tests/Makefile.in b/src/dnsmasq-manager/tests/Makefile.in
index 52301e3d..d5f92416 100644
--- a/src/dnsmasq-manager/tests/Makefile.in
+++ b/src/dnsmasq-manager/tests/Makefile.in
@@ -204,6 +204,8 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@
+BLUEZ5_LIBS = @BLUEZ5_LIBS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -327,6 +329,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@
 NEWT_LIBS = @NEWT_LIBS@
 NM = @NM@
 NMEDIT = @NMEDIT@
+NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@
 NM_MAJOR_VERSION = @NM_MAJOR_VERSION@
 NM_MICRO_VERSION = @NM_MICRO_VERSION@
 NM_MINOR_VERSION = @NM_MINOR_VERSION@
@@ -346,6 +349,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
 PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 PATH_SEPARATOR = @PATH_SEPARATOR@
+PERL = @PERL@
 PKG_CONFIG = @PKG_CONFIG@
 PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
 PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
@@ -372,7 +376,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@
 SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@
 SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@
 SYSTEM_CA_PATH = @SYSTEM_CA_PATH@
-UDEV_BASE_DIR = @UDEV_BASE_DIR@
+UDEV_DIR = @UDEV_DIR@
 USE_NLS = @USE_NLS@
 UUID_CFLAGS = @UUID_CFLAGS@
 UUID_LIBS = @UUID_LIBS@
@@ -453,13 +457,13 @@ with_resolvconf = @with_resolvconf@
 with_valgrind = @with_valgrind@
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/include \
-	-I$(top_builddir)/include \
-	-I${top_srcdir}/libnm-util \
-	-I${top_builddir}/libnm-util \
+	-I${top_srcdir}/libnm-core \
+	-I${top_builddir}/libnm-core \
 	-I$(top_srcdir)/src/dnsmasq-manager \
 	-I$(top_srcdir)/src \
 	-I$(top_srcdir)/src/platform \
 	-DG_LOG_DOMAIN=\""NetworkManager"\" \
+	-DNETWORKMANAGER_COMPILATION \
 	-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
 	$(GLIB_CFLAGS) \
 	-DTESTDIR="\"$(abs_srcdir)\""
diff --git a/src/dnsmasq-manager/tests/test-dnsmasq-utils.c b/src/dnsmasq-manager/tests/test-dnsmasq-utils.c
index 07dbc0f7..f8120ffe 100644
--- a/src/dnsmasq-manager/tests/test-dnsmasq-utils.c
+++ b/src/dnsmasq-manager/tests/test-dnsmasq-utils.c
@@ -18,6 +18,8 @@
  *
  */
 
+#include "config.h"
+
 #include <glib.h>
 #include <arpa/inet.h>