Re: [gnome-network][PATCH] Some bugs fixes (was Re: [gnome-network]IPV6 fix for scan)



Carlos Garcia Campos wrote:
Yes, sorry, this is a patch that I have already sent but it has not been
applied to cvs. I'm sure that Rodrigo or German will apply it when they
have time to see it.

http://lists.gnome.org/archives/gnome-network-list/2003-October/msg00081.html

There are a couple small problems with this patch. It uses a deprecated function gnome_error_dialog_parented and it removes the object references from callbacks in .glade. The latter breaks the copy function.

My only other question is whether this is the best way to collect children in gn_quit_app?

Here is an updated patch.  Ok to commit?

Jon
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/ChangeLog,v
retrieving revision 1.94
diff -u -r1.94 ChangeLog
--- ChangeLog	18 Nov 2003 16:49:38 -0000	1.94
+++ ChangeLog	18 Nov 2003 19:55:46 -0000
@@ -1,5 +1,22 @@
 2003-11-18  William Jon McCann  <mccann jhu edu>
 
+	* netinfo.h: 
+	* main.c (load_ping_widgets_from_xml) 
+	(load_traceroute_widgets_from_xml, load_netstat_widgets_from_xml) 
+	(load_info_widgets_from_xml, load_scan_widgets_from_xml) 
+	(load_lookup_widgets_from_xml, load_finger_widgets_from_xml):
+	Added pointer to main window to the netinfo structure.
+
+	Based on changes sent by Carlos García Campos <carlosgc gnome org>
+	* callbacks.[ch] (gn_quit_app), gnome-netinfo.glade: 
+	  kill of all the children before exit
+	* netinfo.[ch] (validate_host): function to validate a host 
+	  fixes bug #114894
+	* ping.c (ping_do), scan.c (scan_do), traceroute.c (traceroute_do):
+	  validates the host before doing the action, fixes bug #114894
+	  
+2003-11-18  William Jon McCann  <mccann jhu edu>
+
 	* scan.c (scan_do): Work around bug in RH9 where connect always
 	returns zero for IPv6.  Also reduces the number of system calls
 	performed.
Index: callbacks.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/callbacks.c,v
retrieving revision 1.25
diff -u -r1.25 callbacks.c
--- callbacks.c	25 Aug 2003 15:54:37 -0000	1.25
+++ callbacks.c	18 Nov 2003 19:55:46 -0000
@@ -32,6 +32,10 @@
 #include "scan.h"
 #include "finger.h"
 
+#include "sys/wait.h"
+#include "unistd.h"
+#include "sys/types.h"
+
 /* Ping callbacks */
 void
 on_ping_activate (GtkWidget * widget, gpointer data)
@@ -139,6 +143,21 @@
 }
 
 void
