NetworkManager r3712 - in trunk: . src src/dnsmasq-manager



Author: dcbw
Date: Thu May 29 21:16:51 2008
New Revision: 3712
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3712&view=rev

Log:
2008-05-29  Dan Williams <dcbw redhat com>

	* src/dnsmasq-manager/nm-dnsmasq-manager.c
	  src/dnsmasq-manager/nm-dnsmasq-manager.h
		- (nm_dnsmasq_manager_new): move iface argument here
		- (constructor): remove, not needed
		- (get_pidfile_for_iface, create_dm_cmd_line, kill_existing_for_iface,
		   nm_dnsmasq_manager_start, nm_dnsmasq_manager_stop): use priv->pidfile

	* src/nm-device.c
		- (real_act_stage4_get_ip4_config,
		   nm_device_activate_stage5_ip_config_commit): fix for dnsmasq manager
			changes



Modified:
   trunk/ChangeLog
   trunk/src/dnsmasq-manager/nm-dnsmasq-manager.c
   trunk/src/dnsmasq-manager/nm-dnsmasq-manager.h
   trunk/src/nm-device.c

Modified: trunk/src/dnsmasq-manager/nm-dnsmasq-manager.c
==============================================================================
--- trunk/src/dnsmasq-manager/nm-dnsmasq-manager.c	(original)
+++ trunk/src/dnsmasq-manager/nm-dnsmasq-manager.c	Thu May 29 21:16:51 2008
@@ -12,6 +12,8 @@
 #include "nm-utils.h"
 
 typedef struct {
+	char *iface;
+	char *pidfile;
 	GPid pid;
 	guint32 dm_watch_id;
 } NMDnsMasqManagerPrivate;
@@ -29,7 +31,7 @@
 static guint signals[LAST_SIGNAL] = { 0 };
 
 typedef enum {
-	NM_DNSMASQ_MANAGER_ERROR_UNKOWN
+	NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND,
 } NMDnsMasqManagerError;
 
 GQuark
@@ -48,21 +50,16 @@
 {
 }
 
-static GObject *
-constructor (GType type,
-             guint n_construct_params,
-             GObjectConstructParam *construct_params)
-{
-	return G_OBJECT_CLASS (nm_dnsmasq_manager_parent_class)->constructor (type,
-														   n_construct_params,
-														   construct_params);
-}
-
 static void
 finalize (GObject *object)
 {
+	NMDnsMasqManagerPrivate *priv = NM_DNSMASQ_MANAGER_GET_PRIVATE (object);
+
 	nm_dnsmasq_manager_stop (NM_DNSMASQ_MANAGER (object));
 
+	g_free (priv->iface);
+	g_free (priv->pidfile);
+
 	G_OBJECT_CLASS (nm_dnsmasq_manager_parent_class)->finalize (object);
 }
 
@@ -73,7 +70,6 @@
 
 	g_type_class_add_private (manager_class, sizeof (NMDnsMasqManagerPrivate));
 
-	object_class->constructor = constructor;
 	object_class->finalize = finalize;
 
 	/* signals */
@@ -89,9 +85,20 @@
 }
 
 NMDnsMasqManager *
-nm_dnsmasq_manager_new (void)
+nm_dnsmasq_manager_new (const char *iface)
 {
-	return (NMDnsMasqManager *) g_object_new (NM_TYPE_DNSMASQ_MANAGER, NULL);
+	NMDnsMasqManager *manager;
+	NMDnsMasqManagerPrivate *priv;
+
+	manager = (NMDnsMasqManager *) g_object_new (NM_TYPE_DNSMASQ_MANAGER, NULL);
+	if (!manager)
+		return NULL;
+
+	priv = NM_DNSMASQ_MANAGER_GET_PRIVATE (manager);
+	priv->iface = g_strdup (iface);
+	priv->pidfile = g_strdup_printf (LOCALSTATEDIR "/run/nm-dnsmasq-%s.pid", iface);
+
+	return manager;
 }
 
 typedef struct {
@@ -217,25 +224,17 @@
 	g_signal_emit (manager, signals[STATE_CHANGED], 0, NM_DNSMASQ_STATUS_DEAD);
 }
 
-static char *
-get_pidfile_for_iface (const char *iface)
-{
-	g_return_val_if_fail (iface != NULL, NULL);
-
-	return g_strdup_printf (LOCALSTATEDIR "/run/nm-dnsmasq-%s.pid", iface);
-}
-
 static NMCmdLine *
-create_dm_cmd_line (const char *iface, GError **err)
+create_dm_cmd_line (const char *iface, const char *pidfile, GError **error)
 {
 	const char *dm_binary;
 	NMCmdLine *cmd;
-	char *s, *pidfile;
+	char *s;
 
 	dm_binary = nm_find_dnsmasq ();
 	if (!dm_binary) {
-		g_set_error (err, NM_DNSMASQ_MANAGER_ERROR, NM_DNSMASQ_MANAGER_ERROR,
-				   "Could not find dnsmasq binary.");
+		g_set_error (error, NM_DNSMASQ_MANAGER_ERROR, NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND,
+		             "Could not find dnsmasq binary.");
 		return NULL;
 	}
 
@@ -252,9 +251,7 @@
 	nm_cmd_line_add_string (cmd, "--dhcp-option=option:router,0.0.0.0");
 	nm_cmd_line_add_string (cmd, "--dhcp-lease-max=50");
 
-	pidfile = get_pidfile_for_iface (iface);
 	s = g_strdup_printf ("--pid-file=%s", pidfile);
-	g_free (pidfile);
 	nm_cmd_line_add_string (cmd, s);
 	g_free (s);
 
@@ -270,15 +267,13 @@
 }
 
 static void
