gnome-terminal r2984 - trunk/src



Author: chpe
Date: Thu Aug 14 19:38:34 2008
New Revision: 2984
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=2984&view=rev

Log:
Bug 151794 â terminal_screen_get_working_dir() not optimal on Solaris 10
Patch by Mariano SuÃrez-Alvarez and Laszlo PETER.

Modified:
   trunk/src/terminal-screen.c

Modified: trunk/src/terminal-screen.c
==============================================================================
--- trunk/src/terminal-screen.c	(original)
+++ trunk/src/terminal-screen.c	Thu Aug 14 19:38:34 2008
@@ -1762,34 +1762,46 @@
   /* Try to update the working dir using various OS-specific mechanisms */
   if (priv->child_pid >= 0)
     {
-      char *file;
+      static const char *patterns[] = {
+        "/proc/%d/cwd",         /* Linux */
+        "/proc/%d/path/cwd",    /* Solaris >= 10 */
+      };
+      char *file = NULL;
       char buf[PATH_MAX+1];
-      int len;
+      int len = 0;
+      guint i;
 
-      /* readlink (/proc/pid/cwd) will work on Linux */
-      file = g_strdup_printf ("/proc/%d/cwd", priv->child_pid);
+      /* First try to update the working dir using various OS-specific mechanisms */
+      file = NULL;
+      for (i = 0; i < G_N_ELEMENTS (patterns); ++i)
+        {
+          g_free (file);
+          file = g_strdup_printf (patterns[i], priv->child_pid);
+          len = readlink (file, buf, sizeof (buf) - 1);
 
-      /* Silently ignore failure here, since we may not be on Linux */
-      len = readlink (file, buf, sizeof (buf) - 1);
+          if (len > 0 && buf[0] == '/')
+            {
+              buf[len] = '\0';
+              
+              g_free (priv->working_dir);
+              priv->working_dir = g_strdup (buf);
 
-      if (len > 0 && buf[0] == '/')
-        {
-          buf[len] = '\0';
-          
-          g_free (priv->working_dir);
-          priv->working_dir = g_strdup (buf);
+              break;
+            }
         }
-      else if (len == 0)
+
+      /* If that did not do it, be bold */
+      if (len <= 0)
         {
-          /* On Solaris, readlink returns an empty string, but the
-           * link can be used as a directory, including as a target
-           * of chdir().
-           */
           char *cwd;
 
           cwd = g_get_current_dir ();
           if (cwd != NULL)
             {
+              /* On Solaris, readlink returns an empty string, but the
+               * link can be used as a directory, including as a target
+               * of chdir().
+               */
               if (chdir (file) == 0)
                 {
                   g_free (priv->working_dir);
@@ -1799,10 +1811,10 @@
               g_free (cwd);
             }
         }
-      
+
       g_free (file);
     }
-  
+
   return priv->working_dir;
 }
 



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