Merge pull request #1952 from esdrubal/proc_name
authorMarcos Henrich <marcoshenrich@gmail.com>
Tue, 11 Aug 2015 12:10:27 +0000 (13:10 +0100)
committerMarcos Henrich <marcoshenrich@gmail.com>
Tue, 11 Aug 2015 12:10:27 +0000 (13:10 +0100)
Fixes process names trimmed to 15 chars.

1  2 
mono/io-layer/processes.c

index d1e5a6367d04bc2dc0992e69e5576b1239882091,418ba46dcc3b5b325b0f07badd224c58ac1d3872..1391f67f57ac0180e6b4e8fa0e88d252be6dd13a
@@@ -554,7 -554,6 +554,7 @@@ gboolean CreateProcess (const gunichar
                        WapiStartupInfo *startup,
                        WapiProcessInformation *process_info)
  {
 +#if defined (HAVE_FORK) && defined (HAVE_EXECVE)
        char *cmd = NULL, *prog = NULL, *full_prog = NULL, *args = NULL, *args_after_prog = NULL;
        char *dir = NULL, **env_strings = NULL, **argv = NULL;
        guint32 i, env_count = 0;
@@@ -1099,10 -1098,6 +1099,10 @@@ free_strings
        mono_processes_cleanup ();
        
        return ret;
 +#else
 +      SetLastError (ERROR_NOT_SUPPORTED);
 +      return FALSE;
 +#endif // defined (HAVE_FORK) && defined (HAVE_EXECVE)
  }
                
  static void
@@@ -1869,7 -1864,31 +1869,31 @@@ get_process_name_from_proc (pid_t pid
        /* No proc name on OSX < 10.5 nor ppc nor iOS */
        memset (buf, '\0', sizeof(buf));
        proc_name (pid, buf, sizeof(buf));
-       if (strlen (buf) > 0)
+       // Fixes proc_name triming values to 15 characters #32539
+       if (strlen (buf) >= MAXCOMLEN - 1) {
+               char path_buf [PROC_PIDPATHINFO_MAXSIZE];
+               char *name_buf;
+               int path_len;
+               memset (path_buf, '\0', sizeof(path_buf));
+               path_len = proc_pidpath (pid, path_buf, sizeof(path_buf));
+               if (path_len > 0 && path_len < sizeof(path_buf)) {
+                       name_buf = path_buf + path_len;
+                       for(;name_buf > path_buf; name_buf--) {
+                               if (name_buf [0] == '/') {
+                                       name_buf++;
+                                       break;
+                               }
+                       }
+                       if (memcmp (buf, name_buf, MAXCOMLEN - 1) == 0)
+                               ret = g_strdup (name_buf);
+               }
+       }
+       if (ret == NULL && strlen (buf) > 0)
                ret = g_strdup (buf);
  #else
        if (sysctl(mib, 4, NULL, &size, NULL, 0) < 0)