-kill_existing_for_iface (const char *iface)
+kill_existing_for_iface (const char *iface, const char *pidfile)
 {
-	char *pidfile;
 	char *contents = NULL;
 	glong pid;
 	char *proc_path = NULL;
 	char *cmdline_contents = NULL;
 
-	pidfile = get_pidfile_for_iface (iface);
 	if (!g_file_get_contents (pidfile, &contents, NULL, NULL))
 		goto out;
 
@@ -302,13 +297,10 @@
 	g_free (cmdline_contents);
 	g_free (proc_path);
 	g_free (contents);
-	g_free (pidfile);
 }
 
 gboolean
-nm_dnsmasq_manager_start (NMDnsMasqManager *manager,
-				  const char *iface,
-				  GError **err)
+nm_dnsmasq_manager_start (NMDnsMasqManager *manager, GError **error)
 {
 	NMDnsMasqManagerPrivate *priv;
 	NMCmdLine *dm_cmd;
@@ -316,18 +308,19 @@
 	GSource *dm_watch;
 
 	g_return_val_if_fail (NM_IS_DNSMASQ_MANAGER (manager), FALSE);
-	g_return_val_if_fail (iface != NULL, FALSE);
+	if (error)
+		g_return_val_if_fail (*error == NULL, FALSE);
 
-	kill_existing_for_iface (iface);
+	priv = NM_DNSMASQ_MANAGER_GET_PRIVATE (manager);
+
+	kill_existing_for_iface (priv->iface, priv->pidfile);
 
-	dm_cmd = create_dm_cmd_line (iface, err);
+	dm_cmd = create_dm_cmd_line (priv->iface, priv->pidfile, error);
 	if (!dm_cmd)
 		return FALSE;
 
 	g_ptr_array_add (dm_cmd->array, NULL);
 
-	priv = NM_DNSMASQ_MANAGER_GET_PRIVATE (manager);
-
 	nm_info ("Starting dnsmasq...");
 
 	cmd_str = nm_cmd_line_to_str (dm_cmd);
@@ -338,7 +331,7 @@
 	if (!g_spawn_async (NULL, (char **) dm_cmd->array->pdata, NULL,
 					G_SPAWN_DO_NOT_REAP_CHILD,
 					dm_child_setup,
-					NULL, &priv->pid, err)) {
+					NULL, &priv->pid, error)) {
 		goto out;
 	}
 
@@ -390,4 +383,6 @@
 
 		priv->pid = 0;
 	}
+
+	unlink (priv->pidfile);
 }

Modified: trunk/src/dnsmasq-manager/nm-dnsmasq-manager.h
==============================================================================
--- trunk/src/dnsmasq-manager/nm-dnsmasq-manager.h	(original)
+++ trunk/src/dnsmasq-manager/nm-dnsmasq-manager.h	Thu May 29 21:16:51 2008
@@ -33,11 +33,9 @@
 
 GType nm_dnsmasq_manager_get_type (void);
 
-NMDnsMasqManager *nm_dnsmasq_manager_new (void);
+NMDnsMasqManager *nm_dnsmasq_manager_new (const char *iface);
 
-gboolean nm_dnsmasq_manager_start (NMDnsMasqManager *manager,
-                                   const char *device,
-                                   GError **err);
+gboolean nm_dnsmasq_manager_start (NMDnsMasqManager *manager, GError **error);
 
 void     nm_dnsmasq_manager_stop  (NMDnsMasqManager *manager);
 

Modified: trunk/src/nm-device.c
==============================================================================
--- trunk/src/nm-device.c	(original)
+++ trunk/src/nm-device.c	Thu May 29 21:16:51 2008
@@ -701,7 +701,7 @@
 			nm_utils_merge_ip4_config (*config, s_ip4);
 		} else if (!strcmp (s_ip4->method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) {
 			*config = nm_device_new_ip4_shared_config (self);
-			priv->dnsmasq_manager = nm_dnsmasq_manager_new ();
+			priv->dnsmasq_manager = nm_dnsmasq_manager_new (nm_device_get_ip_iface (self));
 		}
 	}
 
@@ -895,7 +895,7 @@
 	if (s_ip4 && !strcmp (s_ip4->method, "shared")) {
 		GError *error = NULL;
 
-		if (!nm_dnsmasq_manager_start (priv->dnsmasq_manager, nm_device_get_ip_iface (self), &error)) {
+		if (!nm_dnsmasq_manager_start (priv->dnsmasq_manager, &error)) {
 			nm_warning ("(%s): failed to start dnsmasq: %s", iface, error->message);
 			g_error_free (error);
 			nm_device_state_changed (self, NM_DEVICE_STATE_FAILED);



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