[gnome-nettool] Check the exit status of external tools
- From: GermÃn Poà CaamaÃo <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nettool] Check the exit status of external tools
- Date: Tue, 3 Jan 2012 04:23:52 +0000 (UTC)
commit b14f9d2f78096502fcec43bbeb09b631dcc467f6
Author: GermÃn Poo-CaamaÃo <gpoo gnome org>
Date: Mon Jan 2 20:23:07 2012 -0800
Check the exit status of external tools
In the very rare cases when running the command fails, it
does not fail silently anymore.
Fixed Bug #612911
Signed-off-by: GermÃn Poo-CaamaÃo <gpoo gnome org>
src/finger.c | 2 +-
src/lookup.c | 2 +-
src/netstat.c | 3 +--
src/nettool.c | 53 ++++++++++++++++++++++++++++++++++++++++++-----------
src/ping.c | 3 +--
src/scan.c | 5 ++---
src/traceroute.c | 2 +-
src/whois.c | 2 +-
8 files changed, 50 insertions(+), 22 deletions(-)
---
diff --git a/src/finger.c b/src/finger.c
index 9af76e7..930582c 100644
--- a/src/finger.c
+++ b/src/finger.c
@@ -122,13 +122,13 @@ finger_do (Netinfo * netinfo)
command_line[i++] = g_strdup (command_arg);
command_line[i++] = NULL;
+ g_strfreev (netinfo->command_line);
netinfo->command_line = command_line;
netinfo_process_command (netinfo);
g_free (command_arg);
g_strfreev (command_options);
- g_strfreev (netinfo->command_line);
}
g_free (command);
diff --git a/src/lookup.c b/src/lookup.c
index 1372719..28ea46e 100644
--- a/src/lookup.c
+++ b/src/lookup.c
@@ -128,12 +128,12 @@ lookup_do (Netinfo * netinfo)
command_line[i++] = g_strdup (query_types[active_index]);
command_line[i++] = NULL;
+ g_strfreev (netinfo->command_line);
netinfo->command_line = command_line;
netinfo_process_command (netinfo);
g_strfreev (command_options);
- g_strfreev (netinfo->command_line);
}
g_free (command);
diff --git a/src/netstat.c b/src/netstat.c
index 1aceb57..bdadcb9 100644
--- a/src/netstat.c
+++ b/src/netstat.c
@@ -202,11 +202,10 @@ netstat_do (Netinfo * netinfo)
command =
g_strdup_printf ("%s netstat %s", program, option);
+ g_strfreev (netinfo->command_line);
netinfo->command_line = g_strsplit (command, " ", -1);
netinfo_process_command (netinfo);
-
- g_strfreev (netinfo->command_line);
}
/* Restore previous state */
diff --git a/src/nettool.c b/src/nettool.c
index f81dc9d..e18e4df 100644
--- a/src/nettool.c
+++ b/src/nettool.c
@@ -264,11 +264,46 @@ netinfo_process_command (Netinfo * netinfo)
netinfo_text_buffer_insert (netinfo);
}
+/* read child output on child termination event */
+static void
+netinfo_reap_child (GPid pid, gint status, gpointer user_data)
+{
+ Netinfo *netinfo = (Netinfo *) user_data;
+ gchar *primary = NULL;
+ gchar *secondary = NULL;
+ const gchar *page_label;
+ gchar *cmd;
+
+ g_spawn_close_pid (pid);
+
+ g_return_if_fail (netinfo != NULL);
+ g_return_if_fail (netinfo->command_line != NULL);
+
+ page_label = gtk_label_get_text (GTK_LABEL (netinfo->page_label));
+
+ if (WEXITSTATUS(status) > 0) {
+ cmd = g_strjoinv (" ", netinfo->command_line);
+
+ /* '%s' is the task name to run
+ (e.g. Traceroute, Port Scan, Finger, etc.) */
+ primary = g_strdup_printf (
+ _("An error occurred when try to run '%s'"),
+ page_label);
+ secondary = g_strdup_printf ("%s", cmd);
+
+ netinfo_error_message (netinfo, primary, secondary);
+
+ g_free (cmd);
+ g_free (primary);
+ g_free (secondary);
+ }
+}
+
void
netinfo_text_buffer_insert (Netinfo * netinfo)
{
gchar *dir = g_get_current_dir ();
- gint child_pid, pout; /* , perr; */
+ gint child_pid, pout;
GIOChannel *channel;
const gchar *charset;
GIOStatus status;
@@ -278,9 +313,10 @@ netinfo_text_buffer_insert (Netinfo * netinfo)
g_return_if_fail (netinfo->command_line != NULL);
if (g_spawn_async_with_pipes (dir, netinfo->command_line, NULL,
- G_SPAWN_FILE_AND_ARGV_ZERO, NULL,
+ G_SPAWN_FILE_AND_ARGV_ZERO |
+ G_SPAWN_DO_NOT_REAP_CHILD, NULL,
NULL, &child_pid, NULL, &pout,
- NULL /* &perr */ ,
+ NULL,
&err)) {
netinfo->child_pid = child_pid;
@@ -289,7 +325,7 @@ netinfo_text_buffer_insert (Netinfo * netinfo)
fcntl (pout, F_SETFL, O_NONBLOCK);
netinfo->command_output = NULL;
- /*netinfo->pipe_err = perr; */
+ g_child_watch_add (child_pid, netinfo_reap_child, netinfo);
g_get_charset(&charset);
channel = g_io_channel_unix_new (pout);
@@ -298,15 +334,10 @@ netinfo_text_buffer_insert (Netinfo * netinfo)
&err);
if (G_IO_STATUS_NORMAL == status) {
g_io_add_watch (channel,
- G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ G_IO_IN | G_IO_HUP |
+ G_IO_ERR | G_IO_NVAL,
netinfo_io_text_buffer_dialog, netinfo);
g_io_channel_unref (channel);
-
- /*channel = g_io_channel_unix_new (perr);
- g_io_add_watch (channel,
- G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- netinfo_io_text_buffer_dialog, netinfo);
- g_io_channel_unref (channel); */
} else {
g_warning ("Error: %s\n", err->message);
g_error_free (err);
diff --git a/src/ping.c b/src/ping.c
index 22a8dfb..0e5eb27 100644
--- a/src/ping.c
+++ b/src/ping.c
@@ -344,11 +344,10 @@ ping_do (Netinfo * netinfo)
#ifdef DEBUG
g_print("command: %s\n", command);
#endif
+ g_strfreev (netinfo->command_line);
netinfo->command_line = g_strsplit (command, " ", -1);
netinfo_process_command (netinfo);
-
- g_strfreev (netinfo->command_line);
}
g_free (count_string);
diff --git a/src/scan.c b/src/scan.c
index c84d866..88efd52 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -86,12 +86,11 @@ scan_do (Netinfo * netinfo)
command = g_strdup_printf ("%s %s %s", program,
"nmap", host);
}
-
+
+ g_strfreev (netinfo->command_line);
netinfo->command_line = g_strsplit (command, " ", -1);
netinfo_process_command (netinfo);
-
- g_strfreev (netinfo->command_line);
}
g_free (command);
diff --git a/src/traceroute.c b/src/traceroute.c
index 48f50b5..8640db7 100644
--- a/src/traceroute.c
+++ b/src/traceroute.c
@@ -121,11 +121,11 @@ traceroute_do (Netinfo * netinfo)
program_name, program_options,
host);
+ g_strfreev (netinfo->command_line);
netinfo->command_line = g_strsplit (command, " ", -1);
netinfo_process_command (netinfo);
- g_strfreev (netinfo->command_line);
g_free (command);
g_free (program);
g_free (program_name);
diff --git a/src/whois.c b/src/whois.c
index ca018ca..7c17e6c 100644
--- a/src/whois.c
+++ b/src/whois.c
@@ -102,13 +102,13 @@ whois_do (Netinfo * netinfo)
command_line[i++] = g_strdup (command_arg);
command_line[i++] = NULL;
+ g_strfreev (netinfo->command_line);
netinfo->command_line = command_line;
netinfo_process_command (netinfo);
g_free (command_arg);
g_strfreev (command_options);
- g_strfreev (netinfo->command_line);
}
g_free (command);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]