[gnome-terminal] screen: Allow getting the cmdline of the current foreground process



commit 6c22fbb564f9f56c8c1a23b844f5c80772613045
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Dec 10 17:14:29 2013 +0100

    screen: Allow getting the cmdline of the current foreground process
    
    This would further enhance our ability to search based on the current
    foreground process.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711075

 src/terminal-screen.c |   28 ++++++++++++++++++++++++----
 src/terminal-screen.h |    3 ++-
 src/terminal-window.c |    4 ++--
 3 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 5ff7e3b..e5ec711 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -1960,6 +1960,7 @@ terminal_screen_check_match (TerminalScreen *screen,
  * terminal_screen_has_foreground_process:
  * @screen:
  * @process_name: (out) (allow-none): the basename of the program, or %NULL
+ * @cmdline: (out) (allow-none): the full command line, or %NULL
  *
  * Checks whether there's a foreground process running in
  * this terminal.
@@ -1968,13 +1969,16 @@ terminal_screen_check_match (TerminalScreen *screen,
  */
 gboolean
 terminal_screen_has_foreground_process (TerminalScreen *screen,
-                                        char           **process_name)
+                                        char           **process_name,
+                                        char           **cmdline)
 {
   TerminalScreenPrivate *priv = screen->priv;
-  gs_free char *cmdline = NULL;
+  gs_free char *command = NULL;
+  gs_free char *data = NULL;
   gs_free char *basename = NULL;
   gs_free char *name = NULL;
   char filename[64];
+  gsize i;
   gsize len;
   int fgpid;
 
@@ -1986,10 +1990,10 @@ terminal_screen_has_foreground_process (TerminalScreen *screen,
     return FALSE;
 
   g_snprintf (filename, sizeof (filename), "/proc/%d/cmdline", fgpid);
-  if (!g_file_get_contents (filename, &cmdline, &len, NULL))
+  if (!g_file_get_contents (filename, &data, &len, NULL))
     return TRUE;
 
-  basename = g_path_get_basename (cmdline);
+  basename = g_path_get_basename (data);
   if (!basename)
     return TRUE;
 
@@ -1997,9 +2001,25 @@ terminal_screen_has_foreground_process (TerminalScreen *screen,
   if (!name)
     return TRUE;
 
+  if (!process_name && !cmdline)
+    return TRUE;
+
   if (process_name)
     gs_transfer_out_value (process_name, &name);
 
+  for (i = 0; i < len - 1; i++)
+    {
+      if (data[i] == '\0')
+        data[i] = ' ';
+    }
+
+  command = g_filename_to_utf8 (data, -1, NULL, NULL, NULL);
+  if (!command)
+    return TRUE;
+
+  if (cmdline)
+    gs_transfer_out_value (cmdline, &command);
+
   return TRUE;
 }
 
diff --git a/src/terminal-screen.h b/src/terminal-screen.h
index 03f6e99..5c8207c 100644
--- a/src/terminal-screen.h
+++ b/src/terminal-screen.h
@@ -134,7 +134,8 @@ void terminal_screen_save_config (TerminalScreen *screen,
 void terminal_screen_update_style (TerminalScreen *screen);
 
 gboolean terminal_screen_has_foreground_process (TerminalScreen *screen,
-                                                 char           **process_name);
+                                                 char           **process_name,
+                                                 char           **cmdline);
 
 /* Allow scales a bit smaller and a bit larger than the usual pango ranges */
 #define TERMINAL_SCALE_XXX_SMALL   (PANGO_SCALE_XX_SMALL/1.2)
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 2d138fa..249bea8 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -3532,7 +3532,7 @@ confirm_close_window_or_tab (TerminalWindow *window,
 
   if (screen)
     {
-      do_confirm = terminal_screen_has_foreground_process (screen, NULL);
+      do_confirm = terminal_screen_has_foreground_process (screen, NULL, NULL);
       n_tabs = 1;
     }
   else
@@ -3549,7 +3549,7 @@ confirm_close_window_or_tab (TerminalWindow *window,
           TerminalScreen *terminal_screen;
 
           terminal_screen = terminal_screen_container_get_screen (TERMINAL_SCREEN_CONTAINER (t->data));
-          if (terminal_screen_has_foreground_process (terminal_screen, NULL))
+          if (terminal_screen_has_foreground_process (terminal_screen, NULL, NULL))
             {
               do_confirm = TRUE;
               break;


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