+gn_quit_app (GtkWidget * widget, gpointer data)
+{
+	gint status, pid;
+
+	pid = getpid () + 1;
+	while (waitpid (-1, &status, WNOHANG) == 0) {
+		if (waitpid (pid, &status, WNOHANG) == 0)
+			kill (pid, SIGKILL);
+		pid ++;
+	}
+
+	gtk_main_quit ();
+}
+
+void
 on_about_activate (GtkWidget * parent, gpointer data)
 {
 	static GtkWidget *about_box = NULL;
@@ -179,7 +198,7 @@
 
         if (pixbuf != NULL)
                 g_object_unref (pixbuf);
-                 
+
 	gtk_window_set_transient_for (GTK_WINDOW (about_box),
 				      GTK_WINDOW (parent));
 
Index: callbacks.h
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/callbacks.h,v
retrieving revision 1.9
diff -u -r1.9 callbacks.h
--- callbacks.h	31 Jul 2003 20:34:40 -0000	1.9
+++ callbacks.h	18 Nov 2003 19:55:46 -0000
@@ -15,6 +15,8 @@
 void on_finger_activate (GtkWidget * editable, gpointer data);
 
 /* General stuff */
+void gn_quit_app (GtkWidget * widget, gpointer data);
+
 void on_about_activate (GtkWidget * parent, gpointer data);
 
 void on_copy_activate (GtkWidget * notebook, gpointer data);
Index: gnome-netinfo.glade
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/gnome-netinfo.glade,v
retrieving revision 1.26
diff -u -r1.26 gnome-netinfo.glade
--- gnome-netinfo.glade	31 Jul 2003 20:34:40 -0000	1.26
+++ gnome-netinfo.glade	18 Nov 2003 19:55:46 -0000
@@ -14,7 +14,7 @@
   <property name="default_height">490</property>
   <property name="resizable">True</property>
   <property name="destroy_with_parent">False</property>
-  <signal name="delete_event" handler="gtk_main_quit" last_modification_time="Mon, 09 Dec 2002 02:18:33 GMT"/>
+  <signal name="delete_event" handler="gn_quit_app" last_modification_time="Sun, 26 Oct 2003 10:04:54 GMT"/>
 
   <child>
     <widget class="GtkVBox" id="vbox_main">
@@ -38,7 +38,7 @@
 		    <widget class="GtkImageMenuItem" id="m_quit">
 		      <property name="visible">True</property>
 		      <property name="stock_item">GNOMEUIINFO_MENU_EXIT_ITEM</property>
-		      <signal name="activate" handler="gtk_main_quit" last_modification_time="Mon, 07 Jul 2003 12:37:48 GMT"/>
+		      <signal name="activate" handler="gn_quit_app" last_modification_time="Sun, 26 Oct 2003 10:05:12 GMT"/>
 		    </widget>
 		  </child>
 		</widget>
Index: main.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/main.c,v
retrieving revision 1.37
diff -u -r1.37 main.c
--- main.c	25 Aug 2003 15:54:37 -0000	1.37
+++ main.c	18 Nov 2003 19:55:46 -0000
@@ -130,6 +130,7 @@
 
 	pinger = g_new0 (Netinfo, 1);
 
+	pinger->main_window = glade_xml_get_widget (xml, "main_window");
 	pinger->running = FALSE;
 	pinger->child_pid = 0;
 	pinger->host = glade_xml_get_widget (xml, "ping_host");
@@ -177,6 +178,7 @@
 
 	tracer = g_new0 (Netinfo, 1);
 
+	tracer->main_window = glade_xml_get_widget (xml, "main_window");
 	tracer->running = FALSE;
 	tracer->child_pid = 0;
 	tracer->host = glade_xml_get_widget (xml, "traceroute_host");
@@ -217,6 +219,7 @@
 
 	netstat = g_new0 (Netinfo, 1);
 
+	netstat->main_window = glade_xml_get_widget (xml, "main_window");
 	netstat->running = FALSE;
 	netstat->child_pid = 0;
 	netstat->host = NULL;
@@ -266,6 +269,7 @@
 
 	info = g_malloc (sizeof (Netinfo));
 
+	info->main_window = glade_xml_get_widget (xml, "main_window");
 	info->hw_address = glade_xml_get_widget (xml, "info_hw_address");
 	info->ip_address = glade_xml_get_widget (xml, "info_ip_address");
 	info->netmask = glade_xml_get_widget (xml, "info_netmask");
@@ -314,6 +318,7 @@
 
 	scan = g_new0 (Netinfo, 1);
 
+	scan->main_window = glade_xml_get_widget (xml, "main_window");
 	scan->running = FALSE;
 	scan->child_pid = 0;
 	scan->host = glade_xml_get_widget (xml, "scan_host");
@@ -353,6 +358,7 @@
 
 	lookup = g_new0 (Netinfo, 1);
 
+	lookup->main_window = glade_xml_get_widget (xml, "main_window");
 	lookup->running = FALSE;
 	lookup->child_pid = 0;
 	lookup->host = glade_xml_get_widget (xml, "lookup_host");
@@ -396,6 +402,7 @@
 
 	finger = g_new0 (Netinfo, 1);
 
+	finger->main_window = glade_xml_get_widget (xml, "main_window");
 	finger->running = FALSE;
 	finger->child_pid = 0;
 	finger->user = glade_xml_get_widget (xml, "finger_user");
Index: netinfo.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netinfo.c,v
retrieving revision 1.14
diff -u -r1.14 netinfo.c
--- netinfo.c	2 Oct 2003 21:26:16 -0000	1.14
+++ netinfo.c	18 Nov 2003 19:55:46 -0000
@@ -120,6 +120,37 @@
 	return -1;
 }
 
