X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fio-layer%2Fprocesses.c;h=48a9687782942f77254e57fa0b6bed58ea884cbc;hb=8eeb2cef8fb37b7aaeed5fb0c31550a1701f9bdf;hp=d1e5a6367d04bc2dc0992e69e5576b1239882091;hpb=b99720966af5e385c08bcbad015814e77c6d8085;p=mono.git diff --git a/mono/io-layer/processes.c b/mono/io-layer/processes.c index d1e5a6367d0..48a96877829 100644 --- a/mono/io-layer/processes.c +++ b/mono/io-layer/processes.c @@ -1869,7 +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) @@ -2176,6 +2200,44 @@ get_module_name (gpointer process, gpointer module, return 0; } +static guint32 +get_module_filename (gpointer process, gpointer module, + gunichar2 *basename, guint32 size) +{ + int pid, len; + gsize bytes; + char *path; + gunichar2 *proc_path; + + pid = GetProcessId (process); + + path = wapi_process_get_path (pid); + if (path == NULL) + return 0; + + proc_path = mono_unicode_from_external (path, &bytes); + if (proc_path == NULL) + return 0; + + len = (bytes / 2); + + /* Add the terminator */ + bytes += 2; + + if (size < bytes) { + DEBUG ("%s: Size %d smaller than needed (%ld); truncating", __func__, size, bytes); + + memcpy (basename, proc_path, size); + } else { + DEBUG ("%s: Size %d larger than needed (%ld)", + __func__, size, bytes); + + memcpy (basename, proc_path, bytes); + } + + return len; +} + guint32 GetModuleBaseName (gpointer process, gpointer module, gunichar2 *basename, guint32 size) @@ -2187,7 +2249,7 @@ guint32 GetModuleFileNameEx (gpointer process, gpointer module, gunichar2 *filename, guint32 size) { - return get_module_name (process, module, filename, size, FALSE); + return get_module_filename (process, module, filename, size); } gboolean