process_name = ProcessName_internal (handle);
- /* If process_name is _still_ null, assume the process has exited */
+ /* If process_name is _still_ null, assume the process has exited or is inaccessible */
if (process_name == null)
- throw new InvalidOperationException ("Process has exited, so the requested information is not available.");
+ throw new InvalidOperationException ("Process has exited or is inaccessible, so the requested information is not available.");
/* Strip the suffix (if it exists) simplistically instead of removing
* any trailing \.???, so we dont get stupid results on sane systems */
// This should return Process[0] or a Process[] with all the "foo" programs running
Process.GetProcessesByName ("foo");
}
+
+ [Test]
+ [ExpectedException(typeof(InvalidOperationException))]
+ public void HigherPrivilegeProcessName ()
+ {
+ if (!RunningOnUnix)
+ Assert.Ignore ("accessing pid 1, only available on unix");
+
+ string v = Process.GetProcessById (1).ProcessName;
+ }
}
}
g_free (pi);
#else
gchar buf[256];
+ gint res;
/* No proc name on OSX < 10.5 nor ppc nor iOS */
memset (buf, '\0', sizeof(buf));
- proc_name (pid, buf, sizeof(buf));
+ res = proc_name (pid, buf, sizeof(buf));
+ if (res == 0) {
+ mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: proc_name failed, error (%d) \"%s\"", __func__, errno, g_strerror (errno));
+ return NULL;
+ }
// Fixes proc_name triming values to 15 characters #32539
if (strlen (buf) >= MAXCOMLEN - 1) {