+gboolean
+netinfo_validate_host (Netinfo * netinfo)
+{
+	struct hostent *hostname;
+	const gchar *host;
+	GtkWidget *dialog;
+
+	host = netinfo_get_host (netinfo);
+
+	hostname = gethostbyname2 (host, PF_INET6);
+	if (hostname == NULL) {
+		hostname = gethostbyname2 (host, AF_INET);
+		if (hostname == NULL) {
+			dialog = gtk_message_dialog_new
+				(GTK_WINDOW (netinfo->main_window),
+				 GTK_DIALOG_DESTROY_WITH_PARENT,
+				 GTK_MESSAGE_ERROR,
+				 GTK_BUTTONS_CLOSE,
+				 "The host '%s' cannot be found",
+				 host);
+			gtk_dialog_set_has_separator (GTK_DIALOG (dialog),
+						      FALSE);
+			gtk_dialog_run (GTK_DIALOG (dialog));
+			gtk_widget_destroy (dialog);
+			return FALSE;
+		}
+	}
+
+	return TRUE;
+}
+
 void
 netinfo_process_command (Netinfo * netinfo)
 {
Index: netinfo.h
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netinfo.h,v
retrieving revision 1.14
diff -u -r1.14 netinfo.h
--- netinfo.h	2 Oct 2003 21:26:16 -0000	1.14
+++ netinfo.h	18 Nov 2003 19:55:46 -0000
@@ -35,6 +35,7 @@
 typedef struct _Netinfo Netinfo;
 
 struct _Netinfo {
+	GtkWidget *main_window;
 	GtkWidget *user;
 	GtkWidget *host;
 	GtkWidget *count;
@@ -116,6 +117,7 @@
 const gchar * netinfo_get_host (Netinfo * netinfo);
 const gchar * netinfo_get_user (Netinfo * netinfo);
 gint netinfo_get_ip_version (Netinfo * netinfo);
+gboolean netinfo_validate_host (Netinfo * netinfo);
 void netinfo_toggle_button (Netinfo * netinfo);
 void netinfo_toggle_state (Netinfo * netinfo, gboolean state,
 			   gpointer user_data);
Index: ping.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/ping.c,v
retrieving revision 1.20
diff -u -r1.20 ping.c
--- ping.c	2 Oct 2003 21:26:16 -0000	1.20
+++ ping.c	18 Nov 2003 19:55:46 -0000
@@ -63,6 +63,11 @@
 
 	g_return_if_fail (netinfo != NULL);
 
+	if (netinfo_validate_host (netinfo) == FALSE) {
+		netinfo_stop_process_command (netinfo);
+		return;
+	}
+
 	count = netinfo_get_count (netinfo);
 	host = netinfo_get_host (netinfo);
 
Index: scan.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/scan.c,v
retrieving revision 1.7
diff -u -r1.7 scan.c
--- scan.c	18 Nov 2003 16:49:38 -0000	1.7
+++ scan.c	18 Nov 2003 19:55:46 -0000
@@ -69,6 +69,11 @@
 
 	g_return_if_fail (netinfo != NULL);
 
+	if (netinfo_validate_host (netinfo) == FALSE) {
+		netinfo_stop_process_command (netinfo);
+		return;
+	}
+
 	host = netinfo_get_host (netinfo);
 
 	/* Clear the current output */
Index: traceroute.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/traceroute.c,v
retrieving revision 1.17
diff -u -r1.17 traceroute.c
--- traceroute.c	2 Oct 2003 21:26:16 -0000	1.17
+++ traceroute.c	18 Nov 2003 19:55:46 -0000
@@ -47,6 +47,11 @@
         
 	g_return_if_fail (netinfo != NULL);
 
+	if (netinfo_validate_host (netinfo) == FALSE) {
+		netinfo_stop_process_command (netinfo);
+		return;
+	}
+
 	host = netinfo_get_host (netinfo);
 
 	model = gtk_tree_view_get_model (GTK_TREE_VIEW (netinfo->output));


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