vpnc and random other cleanups



Hi,

I've attached two patches below.  The first one just does random
cleanups--adding consts where consts belong, adding statics where they
belong, etc...just stuff that I needed to get NetworkManager to build
with my default CFLAGS.

The second patch changes the network manager vpnc helper program to
invoke vpnc in no daemon mode.  This makes it so that vpnc will keep
the same pid it was spawned with, and thus eliminate the race of
waiting for a pid file to be written and read.

--Ray
Index: gnome/applet/applet.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet.c,v
retrieving revision 1.24
diff -u -p -r1.24 applet.c
--- gnome/applet/applet.c	8 Jul 2005 02:37:10 -0000	1.24
+++ gnome/applet/applet.c	8 Jul 2005 04:28:51 -0000
@@ -1344,12 +1344,12 @@ static void nmwa_menu_vpn_item_activate 
 static void nmwa_menu_configure_vpn_item_activate (GtkMenuItem *item, gpointer user_data)
 {
 	NMWirelessApplet	*applet = (NMWirelessApplet *)user_data;
-	char *argv[2] = {BINDIR "/nm-vpn-properties", NULL};
+	const char *argv[] = { BINDIR "/nm-vpn-properties", NULL};
 
 	g_return_if_fail (item != NULL);
 	g_return_if_fail (applet != NULL);
 
-	g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL);
+	g_spawn_async (NULL, (gchar **) argv, NULL, 0, NULL, NULL, NULL, NULL);
 }
 
 /*
Index: gnome/applet/vpn-password-dialog.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/vpn-password-dialog.c,v
retrieving revision 1.3
diff -u -p -r1.3 vpn-password-dialog.c
--- gnome/applet/vpn-password-dialog.c	23 Jun 2005 19:47:37 -0000	1.3
+++ gnome/applet/vpn-password-dialog.c	8 Jul 2005 04:28:51 -0000
@@ -88,7 +88,7 @@ out:
 GSList *
 nmwa_vpn_request_password (NMWirelessApplet *applet, const char *name, const char *service, gboolean retry)
 {
-	char       *argv[] = {NULL /*"/usr/libexec/nm-vpnc-auth-dialog"*/, 
+	const char       *argv[] = {NULL /*"/usr/libexec/nm-vpnc-auth-dialog"*/, 
 			      "-n", NULL /*"davidznet42"*/, 
 			      "-s", NULL /*"org.freedesktop.vpnc"*/, 
 			      "-r",
@@ -161,8 +161,8 @@ nmwa_vpn_request_password (NMWirelessApp
 
 	/* Fix up parameters with what we got */
 	argv[0] = auth_dialog_binary;
-	argv[2] = (char *) name;
-	argv[4] = (char *) service;
+	argv[2] = name;
+	argv[4] = service;
 	if (!retry)
 		argv[5] = NULL;
 
@@ -171,7 +171,7 @@ nmwa_vpn_request_password (NMWirelessApp
 	child_status = -1;
 
 	if (!g_spawn_async_with_pipes (NULL,                       /* working_directory */
-				       argv,                       /* argv */
+				       (gchar **) argv,           /* argv */
 				       NULL,                       /* envp */
 				       G_SPAWN_DO_NOT_REAP_CHILD,  /* flags */
 				       NULL,                       /* child_setup */
Index: src/NetworkManagerDevice.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerDevice.c,v
retrieving revision 1.146
diff -u -p -r1.146 NetworkManagerDevice.c
--- src/NetworkManagerDevice.c	5 Jul 2005 15:05:33 -0000	1.146
+++ src/NetworkManagerDevice.c	8 Jul 2005 04:28:54 -0000
@@ -396,9 +396,9 @@ NMDevice *nm_device_new (const char *ifa
 
 	/* Block until our device thread has actually had a chance to start. */
 	args[0] = &dev->worker_started;
-	args[1] = "nm_device_new(): waiting for device's worker thread to start";
-	args[2] = (void *)LOG_INFO;
-	args[3] = 0;
+	args[1] = (gpointer) "nm_device_new(): waiting for device's worker thread to start";
+	args[2] = GINT_TO_POINTER (LOG_INFO);
+	args[3] = GINT_TO_POINTER (0);
 	nm_wait_for_completion (NM_COMPLETION_TRIES_INFINITY,
 			G_USEC_PER_SEC / 20, nm_completion_boolean_test, NULL, args);
 
@@ -3637,7 +3637,7 @@ static void nm_device_fake_ap_list (NMDe
 	int				i;
 	NMAccessPointList *	old_ap_list = nm_device_ap_list_get (dev);
 
-	char				*fake_essids[NUM_FAKE_APS] = { "green", "bay", "packers", "rule" };
+	const char				*fake_essids[NUM_FAKE_APS] = { "green", "bay", "packers", "rule" };
 	struct ether_addr	 fake_addrs[NUM_FAKE_APS] =  {{{0x70, 0x37, 0x03, 0x70, 0x37, 0x03}},
 											{{0x12, 0x34, 0x56, 0x78, 0x90, 0xab}},
 											{{0xcd, 0xef, 0x12, 0x34, 0x56, 0x78}},
Index: src/NetworkManagerUtils.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerUtils.c,v
retrieving revision 1.39
diff -u -p -r1.39 NetworkManagerUtils.c
--- src/NetworkManagerUtils.c	21 Jun 2005 15:07:01 -0000	1.39
+++ src/NetworkManagerUtils.c	8 Jul 2005 04:28:55 -0000
@@ -79,7 +79,7 @@ static MutexDesc *nm_find_mutex_desc (GM
  * Associate a description with a particular mutex.
  *
  */
-void nm_register_mutex_desc (GMutex *mutex, char *string)
+void nm_register_mutex_desc (GMutex *mutex, const char *string)
 {
 	if (!(nm_find_mutex_desc (mutex)))
 	{
@@ -375,7 +375,7 @@ void nm_dispose_scan_results (wireless_s
  * Wrap g_spawn_sync in a usable manner
  *
  */
-int nm_spawn_process (char *args)
+int nm_spawn_process (const char *args)
 {
 	gint		  num_args;
 	char		**argv = NULL;
Index: src/NetworkManagerUtils.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerUtils.h,v
retrieving revision 1.15
diff -u -p -r1.15 NetworkManagerUtils.h
--- src/NetworkManagerUtils.h	3 May 2005 20:41:34 -0000	1.15
+++ src/NetworkManagerUtils.h	8 Jul 2005 04:28:55 -0000
@@ -47,7 +47,7 @@ typedef struct NMSock NMSock;
 gboolean				nm_try_acquire_mutex			(GMutex *mutex, const char *func);
 void					nm_lock_mutex					(GMutex *mutex, const char *func);
 void					nm_unlock_mutex				(GMutex *mutex, const char *func);
-void					nm_register_mutex_desc			(GMutex *mutex, char *string);
+void					nm_register_mutex_desc			(GMutex *mutex, const char *string);
 
 NMSock *				nm_dev_sock_open				(NMDevice *dev, SockType type, const char *func_name, const char *desc);
 void					nm_dev_sock_close				(NMSock *sock);
@@ -60,7 +60,7 @@ gboolean				nm_ethernet_address_is_valid
 
 void					nm_dispose_scan_results			(wireless_scan *result_list);
 
-int					nm_spawn_process				(char *args);
+int					nm_spawn_process				(const char *args);
 
 NMDriverSupportLevel	nm_get_driver_support_level		(LibHalContext *ctx, NMDevice *dev);
 
Index: src/dhcp-manager/nm-dhcp-manager.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/dhcp-manager/nm-dhcp-manager.c,v
retrieving revision 1.7
diff -u -p -r1.7 nm-dhcp-manager.c
--- src/dhcp-manager/nm-dhcp-manager.c	26 Jun 2005 16:56:31 -0000	1.7
+++ src/dhcp-manager/nm-dhcp-manager.c	8 Jul 2005 04:28:55 -0000
@@ -85,8 +85,8 @@ static gboolean nm_dhcp_manager_exec_dae
 	g_return_val_if_fail (manager != NULL, FALSE);
 
 	dhcp_argv = g_ptr_array_new ();
-	g_ptr_array_add (dhcp_argv, DHCDBD_BINARY_PATH);
-	g_ptr_array_add (dhcp_argv, "--system");
+	g_ptr_array_add (dhcp_argv, (gpointer) DHCDBD_BINARY_PATH);
+	g_ptr_array_add (dhcp_argv, (gpointer) "--system");
 	g_ptr_array_add (dhcp_argv, NULL);
 
 	if (!g_spawn_async ("/", (char **) dhcp_argv->pdata, NULL, 0, NULL, NULL, &pid, &error))
Index: src/vpn-manager/nm-vpn-manager.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/vpn-manager/nm-vpn-manager.c,v
retrieving revision 1.9
diff -u -p -r1.9 nm-vpn-manager.c
--- src/vpn-manager/nm-vpn-manager.c	17 Jun 2005 01:23:16 -0000	1.9
+++ src/vpn-manager/nm-vpn-manager.c	8 Jul 2005 04:28:56 -0000
@@ -562,10 +562,9 @@ gboolean nm_vpn_manager_process_signal (
 		|| dbus_message_is_signal (message, service_name, NM_DBUS_VPN_SIGNAL_IP_CONFIG_BAD))
 	{
 		char *error_msg;
-		char *blank_msg = "";
 
 		if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &error_msg, DBUS_TYPE_INVALID))
-			error_msg = blank_msg;
+			error_msg = (char *) "";
 		nm_warning ("VPN failed for service '%s', signal '%s', with message '%s'.", service_name, member, error_msg);
 		nm_dbus_vpn_signal_vpn_failed (manager->app_data->dbus_connection, member, active, error_msg);
 	}
Index: test/nminfotest.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/test/nminfotest.c,v
retrieving revision 1.13
diff -u -p -r1.13 nminfotest.c
--- test/nminfotest.c	15 Mar 2005 05:30:14 -0000	1.13
+++ test/nminfotest.c	8 Jul 2005 04:28:56 -0000
@@ -30,13 +30,14 @@
 #include "NetworkManager.h"
 
 
-char * get_network_string_property (DBusConnection *connection, char *network, char *method, NMNetworkType type)
+static char * get_network_string_property (DBusConnection *connection, const char *network, const char *method, NMNetworkType type)
 {
 	DBusMessage	*message;
 	DBusMessage	*reply;
 	DBusError		 error;
 	char			*string = NULL;
 	char			*ret_string = NULL;
+	gint32		type_as_int;
 
 	message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, method);
 	if (message == NULL)
@@ -45,7 +46,8 @@ char * get_network_string_property (DBus
 		return NULL;
 	}
 
-	dbus_message_append_args (message, DBUS_TYPE_STRING, network, DBUS_TYPE_INT32, type, DBUS_TYPE_INVALID);
+	type_as_int = (gint32) type;
+	dbus_message_append_args (message, DBUS_TYPE_STRING, &network, DBUS_TYPE_INT32, &type_as_int, DBUS_TYPE_INVALID);
 	dbus_error_init (&error);
 	reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
 	dbus_message_unref (message);
@@ -78,12 +80,13 @@ char * get_network_string_property (DBus
 	return (ret_string);
 }
 
-gboolean get_network_trusted (DBusConnection *connection, char *network, NMNetworkType type)
+static gboolean get_network_trusted (DBusConnection *connection, const char *network, NMNetworkType type)
 {
 	DBusMessage	*message;
 	DBusMessage	*reply;
 	DBusError		 error;
 	gboolean		 trusted = FALSE;
+	gint32		type_as_int;
 
 	g_return_val_if_fail (connection != NULL, -1);
 	g_return_val_if_fail (network != NULL, -1);
@@ -96,7 +99,8 @@ gboolean get_network_trusted (DBusConnec
 	}
 
 	dbus_error_init (&error);
-	dbus_message_append_args (message, DBUS_TYPE_STRING, network, DBUS_TYPE_INT32, type, DBUS_TYPE_INVALID);
+	type_as_int = (gint32) type;
+	dbus_message_append_args (message, DBUS_TYPE_STRING, &network, DBUS_TYPE_INT32, &type_as_int, DBUS_TYPE_INVALID);
 	reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
 	dbus_message_unref (message);
 	if (dbus_error_is_set (&error))
@@ -126,12 +130,13 @@ gboolean get_network_trusted (DBusConnec
 }
 
 
-void get_networks_of_type (DBusConnection *connection, NMNetworkType type)
+static void get_networks_of_type (DBusConnection *connection, NMNetworkType type)
 {
 	DBusMessage 	*message;
 	DBusMessage 	*reply;
 	DBusMessageIter iter;
 	DBusError		 error;
+	gint32		type_as_int;
 	char **networks;
 	int	num_networks;
 	int i;
@@ -144,7 +149,8 @@ void get_networks_of_type (DBusConnectio
 	}
 
 	dbus_error_init (&error);
-	dbus_message_append_args (message, DBUS_TYPE_INT32, type, DBUS_TYPE_INVALID);
+	type_as_int = (gint32) type;
+	dbus_message_append_args (message, DBUS_TYPE_INT32, &type_as_int, DBUS_TYPE_INVALID);
 	reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
 	dbus_message_unref (message);
 	if (dbus_error_is_set (&error))
@@ -195,7 +201,7 @@ void get_networks_of_type (DBusConnectio
 	g_strfreev (networks);
 }
 
-void get_user_key_for_network (DBusConnection *connection)
+static void get_user_key_for_network (DBusConnection *connection)
 {
 	DBusMessage		*message;
 
@@ -219,7 +225,7 @@ void get_user_key_for_network (DBusConne
 }
 
 
-void set_user_key_for_network (DBusConnection *connection, DBusMessage *message, GMainLoop *loop)
+static void set_user_key_for_network (DBusConnection *connection, DBusMessage *message, GMainLoop *loop)
 {
 	DBusError	 error;
 	const char		*device;
Index: vpn-daemons/vpnc/src/nm-vpnc-service.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/vpn-daemons/vpnc/src/nm-vpnc-service.c,v
retrieving revision 1.2
diff -u -p -r1.2 nm-vpnc-service.c
--- vpn-daemons/vpnc/src/nm-vpnc-service.c	23 Jun 2005 20:03:47 -0000	1.2
+++ vpn-daemons/vpnc/src/nm-vpnc-service.c	8 Jul 2005 04:28:57 -0000
@@ -47,7 +47,7 @@
 #include "nm-utils.h"
 
 
-static char *vpnc_binary_paths[] =
+static const char *vpnc_binary_paths[] =
 {
 	"/usr/sbin/vpnc",
 	"/sbin/vpnc",
@@ -55,7 +55,6 @@ static char *vpnc_binary_paths[] =
 };
 
 #define NM_VPNC_HELPER_PATH		BINDIR"/nm-vpnc-service-vpnc-helper"
-#define NM_VPNC_PID_FILE_PATH		LOCALSTATEDIR"/run/vpnc/pid"
 
 typedef struct NmVpncData
 {
@@ -310,8 +309,6 @@ static void vpnc_watch_cb (GPid pid, gin
 	else
 		nm_warning ("vpnc died from an unknown cause");
 
-	/* Reap child if needed. */
-	waitpid (data->pid, NULL, WNOHANG);
 	data->pid = 0;
 
 	/* Must be after data->state is set since signals use data->state */
@@ -325,38 +322,13 @@ static void vpnc_watch_cb (GPid pid, gin
 			nm_vpnc_dbus_signal_failure (data, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED);
 			break;
 
-		case 0:	/* Success, vpnc has daemonized */
-			{
-				GPid	daemon_pid;
-				char *  contents;
-
-				/* vpnc is a bit slow to write the PID file */
-				sleep (2);
-
-				/* Grab the vpnc daemon's PID from its pidfile */
-				if (g_file_get_contents (NM_VPNC_PID_FILE_PATH, &contents, NULL, NULL))
-				{
-					data->pid = atoi (g_strstrip (contents));
-					nm_info ("vpnc daemon's PID is %d\n", data->pid);
-					g_free (contents);
-				}
-				else
-					nm_warning ("Could not read vpnc daemon's PID file.");
-			}
-			break;
-
 		default:
 			break;
 	}
 
-	/* If vpnc did not daemonize (due to errors), we quit after a bit */
-	if (data->pid <= 0)
-	{
-		nm_vpnc_set_state (data, NM_VPN_STATE_STOPPED);
-		unlink (NM_VPNC_PID_FILE_PATH);
+        nm_vpnc_set_state (data, NM_VPN_STATE_STOPPED);
 
-		nm_vpnc_schedule_quit_timer (data, 10000);
-	}
+        nm_vpnc_schedule_quit_timer (data, 10000);
 
 	/* State change from STARTING->STARTED happens when we get successful
 	 * ip4 config info from the helper.
@@ -373,7 +345,7 @@ static void vpnc_watch_cb (GPid pid, gin
 static gint nm_vpnc_start_vpnc_binary (NmVpncData *data)
 {
 	GPid			pid;
-	char **		vpnc_binary = NULL;
+	const char **		vpnc_binary = NULL;
 	GPtrArray *	vpnc_argv;
 	GError *		error = NULL;
 	gboolean		success = FALSE;
@@ -384,8 +356,6 @@ static gint nm_vpnc_start_vpnc_binary (N
 
 	data->pid = 0;
 
-	unlink (NM_VPNC_PID_FILE_PATH);
-
 	/* Find vpnc */
 	vpnc_binary = vpnc_binary_paths;
 	while (*vpnc_binary != NULL)
@@ -402,9 +372,10 @@ static gint nm_vpnc_start_vpnc_binary (N
 	}
 
 	vpnc_argv = g_ptr_array_new ();
-	g_ptr_array_add (vpnc_argv, (char *) (*vpnc_binary));
-	g_ptr_array_add (vpnc_argv, "--non-inter");
-	g_ptr_array_add (vpnc_argv, "-");
+	g_ptr_array_add (vpnc_argv, (gpointer) (*vpnc_binary));
+	g_ptr_array_add (vpnc_argv, (gpointer) "--non-inter");
+	g_ptr_array_add (vpnc_argv, (gpointer) "--no-detach");
+	g_ptr_array_add (vpnc_argv, (gpointer) "-");
 	g_ptr_array_add (vpnc_argv, NULL);
 
 	if (!g_spawn_async_with_pipes (NULL, (char **) vpnc_argv->pdata, NULL,
@@ -456,10 +427,6 @@ static gboolean nm_vpnc_config_write (gu
 	x = write (vpnc_fd, string, strlen (string));
 	g_free (string);
 
-	string = g_strdup ("Pidfile " NM_VPNC_PID_FILE_PATH "\n");
-	x = write (vpnc_fd, string, strlen (string));
-	g_free (string);
-	
 	string = g_strdup_printf ("IPSec secret %s\n", password_items[0]);
 	x = write (vpnc_fd, string, strlen (string));
 	g_free (string);


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